Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jira
- import (
- "encoding/json"
- "net/url"
- )
- const (
- apiName string = "api"
- apiVersion string = "2"
- )
- type JiraClient struct {
- AuthUser string
- AuthPass string
- Host url.URL
- }
- func NewClient(user, pass string, jiraHost url.URL) *JiraClient {
- return &JiraClient{
- AuthUser: user,
- AuthPass: pass,
- }
- }
- func (c *JiraClient) Products() ([]JiraProduct, error) {
- args = map[string]string{
- "projectKeys": "BLD",
- "expand", "projects.issuetypes.fields",
- }
- fields, err := c.performRequest("GET", "issue/createmeta", args)
- // do whatever transformation to turn fields into []JiraProduct
- }
- func (c *JiraClient) performRequest(method string, endpoint string, args map[string]string) jiraFields {
- url := jiraUrl(endpoint)
- q := url.Query()
- for k, v := range args {
- q.Add(k, v)
- }
- url.RawQuery = q.Encode()
- resp := jiraRequest(url, method)
- // Fill the record with the data from the JSON
- var parsedDoc jiraDoc
- // Use json.Decode for reading streams of JSON data
- if err := json.NewDecoder(resp.Body).Decode(&parsedDoc); err != nil {
- return nil, err
- }
- project := parsedDoc.Projects[0] // Only requested one project, use the first one
- issueType := project.IssueTypes[0] // Should be "Task", but probably doesn't matter
- fields := issueType.Fields
- return fields
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement