forked from github/hubot-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-commiters.coffee
More file actions
46 lines (43 loc) · 1.59 KB
/
Copy pathgithub-commiters.coffee
File metadata and controls
46 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Description:
# Show the commiters from a repo
#
# Dependencies:
# "githubot": "0.2.0"
#
# Configuration:
# HUBOT_GITHUB_TOKEN
#
# Commands:
# hubot repo commiters <repo> - shows commiters of repository
# hubot repo top-commiters <repo> - shows top commiters of repository
#
# Author:
# vquaiato
module.exports = (robot) ->
github = require("githubot")(robot)
robot.respond /repo commiters (.*)$/i, (msg) ->
read_contributors msg, (commits) ->
max_length = commits.length
max_length = 20 if commits.length > 20
for commit in commits
msg.send "[#{commit.login}] #{commit.contributions}"
max_length -= 1
return unless max_length
robot.respond /repo top-commiter (.*)$/i, (msg) ->
read_contributors msg, (commits) ->
top_commiter = null
for commit in commits
top_commiter = commit if top_commiter == null
top_commiter = commit if commit.contributions > top_commiter.contributions
msg.send "[#{top_commiter.login}] #{top_commiter.contributions} :trophy:"
read_contributors = (msg, response_handler) ->
repo = github.qualified_repo msg.match[1]
url = "https://api.github.com/repos/#{repo}/contributors"
github.get url, (commits) ->
if commits.message
msg.send "Achievement unlocked: [NEEDLE IN A HAYSTACK] repository #{commits.message}!"
else if commits.length == 0
msg.send "Achievement unlocked: [LIKE A BOSS] no commits found!"
else
msg.send "http://github.com/#{repo}"
response_handler commits