mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
[#232] fix api to use common Version schema
also rewrote the schema fetcher to use Go
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
package jiradata
|
|
||||||
|
|
||||||
type ProjectVersion struct {
|
|
||||||
Self string `json:"self,omitempty" yaml:"self,omitempty"`
|
|
||||||
ID string `json:"id,omitempty" yaml:"id,omitempty"`
|
|
||||||
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
|
||||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
|
||||||
Archived bool `json:"archived,omitempty" yaml:archived,omitempty"`
|
|
||||||
Released bool `json:"released,omitempty" yaml:released,omitempty"`
|
|
||||||
ReleaseDate string `json:"releaseDate,omitempty" yaml:"releaseDate,omitempty"`
|
|
||||||
UserReleaseDate string `json:"userReleaseDate,omitempty" yaml:"userReleaseDate,omitempty"`
|
|
||||||
ProjectID int `json:"projectId,omitempty" yaml:"projectId,omitempty"`
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
package jiradata
|
|
||||||
|
|
||||||
type ProjectVersions []*ProjectVersion
|
|
||||||
+4
-4
@@ -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
|
// 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)
|
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")
|
uri := URLJoin(endpoint, "rest/api/2/project", project, "versions")
|
||||||
resp, err := ua.GetJSON(uri)
|
resp, err := ua.GetJSON(uri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -40,8 +40,8 @@ func GetProjectVersions(ua HttpClient, endpoint string, project string) (*jirada
|
|||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
results := jiradata.ProjectVersions{}
|
results := jiradata.Versions{}
|
||||||
return &results, readJSON(resp.Body, &results)
|
return &results, json.NewDecoder(resp.Body).Decode(&results)
|
||||||
}
|
}
|
||||||
return nil, responseError(resp)
|
return nil, responseError(resp)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
from lxml import html
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
page = requests.get('https://docs.atlassian.com/jira/REST/cloud')
|
|
||||||
tree = html.fromstring(page.content)
|
|
||||||
|
|
||||||
schemas = tree.xpath("//div[@class='representation-doc-block']//code/text()")
|
|
||||||
|
|
||||||
for schema in schemas:
|
|
||||||
try:
|
|
||||||
data = json.loads(schema)
|
|
||||||
if "title" in data:
|
|
||||||
title = data["title"].replace(" ", "")
|
|
||||||
print "Writing {}.json".format(title)
|
|
||||||
with open("{}.json".format(title), 'w') as f:
|
|
||||||
f.write(schema)
|
|
||||||
except:
|
|
||||||
True
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user