Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/scripts/github-commits.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
# Dependencies:
# "url": ""
# "querystring": ""
# "gitio2": "2.0.0"
# "gitio2": "2.0.0" (optional)
#
# Configuration:
# Just put this url <HUBOT_URL>:<PORT>/hubot/gh-commits?room=<room> into you'r github hooks
# Put this url <HUBOT_URL>:<PORT>/hubot/gh-commits?room=<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.
# HUBOT_COMMIT_ONELINE
# Set nonempty to only show the summary lines. If not unset or
# empty, show the full message.
#
# Commands:
# None
Expand All @@ -20,7 +29,8 @@

url = require('url')
querystring = require('querystring')
gitio = require('gitio2')
if process.env.HUBOT_GITIO
gitio = require('gitio2')

module.exports = (robot) ->

Expand All @@ -42,8 +52,20 @@ 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) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done asynchronously, so if you set process.env.HUBOT_GITIO, this updated commit.url isn't ensured to be set by the time robot.send is called.

To get around that, I'd suggest refactoring most of the logic to it's own function, so it can either be called in a callback for gitio if process.env.HUBOT_GITIO or by itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Sat, May 24, 2014 at 07:51:09AM -0700, Josh Nichols wrote:

To get around that, I'd suggest refactoring most of the logic to
it's own function, …

I've pulled this out into githubot with iangreenleaf/githubot#25.
Once that lands and is released, I'll update this PR with the
associated githubot bumps and API changes.

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')
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}"
Expand Down