-
Notifications
You must be signed in to change notification settings - Fork 3
/
tcispy.py
87 lines (69 loc) · 2.63 KB
/
tcispy.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# -----------------------------------------------------------
# tcispy.py
#
# Pull author and committer names and emails from travis-ci.
#
# Usage:
# mkvirtualenv travispy
# pip install travispy
# python ./tcispy.py <target/repo> <access_token>
#
# Example:
# python ./tcispy.py rapid7/nexpose-client d84dda6de6244eb5c30d3ef3eeda957d390a4ee7 2>/dev/null
# -----------------------------------------------------------
from sys import argv, exit
from travispy import TravisPy
def main():
# -----------------------------------------------------------
# quick sanity check for args
# -----------------------------------------------------------
if len(argv) != 3:
print 'Insufficient arguments.'
print 'Usage: {} <target/repo> <access_token>'.format(argv[0])
print 'Example: {} rapid7/nexpose-client d84dda6de6244eb5c30d3ef3eeda957d390a4ee7'.format(argv[0])
exit(1)
# -----------------------------------------------------------
# generate a token on github with the following access:
# repo:status
# repo_deployment
# read:org
# write:repo_hook
# user:email
#
# populate the github_token variable with the resulting token
# -----------------------------------------------------------
target_repo = argv[1]
github_token = argv[2]
# -----------------------------------------------------------
# minimal client setup
# -----------------------------------------------------------
t = TravisPy.github_auth(github_token)
builds = t.builds(slug=target_repo)
# -----------------------------------------------------------
# append users as a tuple (name, email). some users have
# multiple email addresses, and we want everything
# -----------------------------------------------------------
users = []
for b in builds:
try:
build = t.build(b.id)
except AttributeError:
pass
users.append((build.commit.author_name, build.commit.author_email))
users.append((build.commit.committer_name, build.commit.committer_email))
# -----------------------------------------------------------
# trim the collection to unique tuples
# -----------------------------------------------------------
unique = list(set(users))
# -----------------------------------------------------------
# aaaaaaaaaaaand dump
# -----------------------------------------------------------
print 'Name,Email'
for u in unique:
print '{},{}'.format(u[0], u[1])
# -----------------------------------------------------------
# make it do the thing
# -----------------------------------------------------------
if __name__ == '__main__':
main()