forked from ansible/ansibullbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-module-alert.py
executable file
·60 lines (46 loc) · 2.21 KB
/
new-module-alert.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
#!/usr/bin/python
# Very simple reporting script for status of new modules in Ansible extras.
# No auth, no args. Just pulling basic query data and parsing it for reporting
# to the Ansible community (ansible-project and ansible-devel mailing lists).
#
# Will use the new_issue_alert.j2 template.
# FIXME:
# * In loop: Pick out all PRs in last week by issue['created_at']
# * In loop: Pick out oldest unreviewed PRs by issue['created_at'] (in community review)
# * Be sure to include individual URLs ['pull_request']['html_url']
import os, requests, json, sys, argparse, time
from jinja2 import Environment, FileSystemLoader
loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates'))
environment = Environment(loader=loader, trim_blocks=True)
repo_url = 'https://api.github.com/repos/ansible/ansible-modules-extras/issues?labels=new_plugin'
args = {'state':'open', 'page':1}
# Get number of pages
r = requests.get(repo_url, params=args)
try:
lastpage = int(str(r.links['last']['url']).split('=')[-1])
except:
lastpage = 1
total_prs = 0
latest_module_string = ''
oldest_module_string = ''
oldest_module_time = time.time()
for page in range(1,lastpage):
pull_args = {'state':'open', 'page':page}
r = requests.get(repo_url, params=pull_args)
for issue in r.json():
total_prs += 1
issue_time = time.mktime((time.strptime(issue['created_at'], "%Y-%m-%dT%H:%M:%SZ")))
issue_age = int((time.time()-issue_time)/86400)
if issue_age < 7:
latest_module_string += issue['title'] + "\n"
latest_module_string += issue['html_url'] + "\n\n"
if issue_time < oldest_module_time:
oldest_module_time = issue_time
oldest_module_string = issue['title'] + " (" + str(issue_age) + " days old)\n" + issue['html_url']+ "\n\n"
# Final report
#print "Total PRs: ", total_prs
#print "Latest new module PRs this week: \n", latest_module_string
#print "Oldest new module PR: \n", oldest_module_string
template = environment.get_template('new_issue_alert.j2')
comment = template.render(total_prs=total_prs, latest_module_string=latest_module_string, oldest_module_string = oldest_module_string)
print comment.encode('ascii','ignore')