Skip to content

Commit

Permalink
add vote command
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Aug 14, 2017
1 parent 37f81a4 commit a08c92f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 300 deletions.
17 changes: 4 additions & 13 deletions cmd/jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func main() {
Aliases: []string{"prog", "progress"},
Entry: cli.CmdTransitionRegistry("Progress"),
},
jiracli.CommandRegistry{
Command: "vote",
Entry: cli.CmdVoteRegistry(),
},
}

cli.Register(app, registry)
Expand Down Expand Up @@ -225,21 +229,16 @@ func main() {
// }
// output := fmt.Sprintf(`
// Usage:
// jira vote ISSUE [--down]
// jira rank ISSUE (after|before) ISSUE
// jira watch ISSUE [-w WATCHER] [--remove]
// jira (trans|transition) TRANSITION ISSUE [--noedit] <Edit Options>
// jira comment ISSUE [--noedit] <Edit Options>
// jira (set,add,remove) labels ISSUE [LABEL] ...
// jira take ISSUE
// jira (assign|give) ISSUE [ASSIGNEE|--default]
// jira unassign ISSUE
// jira transmeta ISSUE
// jira add component [-p PROJECT] NAME DESCRIPTION LEAD
// jira components [-p PROJECT]
// jira issuetypes [-p PROJECT]
// jira createmeta [-p PROJECT] [-i ISSUETYPE]
// jira transitions ISSUE
// jira export-templates [-d DIR] [-t template]
// jira (b|browse) ISSUE
// jira request [-M METHOD] URI [DATA]
Expand Down Expand Up @@ -304,7 +303,6 @@ func main() {
// "browse": "browse",
// "req": "request",
// "request": "request",
// "vote": "vote",
// "rank": "rank",
// "unassign": "unassign",
// }
Expand Down Expand Up @@ -506,13 +504,6 @@ func main() {
// case "unassign":
// requireArgs(1)
// err = c.CmdUnassign(args[0])
// case "vote":
// requireArgs(1)
// if val, ok := opts["down"]; ok {
// err = c.CmdVote(args[0], !val.(bool))
// } else {
// err = c.CmdVote(args[0], true)
// }
// case "rank":
// requireArgs(3)
// if args[1] == "after" {
Expand Down
30 changes: 30 additions & 0 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,33 @@ func (j *Jira) GetIssueLinkTypes() (*jiradata.IssueLinkTypes, error) {
}
return nil, responseError(resp)
}

// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-addVote
func (j *Jira) IssueAddVote(issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", j.Endpoint, issue)
resp, err := j.UA.Post(uri, "application/json", strings.NewReader("{}"))
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode == 204 {
return nil
}
return responseError(resp)
}

// https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-removeVote
func (j *Jira) IssueRemoveVote(issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", j.Endpoint, issue)
resp, err := j.UA.Delete(uri)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode == 204 {
return nil
}
return responseError(resp)
}
Loading

0 comments on commit a08c92f

Please sign in to comment.