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

Commit 5000b5c

Browse files
Merge pull request #911 from theodi/master
Tweaked github-issue-link to allow linking to other repos
2 parents ea62c6d + 7da3135 commit 5000b5c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/scripts/github-issue-link.coffee

Lines changed: 17 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,9 @@
1112
# HUBOT_GITHUB_API
1213
#
1314
# Commands:
14-
# Listens for #nnn and links to the issue for your default repo on github
15+
# #nnn - link to GitHub issue nnn for HUBOT_GITHUB_REPO project
16+
# repo#nnn - link to GitHub issue nnn for repo project
17+
# user/repo#nnn - link to GitHub issue nnn for user/repo project
1518
#
1619
# Notes:
1720
# HUBOT_GITHUB_API allows you to set a custom URL path (for Github enterprise users)
@@ -21,18 +24,23 @@
2124

2225
module.exports = (robot) ->
2326
github = require("githubot")(robot)
24-
robot.hear /.*(#(\d+)).*/, (msg) ->
25-
issue_number = msg.match[1].replace /#/, ""
27+
robot.hear /.*( (\S*)?#(\d+)).*/, (msg) ->
28+
issue_number = msg.match[3]
2629
if isNaN(issue_number)
2730
return
28-
29-
bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO
31+
32+
if msg.match[2] == undefined
33+
bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO
34+
else
35+
bot_github_repo = github.qualified_repo msg.match[2]
36+
3037
issue_title = ""
3138
base_url = process.env.HUBOT_GITHUB_API || 'https://api.github.com'
39+
3240
github.get "#{base_url}/repos/#{bot_github_repo}/issues/" + issue_number, (issue_obj) ->
3341
issue_title = issue_obj.title
3442
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}"
43+
url = "https://github.com"
44+
else
45+
url = base_url.replace /\/api\/v3/, ''
46+
msg.send "Issue #{issue_number}: #{issue_title} #{url}/#{bot_github_repo}/issues/#{issue_number}"

0 commit comments

Comments
 (0)