Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Allows PR changelog to be requested by URL
Browse files Browse the repository at this point in the history
  • Loading branch information
athieriot committed Jun 25, 2013
1 parent 07c4df9 commit dafec7c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.coffee
Expand Up @@ -20,7 +20,7 @@ module.exports = (grunt) ->

mochacli:
options:
reporter: 'spec',
reporter: 'nyan',
globals: ['data']

all: ['test/**/*.coffee']
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -70,7 +70,7 @@ You can even have the last Pull Request filtered like 'with'

$ albot pulls last athieriot

Finally, if you are lazy (like me), you can copy/paste an URL from your browser
Finally, if you are lazy (like me), you can copy/paste a URL from your browser

$ albot pulls https://github.com/flatiron/nock/pull/110

Expand Down Expand Up @@ -124,6 +124,10 @@ You can get the changes for a specified Pull Request

$ albot changelog webapp pr 620

Or copy/paste a URL from your browser

$ albot changelog https://github.com/flatiron/nock/pull/110

The changes of the master branch since a certain period
Like in the Pulls command, all usable keys comes from Moment.js here: [Moment#add](http://momentjs.com/docs/#/manipulating/add/)

Expand Down
1 change: 1 addition & 0 deletions TODO
Expand Up @@ -10,6 +10,7 @@ Improvement:
Maybe
- Better Link customisation when printing (template)
- Inspect more than the first page of PRs
- Add usage statistics for each commands

Commands:
- Github status: https://status.github.com/api
Expand Down
15 changes: 12 additions & 3 deletions lib/changelog.coffee
Expand Up @@ -14,10 +14,19 @@ Utils = require './utils'

changelog = (fallback, repo, keyword, filter, period, save) ->
repo = Deploy.aliases[repo] || repo
org = Github.Org

# First we verify if the first argument is an URL
match = Utils.githubPRUrlMatching repo
if (match?)
org = match.org
repo = match.repo
keyword = 'pr'
filter = match.number

if (keyword == 'pr')
Github.Api.pullRequests.getCommits {
user: Github.Org
user: org
repo: repo
number: filter
}, (error, commits) ->
Expand All @@ -28,7 +37,7 @@ changelog = (fallback, repo, keyword, filter, period, save) ->

if (keyword == 'since')
Github.Api.repos.getCommits {
user: Github.Org
user: org
repo: repo
since: Moment().subtract(period, filter).format()
}, (error, commits) ->
Expand All @@ -46,7 +55,7 @@ changelog = (fallback, repo, keyword, filter, period, save) ->
last = _.last filter.split("..")

Github.Api.repos.compareCommits {
user: Github.Org
user: org
repo: repo
base: first
head: last
Expand Down
9 changes: 3 additions & 6 deletions lib/pulls.coffee
Expand Up @@ -84,16 +84,13 @@ getInfoPull = (org, reponame, number, callback) ->
order: details.created_at
}

githubUrlPattern = new RegExp "(http|https):\/\/github.com+([a-z0-9\-\.,@\?^=%&;:\/~\+#]*[a-z0-9\-@\?^=%&;\/~\+#])?",'i'

#TODO: Speeeeeeeeeeed
pulls = (fallback, keyword, filter) ->

# First we verify if the argument is an URL
matching = keyword.match(githubUrlPattern) if _.isString(keyword)
if (matching and _.str.include(keyword, 'pull'))
pull = matching[2].split('\/')
getInfoPull pull[1], pull[2], pull[4], (error, result) ->
match = Utils.githubPRUrlMatching keyword
if (match?)
getInfoPull match.org, match.repo, match.number, (error, result) ->
if (error?)
Utils.fallback_printError(fallback, error)
else
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.coffee
Expand Up @@ -5,6 +5,18 @@ Hipchat = Configuration.Hipchat
Async = require 'async'
Styled = require 'styled'

githubUrlPattern = new RegExp "(http|https):\/\/github.com+([a-z0-9\-\.,@\?^=%&;:\/~\+#]*[a-z0-9\-@\?^=%&;\/~\+#])?",'i'

githubPRUrlMatching = (url) ->
matching = url.match(githubUrlPattern) if _.isString(url)
if (matching and _.str.include(url, 'pull'))
pull = matching[2].split('\/')
{
org: pull[1]
repo: pull[2]
number: pull[4]
}

status_icon = (status) ->
if (status?)
if status then "" else ""
Expand Down Expand Up @@ -97,6 +109,7 @@ fallback_printError = (fallback, error) ->
fallback_print(fallback) { title: "An error occured: #{JSON.stringify(error)}", status: false }

module.exports = {
githubPRUrlMatching: githubPRUrlMatching,
format_term: format_term,
format_html: format_html,
print: print,
Expand Down
23 changes: 23 additions & 0 deletions test/commands/changelog.coffee
Expand Up @@ -8,6 +8,29 @@ Querystring = require 'querystring'

describe 'Commands', () ->
describe '#changelog()', () ->
it 'Can display the commits of a PR based on an URL', (done) ->
Nock('https://api.github.com')
.persist()
.get('/repos/testorg-ext/god/pulls/156/commits?access_token=testtoken')
.reply(200, [{
"commit": {
"message": "Commit message"
"committer": {
"date": "2011-01-26T19:01:12Z"
}
},
"committer": {
"gravatar_id": "lksajglkfdjg"
}
}])

Commands.changelog.action (object) ->
object.title.should.be.equal 'Commit message'
object.comments.should.be.equal Moment("2011-01-26T19:01:12Z").fromNow()
object.avatar.should.be.equal "lksajglkfdjg"
done()
, 'https://github.com/testorg-ext/god/pull/156'

it 'Can display the commits of a PR', (done) ->
Nock('https://api.github.com')
.persist()
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
@@ -1,4 +1,4 @@
--compilers coffee:coffee-script
--check-leaks
--reporter spec
--reporter nyan
--globals data

0 comments on commit dafec7c

Please sign in to comment.