Skip to content

Commit

Permalink
add issuelinktypes command
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Aug 14, 2017
1 parent aacc9f4 commit 37f81a4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
13 changes: 4 additions & 9 deletions cmd/jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func main() {
Command: "issuelink",
Entry: cli.CmdIssueLinkRegistry(),
},
jiracli.CommandRegistry{
Command: "issuelinktypes",
Entry: cli.CmdIssueLinkTypesRegistry(),
},
jiracli.CommandRegistry{
Command: "transition",
Aliases: []string{"trans"},
Expand Down Expand Up @@ -230,7 +234,6 @@ func main() {
// jira take ISSUE
// jira (assign|give) ISSUE [ASSIGNEE|--default]
// jira unassign ISSUE
// jira issuelinktypes
// jira transmeta ISSUE
// jira add component [-p PROJECT] NAME DESCRIPTION LEAD
// jira components [-p PROJECT]
Expand Down Expand Up @@ -296,13 +299,7 @@ func main() {
// "take": "take",
// "assign": "assign",
// "give": "assign",
// "fields": "fields",
// "issuelinktypes": "issuelinktypes",
// "transmeta": "transmeta",
// "editmeta": "editmeta",
// "issuetypes": "issuetypes",
// "createmeta": "createmeta",
// "transitions": "transitions",
// "export-templates": "export-templates",
// "browse": "browse",
// "req": "request",
Expand Down Expand Up @@ -456,8 +453,6 @@ func main() {

// var err error
// switch command {
// case "issuelinktypes":
// err = c.CmdIssueLinkTypes()
// case "issuetypes":
// err = c.CmdIssueTypes()
// case "watch":
Expand Down
20 changes: 20 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,23 @@ func (j *Jira) TransitionIssue(issue string, iup IssueUpdateProvider) error {
}
return responseError(resp)
}

// https://docs.atlassian.com/jira/REST/cloud/#api/2/issueLinkType-getIssueLinkTypes
func (j *Jira) GetIssueLinkTypes() (*jiradata.IssueLinkTypes, error) {
uri := fmt.Sprintf("%s/rest/api/2/issueLinkType", j.Endpoint)
resp, err := j.UA.GetJSON(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode == 200 {
results := struct {
IssueLinkTypes jiradata.IssueLinkTypes
}{
IssueLinkTypes: jiradata.IssueLinkTypes{},
}
return &results.IssueLinkTypes, readJSON(resp.Body, &results)
}
return nil, responseError(resp)
}
36 changes: 36 additions & 0 deletions jiracli/issuelinktypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jiracli

import kingpin "gopkg.in/alecthomas/kingpin.v2"

func (jc *JiraCli) CmdIssueLinkTypesRegistry() *CommandRegistryEntry {
opts := GlobalOptions{
Template: "issuelinktypes",
}

return &CommandRegistryEntry{
"Show the issue link types",
func() error {
return jc.CmdIssueLinkTypes(&opts)
},
func(cmd *kingpin.CmdClause) error {
return jc.CmdIssueLinkTypesUsage(cmd, &opts)
},
}
}

func (jc *JiraCli) CmdIssueLinkTypesUsage(cmd *kingpin.CmdClause, opts *GlobalOptions) error {
if err := jc.GlobalUsage(cmd, opts); err != nil {
return err
}
jc.TemplateUsage(cmd, opts)
return nil
}

// CmdIssueLinkTypes will get issue link type data and send to "issuelinktypes" template
func (jc *JiraCli) CmdIssueLinkTypes(opts *GlobalOptions) error {
data, err := jc.GetIssueLinkTypes()
if err != nil {
return err
}
return jc.runTemplate(opts.Template, data, nil)
}
44 changes: 44 additions & 0 deletions jiradata/IssueLinkTypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package jiradata

/////////////////////////////////////////////////////////////////////////
// This Code is Generated by SlipScheme Project:
// https://github.com/coryb/slipscheme
//
// Generated with command:
// slipscheme -dir jiradata -pkg jiradata schemas/IssueLinkTypes.json
/////////////////////////////////////////////////////////////////////////
// DO NOT EDIT //
/////////////////////////////////////////////////////////////////////////

// IssueLinkTypes defined from schema:
// {
// "title": "issueLinkTypes",
// "type": "array",
// "items": {
// "title": "Issue Link Type",
// "type": "object",
// "properties": {
// "id": {
// "title": "id",
// "type": "string"
// },
// "inward": {
// "title": "inward",
// "type": "string"
// },
// "name": {
// "title": "name",
// "type": "string"
// },
// "outward": {
// "title": "outward",
// "type": "string"
// },
// "self": {
// "title": "self",
// "type": "string"
// }
// }
// }
// }
type IssueLinkTypes []*IssueLinkType

0 comments on commit 37f81a4

Please sign in to comment.