6
6
import json
7
7
from datetime import timedelta , datetime
8
8
from dateutil import parser , relativedelta
9
- from script import userTopicResult
9
+ from algorithms . script import userTopicResult
10
10
11
11
12
12
import requests
13
13
14
+
15
+
14
16
class RepositoryMetrics :
15
17
16
18
def __init__ (self , name , owner , token ):
17
19
# initialize class variables
18
20
self .name = str (name )
19
21
self .owner = str (owner )
22
+ self .token = str (token )
20
23
self .reponame = self .name + '-' + self .owner
24
+ self .headers = {"Authorization" : "bearer " + self .token }
21
25
22
26
# User Profile Details
23
27
self .fullName = ''
@@ -83,7 +87,7 @@ def fetchBasicDetails(self):
83
87
}
84
88
"""
85
89
86
- request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = headers )
90
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = self . headers )
87
91
88
92
if request .status_code == 200 :
89
93
result = request .json ()
@@ -123,7 +127,7 @@ def calcActivityScore(self):
123
127
}
124
128
}
125
129
"""
126
- request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = headers )
130
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = self . headers )
127
131
128
132
if request .status_code == 200 :
129
133
result = request .json ()
@@ -186,7 +190,7 @@ def calcActivityScore(self):
186
190
}
187
191
}
188
192
"""
189
- request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = headers )
193
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = self . headers )
190
194
191
195
if request .status_code == 200 :
192
196
result = request .json ()
@@ -228,7 +232,7 @@ def calcActivityScore(self):
228
232
self .weeklyContributorNames .remove (user )
229
233
230
234
self .weeklyContributorsChange = len (clist ) - self .weeklyContributorsCount
231
- self .weeklyContributorsCount = len (clist )
235
+ self .weeklyContributorsCount = len (clist )
232
236
233
237
# -- ok
234
238
@@ -270,8 +274,8 @@ def calcInclusivityScore(self):
270
274
}
271
275
}
272
276
"""
273
- mergedPR = requests .post ('https://api.github.com/graphql' , json = {'query' : merged_prs_query }, headers = headers )
274
- totalPR = requests .post ('https://api.github.com/graphql' , json = {'query' : total_prs_query }, headers = headers )
277
+ mergedPR = requests .post ('https://api.github.com/graphql' , json = {'query' : merged_prs_query }, headers = self . headers )
278
+ totalPR = requests .post ('https://api.github.com/graphql' , json = {'query' : total_prs_query }, headers = self . headers )
275
279
276
280
if totalPR .status_code == 200 and mergedPR .status_code == 200 :
277
281
PRmergedData = mergedPR .json ()
@@ -308,7 +312,7 @@ def calcInclusivityScore(self):
308
312
}
309
313
}
310
314
"""
311
- request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = headers )
315
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = self . headers )
312
316
313
317
if request .status_code == 200 :
314
318
flag = 0
@@ -327,7 +331,7 @@ def calcInclusivityScore(self):
327
331
self .firstTimeContributorsThisWeek = self .firstTimeContributorsThisWeek + 1
328
332
329
333
330
- request = requests .get ('https://api.github.com/repos/' + str (self .owner ) + '/' + str (self .name ) + '/contributors?page=1&per_page=100&access_token=' + accessToken )
334
+ request = requests .get ('https://api.github.com/repos/' + str (self .owner ) + '/' + str (self .name ) + '/contributors?page=1&per_page=100&access_token=' + self . token )
331
335
332
336
if request .status_code == 200 :
333
337
result = request .json ()
@@ -346,7 +350,7 @@ def calcInclusivityScore(self):
346
350
347
351
while (flag != 0 ):
348
352
i = i + 1
349
- request = requests .get ('https://api.github.com/repos/' + str (self .owner ) + '/' + str (self .name ) + '/contributors?page=' + str (i ) + '&per_page=100&access_token=' + accessToken )
353
+ request = requests .get ('https://api.github.com/repos/' + str (self .owner ) + '/' + str (self .name ) + '/contributors?page=' + str (i ) + '&per_page=100&access_token=' + self . token )
350
354
351
355
if request .status_code == 200 :
352
356
@@ -365,8 +369,8 @@ def calcInclusivityScore(self):
365
369
366
370
def calcMeritScore (self ):
367
371
368
-
369
- # repo complexity
372
+
373
+ # repo complexity
370
374
371
375
query = """
372
376
{
@@ -381,21 +385,21 @@ def calcMeritScore(self):
381
385
}
382
386
}
383
387
"""
384
- request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = headers )
388
+ request = requests .post ('https://api.github.com/graphql' , json = {'query' : query }, headers = self . headers )
385
389
if request .status_code == 200 :
386
390
result = request .json ()
387
391
clist = list ()
388
392
for topic in result ["data" ]["repository" ]["repositoryTopics" ]["nodes" ]:
389
393
clist .append (topic ["topic" ]["name" ])
390
-
394
+
391
395
to_delete = set ()
392
- fileTopicList = open ("topics.txt" , "r" ).read ().split ('\n ' )
396
+ fileTopicList = open ("algorithms/ topics.txt" , "r" ).read ().split ('\n ' )
393
397
for topic in clist :
394
398
if topic not in fileTopicList :
395
399
to_delete .add (topic )
396
400
clist = list (set (clist )- to_delete )
397
401
398
- request = requests .get ("https://api.github.com/repos/" + str (self .owner ) + '/' + str (self .name ) + "/contributors?page=1&per_page=5&access_token=" + accessToken )
402
+ request = requests .get ("https://api.github.com/repos/" + str (self .owner ) + '/' + str (self .name ) + "/contributors?page=1&per_page=5&access_token=" + self . token )
399
403
if request .status_code == 200 :
400
404
result = request .json ()
401
405
usernameList = list ()
@@ -413,19 +417,19 @@ def calcMeritScore(self):
413
417
def calcRepoScore (self ):
414
418
self .repoPoints = self .basePoints + self .activityPoints + self .inclusivityPoints + self .meritPoints
415
419
420
+ """
421
+ RepositoryMetrics.token = "<token>"
416
422
417
-
418
- accessToken = "03e5d817f468829fd9b3307f55de055461460c1a"
419
- headers = {"Authorization" : "bearer " + accessToken }
420
423
421
424
username = input("Enter the owner name: ")
422
425
reponame = input("Enter the repository name: ")
423
- r = RepositoryMetrics (str (reponame ), str (username ), accessToken )
426
+ r=RepositoryMetrics(str(reponame), str(username), RepositoryMetrics.token )
424
427
425
428
print()
426
429
print("The Base Points: " + str(r.basePoints))
427
430
print("The Activity Points: " + str(r.activityPoints))
428
431
print("The Inclusivity Points: " + str(r.inclusivityPoints))
429
432
print("The Merit Points: " + str(r.meritPoints))
430
433
print()
431
- print ("The Repository Score is " + str (r .repoPoints ))
434
+ print("The Repository Score is " + str(r.repoPoints))
435
+ """
0 commit comments