From cc2f9f2f4d0e4e91b94b046b60e807381a5e98f5 Mon Sep 17 00:00:00 2001 From: Tulir Asokan <tulir@maunium.net> Date: Sat, 30 Sep 2017 19:07:12 +0300 Subject: [PATCH] Add support for commenting on issues --- README.md | 2 +- commands.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 839ba3e..ad58011 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A Gitlab bot for Matrix. It uses * [x] Read issues * [x] Create/close/reopen issues * [ ] Read comments on issues - * [ ] Comment on issues + * [x] Comment on issues ## Usage Configure the server by copying `example-config.json` to `config.json` and diff --git a/commands.go b/commands.go index 9af74b7..5d5edc9 100644 --- a/commands.go +++ b/commands.go @@ -265,6 +265,28 @@ func commandCreateIssue(git *gitlab.Client, room *mautrix.Room, sender string, a } } +func commandCommentOnIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []string, lines []string) { + if len(args) < 2 { + room.Send("Usage: !gitlab issue comment <repo> <issue id> [\\n] <body>") + return + } + + issueID, err := strconv.Atoi(args[1]) + if err != nil { + room.Sendf("Invalid issue ID: %s", args[1]) + } + + var body string + if len(args) > 2 { + body = strings.Join(args[2:], " ") + "\n" + } + body += strings.Join(lines, "\n") + + git.Notes.CreateIssueNote(args[0], issueID, &gitlab.CreateIssueNoteOptions{ + Body: &body, + }) +} + func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []string, lines []string) { if len(args) == 0 { room.SendHTML("Unknown subcommand. Try <code>!gitlab help issue</code> for help.") @@ -310,6 +332,7 @@ func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args [] room.Sendf("Failed to %s issue: %s", subcommand, err) } case "comment": + commandCommentOnIssue(git, room, sender, args, lines) case "read-comments": default: room.SendHTML("Unknown subcommand. Try <code>!gitlab help issue</code> for help.") -- GitLab