|
8 | 8 | # Configuration:
|
9 | 9 | # HUBOT_GITHUB_REPO
|
10 | 10 | # The `user/repository` that you want to connect to. example: github/hubot-scripts
|
| 11 | +# HUBOT_GITHUB_USER |
| 12 | +# The `user` that you want to connect to. example: github |
11 | 13 | # HUBOT_GITHUB_TOKEN
|
12 | 14 | # You can retrieve your github token via:
|
13 | 15 | # curl -i https://api.github.com/authorizations -d '{"scopes":["repo"]}' -u "yourusername"
|
|
21 | 23 | # http[s]://yourdomain.com/api/v3/ for Enterprise installations.
|
22 | 24 | #
|
23 | 25 | # Commands:
|
24 |
| -# Listens for <SHA> and links to the commit for your default repo on github |
| 26 | +# Listens for <SHA>s with at least seven characters: |
| 27 | +# <SHA> links to that commit in HUBOT_GITHUB_REPO |
| 28 | +# repo@<SHA> links to that commit in HUBOT_GITHUB_USER's repo |
| 29 | +# user/repo@<SHA> links to that commit in user/repo |
| 30 | +# Unless the string 'commit/' shows up in the line, in which case it |
| 31 | +# is ignored. |
25 | 32 | #
|
26 | 33 | # Author:
|
27 | 34 | # achiu
|
28 | 35 |
|
29 | 36 | module.exports = (robot) ->
|
30 | 37 | github = require("githubot")(robot)
|
31 |
| - robot.hear /.*(\b[0-9a-f]{7,40}\b).*/i, (msg) -> |
| 38 | + robot.hear /// |
| 39 | + ^.*? # non-greedy pre-commit-reference text |
| 40 | + \b # word boundary before the commit reference |
| 41 | + (?:([^\s@]+)@)? # optional repo@ or user/repo@ qualifier |
| 42 | + ([0-9a-f]{7,40}) # commit hash (>= 7 and <= 40 hex digits long) |
| 43 | + \b # word boundary after the commit reference |
| 44 | + .*$ # post-commit-reference text |
| 45 | + ///i, (msg) -> |
32 | 46 | if process.env.HUBOT_GITHUB_REPO && process.env.HUBOT_GITHUB_TOKEN
|
33 | 47 | if !(msg.message.text.match(/commit\//))
|
34 |
| - commit_sha = msg.match[1].replace /\b/, "" |
35 |
| - bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO |
| 48 | + commit_sha = msg.match[2] |
| 49 | + if msg.match[1]? |
| 50 | + bot_github_repo = github.qualified_repo msg.match[1] |
| 51 | + else |
| 52 | + bot_github_repo = github.qualified_repo process.env.HUBOT_GITHUB_REPO |
36 | 53 | issue_title = ""
|
37 | 54 | base_url = process.env.HUBOT_GITHUB_API || 'https://api.github.com'
|
38 | 55 | github.get "#{base_url}/repos/#{bot_github_repo}/commits/" + commit_sha, (commit_obj) ->
|
|
0 commit comments