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

Commit

Permalink
Merge 0035cf4 into bace2e1
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkoian committed Jun 22, 2013
2 parents bace2e1 + 0035cf4 commit c8aac8b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ node_modules/
covershot/
lib-cov/
.idea/
.albot.json
96 changes: 96 additions & 0 deletions lib/changelog.coffee
@@ -0,0 +1,96 @@
Configuration = require './configuration'
Deploy = Configuration.Nconf.get('deploy')
Changelog = Configuration.Nconf.get('changelog')

_ = require('underscore')._
_.str = require 'underscore.string'
_.mixin _.str.exports()

Github = Configuration.Github
Async = require 'async'
Moment = require 'moment'

Utils = require './utils'

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

if (keyword == 'pr')
Github.Api.pullRequests.getCommits {
user: Github.Org
repo: repo
number: filter
}, (error, commits) ->
if (error?)
Utils.fallback_printError(fallback, error)
else
display(fallback, commits, period)

if (keyword == 'since')
Github.Api.repos.getCommits {
user: Github.Org
repo: repo
since: Moment().subtract(period, filter).format()
}, (error, commits) ->
if (error?)
Utils.fallback_printError(fallback, error)
else
display(fallback, commits, save)

if (keyword == 'between')
if (_.str.include filter, "...")
first = _.first filter.split("...")
last = _.last filter.split("...")
else
first = _.first filter.split("..")
last = _.last filter.split("..")

Github.Api.repos.compareCommits {
user: Github.Org
repo: repo
base: first
head: last
}, (error, diff) ->
if (error?)
Utils.fallback_printError(fallback, error)
else
display(fallback, diff.commits, period)

display = (fallback, commits, save) ->
list = _.map commits, (commit) -> {
title: commit.commit.message
comments: Moment(commit.commit.committer.date).fromNow()
order: commit.commit.committer.date
}
list = _.filter list, (object) ->
not object.title.match(new RegExp '^Merge')

if (save == "save")
gist list, (error, url) ->
if (error?)
Utils.fallback_printError(fallback, error)
else
Utils.fallback_print(fallback) {
title: "View the changelog"
url: url
comments: url
status: true
}
else
Utils.fallback_printList fallback, list

gist = (list, callback) ->
data = _.reduce list, (memo, o) ->
memo += '- ' + o.title + ' - *' + o.comments + '*' + '\n'
, ""

Github.Api.gists.edit { id: Changelog.gistId, files: {"history.md": { content: data } }}, (err, gist) ->
if (err?) then callback(err) else callback(null, gist.html_url)

module.exports = {
name: "Changelog"
description: "-project- | -alias- [-pr- [-number-]
| -since- [-number-] [-period-] | -between- [-tag-range-]
] [-save-] List changelog for a given PR, period, range ",
action: changelog
}
1 change: 1 addition & 0 deletions lib/commands.coffee
Expand Up @@ -17,6 +17,7 @@ help = (fallback) ->
list = {
pulls: require('./pulls'),
deploy: require('./deploy'),
changelog: require('./changelog')
help: {
name: "Help"
description: "Display a list of available commands",
Expand Down
9 changes: 5 additions & 4 deletions lib/server.coffee
Expand Up @@ -13,10 +13,11 @@ dispatch = (message) ->
# TODO: Loop
pattern = new RegExp "^#{Configuration.Nickname} ([a-zA-Z0-9]+)
( ([a-zA-Z0-9\-\+\/\.\:]+))?
( ([a-zA-Z0-9\-\+]+))?
( ([a-zA-Z0-9\-\+]+))?
( ([a-zA-Z0-9\-\+]+))?
( ([a-zA-Z0-9\-\+]+))?$"
( ([a-zA-Z0-9\-\+\/\.\:]+))?
( ([a-zA-Z0-9\-\+\/\.\:]+))?
( ([a-zA-Z0-9\-\+\/\.\:]+))?
( ([a-zA-Z0-9\-\+\/\.\:]+))?
( ([a-zA-Z0-9\-\+\/\.\:]+))?$"

request = message.match(pattern)
if (request and request.length > 1)
Expand Down

0 comments on commit c8aac8b

Please sign in to comment.