Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 4625127

Browse files
committed
Tweaked github-issue-link to allow linking to other repos
1 parent 581545a commit 4625127

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/scripts/github-issue-link.coffee

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Description:
22
# Github issue link looks for #nnn and links to that issue for your default
33
# repo. Eg. "Hey guys check out #273"
4+
# Defaults to issues in HUBOT_GITHUB_REPO, unless a repo is specified Eg. "Hey guys, check out awesome-repo#273"
45
#
56
# Dependencies:
67
# "githubot": "0.2.0"
@@ -11,7 +12,8 @@
1112
# HUBOT_GITHUB_API
1213
#
1314
# Commands:
14-
# Listens for #nnn and links to the issue for your default repo on github
15+
# Listens for #nnn or repo-name#nnn and links to the issue on github.
16+
# Defaults to issues in HUBOT_GITHUB_REPO, unless a repo is specified
1517
#
1618
# Notes:
1719
# HUBOT_GITHUB_API allows you to set a custom URL path (for Github enterprise users)
@@ -21,18 +23,23 @@
2123

2224
module.exports = (robot) ->
2325
github = require("githubot")(robot)
24-
robot.hear /.*(#(\d+)).*/, (msg) ->
25-
issue_number = msg.match[1].replace /#/, ""
26+
robot.hear /.*( (\S*)?#(\d+)).*/, (msg) ->
27+
issue_number = msg.match[3]
2628
if isNaN(issue_number)
2729
return
28-
29-
bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO
30+
31+
if msg.match[2] == undefined
32+
bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO
33+
else
34+
bot_github_repo = github.qualified_repo msg.match[2]
35+
3036
issue_title = ""
3137
base_url = process.env.HUBOT_GITHUB_API || 'https://api.github.com'
38+
3239
github.get "#{base_url}/repos/#{bot_github_repo}/issues/" + issue_number, (issue_obj) ->
3340
issue_title = issue_obj.title
3441
unless process.env.HUBOT_GITHUB_API
35-
url = "https://github.com"
36-
else
37-
url = base_url.replace /\/api\/v3/, ''
38-
msg.send "Issue #{issue_number}: #{issue_title} #{url}/#{bot_github_repo}/issues/#{issue_number}"
42+
url = "https://github.com"
43+
else
44+
url = base_url.replace /\/api\/v3/, ''
45+
msg.send "Issue #{issue_number}: #{issue_title} #{url}/#{bot_github_repo}/issues/#{issue_number}"

0 commit comments

Comments
 (0)