Skip to content
Snippets Groups Projects
Commit cc2f9f2f authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Add support for commenting on issues

parent d9e22b8a
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ A Gitlab bot for Matrix. It uses ...@@ -16,7 +16,7 @@ A Gitlab bot for Matrix. It uses
* [x] Read issues * [x] Read issues
* [x] Create/close/reopen issues * [x] Create/close/reopen issues
* [ ] Read comments on issues * [ ] Read comments on issues
* [ ] Comment on issues * [x] Comment on issues
## Usage ## Usage
Configure the server by copying `example-config.json` to `config.json` and Configure the server by copying `example-config.json` to `config.json` and
......
...@@ -265,6 +265,28 @@ func commandCreateIssue(git *gitlab.Client, room *mautrix.Room, sender string, a ...@@ -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) { func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []string, lines []string) {
if len(args) == 0 { if len(args) == 0 {
room.SendHTML("Unknown subcommand. Try <code>!gitlab help issue</code> for help.") 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 [] ...@@ -310,6 +332,7 @@ func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []
room.Sendf("Failed to %s issue: %s", subcommand, err) room.Sendf("Failed to %s issue: %s", subcommand, err)
} }
case "comment": case "comment":
commandCommentOnIssue(git, room, sender, args, lines)
case "read-comments": case "read-comments":
default: default:
room.SendHTML("Unknown subcommand. Try <code>!gitlab help issue</code> for help.") room.SendHTML("Unknown subcommand. Try <code>!gitlab help issue</code> for help.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment