Skip to content

Commit

Permalink
[#232] fix api to use common Version schema
Browse files Browse the repository at this point in the history
also rewrote the schema fetcher to use Go
  • Loading branch information
coryb committed Oct 2, 2019
1 parent 2c9d957 commit 90f01ce
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 41 deletions.
13 changes: 0 additions & 13 deletions jiradata/ProjectVersion.go

This file was deleted.

3 changes: 0 additions & 3 deletions jiradata/ProjectVersions.go

This file was deleted.

8 changes: 4 additions & 4 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func GetProjectComponents(ua HttpClient, endpoint string, project string) (*jira
}

// https://developer.atlassian.com/cloud/jira/platform/rest/v2#api-api-2-project-projectIdOrKey-versions-get
func (j *Jira) GetProjectVersions(project string) (*jiradata.ProjectVersions, error) {
func (j *Jira) GetProjectVersions(project string) (*jiradata.Versions, error) {
return GetProjectVersions(j.UA, j.Endpoint, project)
}

func GetProjectVersions(ua HttpClient, endpoint string, project string) (*jiradata.ProjectVersions, error) {
func GetProjectVersions(ua HttpClient, endpoint string, project string) (*jiradata.Versions, error) {
uri := URLJoin(endpoint, "rest/api/2/project", project, "versions")
resp, err := ua.GetJSON(uri)
if err != nil {
Expand All @@ -40,8 +40,8 @@ func GetProjectVersions(ua HttpClient, endpoint string, project string) (*jirada
defer resp.Body.Close()

if resp.StatusCode == 200 {
results := jiradata.ProjectVersions{}
return &results, readJSON(resp.Body, &results)
results := jiradata.Versions{}
return &results, json.NewDecoder(resp.Body).Decode(&results)
}
return nil, responseError(resp)
}
63 changes: 63 additions & 0 deletions schemas/fetch-schemas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"

"golang.org/x/net/html"
)

func mayPanic(err error) {
if err != nil {
panic(err)
}
}

func main() {
resp, err := http.Get("https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/")
mayPanic(err)
defer resp.Body.Close()

capture := false
nextCodeBlock := false
stream := html.NewTokenizer(resp.Body)
var buffer string
for tt := stream.Next(); tt != html.ErrorToken; tt = stream.Next() {
t := stream.Token()
if t.Data == "h6" && tt == html.StartTagToken {
capture = true
}
if t.Data == "h6" && tt == html.EndTagToken {
capture = false
if strings.Contains(strings.ToLower(buffer), "schema") {
nextCodeBlock = true
}
buffer = ""
}
if nextCodeBlock && t.Data == "code" && tt == html.StartTagToken {
capture = true
}
if nextCodeBlock && t.Data == "code" && tt == html.EndTagToken {
capture = false
schema := map[string]interface{}{}
err := json.Unmarshal([]byte(buffer), &schema)
mayPanic(err)
title, ok := schema["title"].(string)
if ok {
title = strings.ReplaceAll(title, " ", "")
fileName := fmt.Sprintf("%s.json", title)
fmt.Printf("Writing %s\n", fileName)
err := ioutil.WriteFile(fileName, []byte(buffer), 0644)
mayPanic(err)
}
buffer = ""
nextCodeBlock = false
}
if capture && tt == html.TextToken {
buffer += t.Data
}
}
}
21 changes: 0 additions & 21 deletions schemas/fetch-schemas.py

This file was deleted.

0 comments on commit 90f01ce

Please sign in to comment.