mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-27 09:51:10 +00:00
docker script for commits
This commit is contained in:
@@ -3,6 +3,9 @@ import json, urllib2, datetime
|
||||
from collections import defaultdict
|
||||
start = ''
|
||||
|
||||
print "#############################"
|
||||
print "#############################"
|
||||
print "#############################"
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--client')
|
||||
@@ -15,6 +18,8 @@ parser.add_argument('--reponame')
|
||||
parser.add_argument('--issueid')
|
||||
parser.add_argument('--pullid')
|
||||
parser.add_argument('--commitid')
|
||||
parser.add_argument('--tail')
|
||||
parser.add_argument('--head')
|
||||
|
||||
|
||||
argn = []
|
||||
@@ -130,25 +135,46 @@ def updateIssue(issueid):
|
||||
points[author] += int(json.dumps(_commit['stats']['total']))
|
||||
print points.items()
|
||||
|
||||
#branchname required
|
||||
|
||||
def updateCommits(branchname, lastcommit):
|
||||
if(len(lastcommit) > 0):
|
||||
commit_link = repo_link + "/commits/" + lastcommit + auth
|
||||
req = urllib2.Request(commit_link)
|
||||
commit = json.load(urllib2.urlopen(req));
|
||||
setCommittedTree(commit)
|
||||
|
||||
branches_link = repo_link + "/branches/" + branchname + auth
|
||||
req = urllib2.Request(branches_link)
|
||||
branch = json.load(urllib2.urlopen(req));
|
||||
#print branch
|
||||
|
||||
commit_link = repo_link + "/commits/" + branch['commit']['sha'] + auth
|
||||
|
||||
|
||||
|
||||
|
||||
def updateCommits(branchname, head, tail):
|
||||
if(head is None and tail is not None): #tail only = error
|
||||
print "bad call"
|
||||
return
|
||||
elif(head is None and tail is None): #no head and no tail (new) = from latest head to reachable tails
|
||||
branches_link = repo_link + "/branches/" + branchname + auth
|
||||
req = urllib2.Request(branches_link)
|
||||
branch = json.load(urllib2.urlopen(req))
|
||||
_head = json.dumps(branch['commit']['sha'])[1:-1]
|
||||
head = _head
|
||||
elif(head is not None and tail is None): #head only (sync) = from latestHead to head
|
||||
setClaimedChunk(head, "")
|
||||
branches_link = repo_link + "/branches/" + branchname + auth
|
||||
req = urllib2.Request(branches_link)
|
||||
branch = json.load(urllib2.urlopen(req))
|
||||
_head = json.dumps(branch['commit']['sha'])[1:-1]
|
||||
head = _head
|
||||
elif(tail is not None and head is not None): #head and tail (continue) = continue from tail
|
||||
_head = tail
|
||||
|
||||
commit_link = repo_link + "/commits/" + _head + auth
|
||||
print commit_link
|
||||
req = urllib2.Request(commit_link)
|
||||
commit = json.load(urllib2.urlopen(req));
|
||||
loadPoints(commit)
|
||||
print points.items();
|
||||
|
||||
_head = json.load(urllib2.urlopen(req))
|
||||
ntail = loadPoints(_head)
|
||||
|
||||
print head + "," + json.dumps(ntail['sha']) + ",",
|
||||
print points.items(),
|
||||
|
||||
|
||||
#https://api.github.com/repos/status-im/github-oracle/compare/master...6e2528a9eb3fec21ca0679ec0c2a0935c2aa6656 COMPARE IF COMMIT IS IN `master`
|
||||
#https://api.github.com/repos/status-im/github-oracle/commits?per_page=100&sha=e0a340e72784b1322929d6803773b31a2b6b5707
|
||||
#https://api.github.com/repos/status-im/github-oracle/git/refs/heads BRANCHES
|
||||
#https://developer.github.com/v3/#conditional-requests
|
||||
|
||||
def setCommittedTree(commit):
|
||||
if(claimed[commit['sha']] == False):
|
||||
@@ -157,28 +183,49 @@ def setCommittedTree(commit):
|
||||
link_commit = json.dumps(parent['url'])[1:-1] + auth
|
||||
_commit = json.load(urllib2.urlopen(link_commit))
|
||||
setCommittedTree(_commit);
|
||||
|
||||
|
||||
def setClaimedChunk(head, tail):
|
||||
global count
|
||||
while (tail != head):
|
||||
commit_link = repo_link + "/commits" + auth + "&per_page=100&sha=" + head
|
||||
req = urllib2.Request(commit_link)
|
||||
commits = json.load(urllib2.urlopen(req));
|
||||
for commit in commits:
|
||||
if(claimed[commit['sha']] != True):
|
||||
claimed[commit['sha']] = True
|
||||
print "claimed "+str(count)+": "+commit['sha']
|
||||
count += 1
|
||||
head = commit['sha']
|
||||
if(len(commit['parents']) == 2):
|
||||
setClaimedChunk("", json.dumps(commit['parents'])[1][1:-1])
|
||||
if (tail == head):
|
||||
break
|
||||
if(len(commits) < 100):
|
||||
break
|
||||
return head
|
||||
|
||||
|
||||
def loadPoints(commit):
|
||||
def loadPoints(head):
|
||||
global count
|
||||
|
||||
while (claimed[commit['sha']] == False):
|
||||
claimed[commit['sha']] = True
|
||||
if (len(commit['parents']) < 2 and commit['author'] is not None):
|
||||
author = json.dumps(commit['author']['login'])[1:-1]
|
||||
points[author] += int(json.dumps(commit['stats']['total']))
|
||||
print str(count) + ": " + commit['sha'] +" +"+ str(commit['stats']['total'])
|
||||
count += 1
|
||||
if (len(commit['parents']) == 1):
|
||||
link_commit = json.dumps(commit['parents'][0]['url'])[1:-1] + auth
|
||||
commit = json.load(urllib2.urlopen(link_commit))
|
||||
while (claimed[head['sha']] == False and count < 1000):
|
||||
claimed[head['sha']] = True
|
||||
count += 1
|
||||
if (head['author'] is not None):
|
||||
author = json.dumps(head['author']['login'])[1:-1]
|
||||
if (len(points) > 5 and points[author] == 0): break;
|
||||
if (len(head['parents']) < 2):
|
||||
points[author] += int(json.dumps(head['stats']['total']))
|
||||
print str(count) + ": " + head['sha'] +" +"+ str(head['stats']['total'])
|
||||
else:
|
||||
print str(count) + ": " + head['sha'] +" -"+ str(head['stats']['total'])
|
||||
else:
|
||||
print str(count) + ": " + commit['sha'] +" -"+ str(commit['stats']['total'])
|
||||
count += 1
|
||||
for parent in commit['parents']:
|
||||
link_commit = json.dumps(parent['url'])[1:-1] + auth
|
||||
_commit = json.load(urllib2.urlopen(link_commit))
|
||||
loadPoints(_commit)
|
||||
print str(count) + ": " + head['sha'] +" x"+ str(head['stats']['total'])
|
||||
for parent in head['parents']:
|
||||
link_commit = json.dumps(parent['url'])[1:-1] + auth
|
||||
_commit = json.load(urllib2.urlopen(link_commit))
|
||||
head = loadPoints(_commit)
|
||||
return head
|
||||
|
||||
|
||||
|
||||
@@ -195,5 +242,5 @@ elif args.script == 'commit-points':
|
||||
elif args.script == 'commit-data':
|
||||
commitData(args.commitid)
|
||||
elif args.script== 'update-commits':
|
||||
updateCommits("master", "")
|
||||
updateCommits("master", args.head, args.tail)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user