-
Notifications
You must be signed in to change notification settings - Fork 3
/
gh-issues.coffee
78 lines (71 loc) · 3.05 KB
/
gh-issues.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Description
# Hubot interface for GitHub issues
#
# Configuration:
# HUBOT_GH_ISSUES_DEFAULT_OWNER
# HUBOT_GH_ISSUES_DEFAULT_REPO
#
# Dependencies:
# hubot-gh-token
# octonode
#
# Commands:
# hubot github open issue "<title>" (about "<body>") (in "(<owner>/)<repo>") (with labels "<label1>,<label2>,..") - Opens a new issue
# hubot github show issue #<issue_number> (in (<owner>/)<repo>)
# hubot github close issue #<issue_number> (in (<owner>/)<repo>)
# hubot github comment issue #<issue_number> (in (<owner>/)<repo>) "<comment>"
# hubot github search issues "<query>" (in "(<owner>/)<repo>") (with labels "<label1>,<label2>,..") - Search issues
#
# Author:
# @benwtr
DEFAULT_OWNER = process.env.HUBOT_GH_ISSUES_DEFAULT_OWNER
DEFAULT_REPO = process.env.HUBOT_GH_ISSUES_DEFAULT_REPO
module.exports = (robot) ->
robot.respond /(?:github|gh) (?:open|create|new) issue "([^"]+)"(?: (?:about|regarding|re|body|description) "([^"]+)")?(?: in "([\w\d-_]+)(?:\/([\w\d-_]+))?")?(?: (?:with )?(?:tags|tag|labels|label|tagged) "([\w\d,-_]+)")?$/i, id: 'gh-issues.open', (msg) ->
title = msg.match[1]
body = msg.match[2] || ''
repo = if msg.match[3]? and msg.match[4]?
"#{msg.match[3]}/#{msg.match[4]}"
else if msg.match[3]?
"#{DEFAULT_OWNER}/#{msg.match[3]}"
else
"#{DEFAULT_OWNER}/#{DEFAULT_REPO}"
labels = if msg.match[5]? then msg.match[5].split(',') else []
robot.ghissues.openIssue msg, title, body, repo, labels
robot.respond /(?:github|gh) show issue #?(\d+)(?: in ([\w\d-_]+)(?:\/([\w\d-_]+))?)?$/i, id: 'gh-issues.show', (msg) ->
id = msg.match[1]
repo = if msg.match[2]? and msg.match[3]?
"#{msg.match[2]}/#{msg.match[3]}"
else if msg.match[2]?
"#{DEFAULT_OWNER}/#{msg.match[2]}"
else
"#{DEFAULT_OWNER}/#{DEFAULT_REPO}"
robot.ghissues.showIssue msg, id, repo
robot.respond /(?:github|gh) close issue #?(\d+)(?: in ([\w\d-_]+)(?:\/([\w\d-_]+))?)?$/i, id: 'gh-issues.close', (msg) ->
id = msg.match[1]
repo = if msg.match[2]? and msg.match[3]?
"#{msg.match[2]}/#{msg.match[3]}"
else if msg.match[2]?
"#{DEFAULT_OWNER}/#{msg.match[2]}"
else
"#{DEFAULT_OWNER}/#{DEFAULT_REPO}"
robot.ghissues.closeIssue msg, id, repo
robot.respond /(?:github|gh) comment issue #?(\d+)(?: in ([\w\d-_]+)(?:\/([\w\d-_]+))?)? "(.*)"$/i, id: 'gh-issues.comment', (msg) ->
id = msg.match[1]
repo = if msg.match[2]? and msg.match[3]?
"#{msg.match[2]}/#{msg.match[3]}"
else if msg.match[2]?
"#{DEFAULT_OWNER}/#{msg.match[2]}"
else
"#{DEFAULT_OWNER}/#{DEFAULT_REPO}"
comment = msg.match[4]
robot.ghissues.commentOnIssue msg, comment, id, repo
robot.respond /(?:github|gh) search issues "([^"]+)"(?: in "([\w\d-_]+)(?:\/([\w\d-_]+))?")?$/i, id: 'gh-issues.search', (msg) ->
query = msg.match[1]
repo = if msg.match[2]? and msg.match[3]?
"#{msg.match[2]}/#{msg.match[3]}"
else if msg.match[2]?
"#{DEFAULT_OWNER}/#{msg.match[2]}"
else
"#{DEFAULT_OWNER}/#{DEFAULT_REPO}"
robot.ghissues.searchIssues msg, query, repo