From 6ae54217d30fa2ba334b8b49154a1a43b85ce3b9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 May 2014 21:16:32 -0700 Subject: [PATCH 1/2] github-commits: Add HUBOT_GITIO to make Git.io shortening opt-in Short URLs are nice, but when I don't have a browser running, I prefer something with the unadulterated commit hash. With the new envorinment variable, you can turn Git.io shortening on or off as you see fit. The alternative URL manipulation and HUBOT_GITHUB_API docs come from github-commit-link.coffee. --- src/scripts/github-commits.coffee | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/scripts/github-commits.coffee b/src/scripts/github-commits.coffee index f52fde2e2..f1e4b024c 100644 --- a/src/scripts/github-commits.coffee +++ b/src/scripts/github-commits.coffee @@ -4,10 +4,16 @@ # Dependencies: # "url": "" # "querystring": "" -# "gitio2": "2.0.0" +# "gitio2": "2.0.0" (optional) # # Configuration: -# Just put this url :/hubot/gh-commits?room= into you'r github hooks +# Put this url :/hubot/gh-commits?room= into your GitHub hooks +# HUBOT_GITIO +# Set nonempty for shortened URLs. If not unset or empty, you +# don't need gitio2. +# HUBOT_GITHUB_API +# Optional, default is https://api.github.com. Override with +# http[s]://yourdomain.com/api/v3/ for Enterprise installations. # # Commands: # None @@ -20,7 +26,8 @@ url = require('url') querystring = require('querystring') -gitio = require('gitio2') +if process.env.HUBOT_GITIO + gitio = require('gitio2') module.exports = (robot) -> @@ -42,8 +49,18 @@ module.exports = (robot) -> robot.send user, "Got #{push.commits.length} new #{commitWord} from #{push.commits[0].author.name} on #{push.repository.name}" for commit in push.commits do (commit) -> - gitio commit.url, (err, data) -> - robot.send user, " * #{commit.message} (#{if err then commit.url else data})" + if process.env.HUBOT_GITIO + gitio commit.url, (err, data) -> + if not err + commit.url = data + else + if process.env.HUBOT_GITHUB_API + commit.url = commit.url.replace(/api\/v3\//,'') + else + commit.url = commit.url.replace(/api\./,'') + commit.url = commit.url.replace(/repos\//,'') + commit.url = commit.url.replace(/commits/,'commit') + robot.send user, " * #{commit.message} (#{commit.url})" else if push.created robot.send user, "#{push.pusher.name} created: #{push.ref}: #{push.base_ref}" From 3237f88b605e47fabd977a7bda8c4ec91b9f2926 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 May 2014 21:26:54 -0700 Subject: [PATCH 2/2] github-commits: Add HUBOT_COMMIT_ONELINE to only show the summary line Following 660ae28 (github-commit-link: Only show the first line of the commit, 2014-03-13), but configurable this time, for folks who push tiny feature branches and *do* actually want the whole message dumped into their channel. --- src/scripts/github-commits.coffee | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/scripts/github-commits.coffee b/src/scripts/github-commits.coffee index f1e4b024c..76381da88 100644 --- a/src/scripts/github-commits.coffee +++ b/src/scripts/github-commits.coffee @@ -14,6 +14,9 @@ # HUBOT_GITHUB_API # Optional, default is https://api.github.com. Override with # http[s]://yourdomain.com/api/v3/ for Enterprise installations. +# HUBOT_COMMIT_ONELINE +# Set nonempty to only show the summary lines. If not unset or +# empty, show the full message. # # Commands: # None @@ -60,7 +63,9 @@ module.exports = (robot) -> commit.url = commit.url.replace(/api\./,'') commit.url = commit.url.replace(/repos\//,'') commit.url = commit.url.replace(/commits/,'commit') - robot.send user, " * #{commit.message} (#{commit.url})" + if process.env.HUBOT_COMMIT_ONELINE + commit.message = commit.message.split("\n")[0] + "\n" + robot.send user, "* #{commit.message} (#{commit.url})" else if push.created robot.send user, "#{push.pusher.name} created: #{push.ref}: #{push.base_ref}"