Skip to content

Commit

Permalink
fix #15 added command
Browse files Browse the repository at this point in the history
  • Loading branch information
kyokomi committed Sep 17, 2014
1 parent 94d7025 commit fcc2b66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
27 changes: 27 additions & 0 deletions gitlab-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ func doEditIssue(c *cli.Context) {
fmt.Println("done. ", string(res))
}

func doCreateIssueNote(c *cli.Context) {
gitLab, err := newGitLabCli(c.GlobalBool("skip-cert-check"))
if err != nil {
log.Fatal("error create gitlab ")
}

values := url.Values{}
values.Set("body", c.String("message"))

issueID := c.Int("issue-id")
res, err := gitLab.AddIssuesNote(gitLab.currentProjectID, issueID, values)
if err != nil {
log.Fatal("project issue note create error ", err)
}
fmt.Println("done. ", string(res))
}

// project check task.
func doCheckProject(_ *cli.Context) {
projectName, err := GetCurrentDirProjectName()
Expand Down Expand Up @@ -202,6 +219,16 @@ func main() {
},
Action: doEditIssue,
},
{
Name: "comment",
ShortName: "",
Usage: "Creates a new note to a single project issue.",
Flags: []cli.Flag{
cli.IntFlag{"issue-id, id", 0, "(required) - The ID of a project issue", ""},
cli.StringFlag{"message, m", "", "(required) - The content of a note", ""},
},
Action: doCreateIssueNote,
},
{
Name: "check-project",
ShortName: "check",
Expand Down
21 changes: 21 additions & 0 deletions gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ func (gitLab *gitLabCli) EditIssue(projectID, issueID int, values url.Values) ([
return res, nil
}

func (gitLab *gitLabCli) AddIssuesNote(projectID, issueID int, values url.Values) ([]byte, error) {
reader := strings.NewReader(values.Encode())
data, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}

// localIssueID => issueID
issue := gitLab.findIssueByID(projectID, issueID)
if issue == nil {
return nil, fmt.Errorf("issue not found")
}

res, err := gitLab.CreateIssuesNote(projectID, issue.ID, data)
if err != nil {
return nil, err
}

return res, nil
}

func (gitLab *gitLabCli) PrintIssue(projectID int, state string) {
c := make(chan []*gogitlab.Issue)
go gitLab.findIssueState(c, projectID, func(issues []*gogitlab.Issue) bool {
Expand Down

0 comments on commit fcc2b66

Please sign in to comment.