-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathapp.py
146 lines (127 loc) · 5.4 KB
/
app.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import json
import os
import requests
f=open("members.txt","r")
repos=[]
openissues=0
closedissues=0
openprs=0
closedprs=0
itercount=0
os.system("git pull --rebase origin master")
while (1):
name=f.readline()
if not name: break
name=name.strip()
url = "https://api.github.com/graphql"
headers = {"Authorization": "Basic "+str(os.environ['OUATH_KEY'])}
repo_cur=issue_cur=pr_cur="first: 100"
while (1):
query = json.dumps({"query": "query{user(login: \"" + name +
"\") { repositories("+str(repo_cur)+"){edges{node{url isFork}} pageInfo{endCursor hasNextPage}} issues("+str(issue_cur)+")\
{edges{node{state}} pageInfo {endCursor hasNextPage}} pullRequests("+str(pr_cur)+"){edges{node{state}} pageInfo \
{endCursor hasNextPage}} }}"})
print("query",query)
r = requests.post(url, headers=headers, data=query)
data_dict = json.loads(str(r.content))
try:
next_repo=data_dict['data']['user']['repositories']['pageInfo']['endCursor']
except:
next_repo="errored"
try:
next_issue=data_dict['data']['user']['issues']['pageInfo']['endCursor']
except:
next_issue="errored"
try:
next_pr=data_dict['data']['user']['pullRequests']['pageInfo']['endCursor']
except:
next_pr="errored"
print ("data dict",data_dict)
if next_repo!="errored":
for repo in data_dict['data']['user']['repositories']['edges']:
if repo['node']['isFork']==False:
repos.append(repo['node']['url'])
if next_repo!=None and data_dict['data']['user']['repositories']['pageInfo']['hasNextPage']!=False:
repo_cur='first:100 after:"'+str(next_repo)+'" '
else:
repo_cur='first: 0'
if next_issue!="errored":
for issue in data_dict['data']['user']['issues']['edges']:
if issue['node']['state']=='CLOSED':
closedissues+=1
else:
openissues+=1
if next_issue!=None and data_dict['data']['user']['issues']['pageInfo']['hasNextPage']!=False:
issue_cur='first: 100 after:"'+str(next_issue)+'" '
else:
issue_cur='first: 0'
if next_pr!="errored":
for pr in data_dict['data']['user']['pullRequests']['edges']:
if pr['node']['state']=='MERGED':
closedprs+=1
elif pr['node']['state']=='OPEN':
openprs+=1
if next_pr!=None and data_dict['data']['user']['pullRequests']['pageInfo']['hasNextPage']!=False:
pr_cur='first: 100 after:"'+str(next_pr)+'" '
else:
pr_cur='first: 0'
if (data_dict['data']['user']['repositories']['pageInfo']['hasNextPage']==False or next_repo==None) and (data_dict['data']['user']\
['issues']['pageInfo']['hasNextPage']==False or next_issue==None) and (data_dict['data']['user']['pullRequests']['pageInfo']\
['hasNextPage']==False or next_pr==None): break
itercount+=1
repos=set(repos)
print repos
print "before comma: "
print openissues
print closedissues
print openprs
print closedprs
def insertcomma(num):
length=len(num)
count=0
while(count<length):
if count==1:
count+=1; continue
if count%2==1:
num=num[:length-count]+','+num[length-count:]
count+=1
return num
openissues = insertcomma(str(openissues))
closedissues = insertcomma(str(closedissues))
openprs = insertcomma(str(openprs))
closedprs = insertcomma(str(closedprs))
print "open issues: "+openissues
print "closed issues: "+closedissues
print "open prs: "+openprs
print "closed prs: "+closedprs
print "repeated: "+str(itercount)
# import os<!-- Closed issues -->
lines_of_code=0
for repo in repos:
os.system("git clone --depth 1 "+str(repo)+".git ")
os.system("cloc "+str(repo).split('/')[-1]+" > out")
f=open("out","r")
alltext=f.read()
# print alltext
# print alltext.split(' ')[-1].split('-')[0]
try:
lines_of_code+=int(alltext.split(' ')[-1].split('-')[0])
os.system("rm -rf "+str(repo.split('/')[-1]))
except:
pass
# lines_of_code=str(lines_of_code)
# print lines_of_code
lines_of_code = insertcomma(str(lines_of_code))
print ("lines of code",lines_of_code)
f=open("index.tmpl","r")
all_lines=f.read()
all_lines=all_lines.replace("<!-- Open PRs -->",str(openprs))
all_lines=all_lines.replace("<!-- Closed PRs -->",str(closedprs))
all_lines=all_lines.replace("<!-- Open Issues -->",str(openissues))
all_lines=all_lines.replace(" <!-- Closed issues -->",str(closedissues))
all_lines=all_lines.replace("<!-- Lines -->",str(lines_of_code))
f=open("index.html","r")
all_prev_lines=f.read()
if all_prev_lines!=all_lines:
f=open("index.html","w")
f.write(all_lines)