diff --git a/contracts/src/DGitDB.sol b/contracts/src/DGitDB.sol index 71b3051..531da92 100644 --- a/contracts/src/DGitDB.sol +++ b/contracts/src/DGitDB.sol @@ -24,8 +24,9 @@ contract DGitDBI { function getRepositoryAddress(string _full_name) constant returns(address); function getUserAddress(uint256 _id) constant returns(address); function getUserAddress(string _login) constant returns(address); - function getClaimed(uint256 _repoid, bytes20 _commitid) constant returns (uint); - function setClaimed(uint256 _repoid, bytes20 _commitid, uint _userid, uint _points); + function getClaimedHead(uint256 _repoid) constant returns (bytes20); + function getClaimedTail(uint256 _repoid) constant returns (bytes20); + function setClaimed(uint256 _repoid, bytes20 _head, bytes20 _tail, uint points); } contract DGitDB is DGitDBI, Owned { @@ -41,14 +42,10 @@ contract DGitDB is DGitDBI, Owned { string full_name; address addr; uint points; - mapping (bytes20 => Commit) commits; - + bytes20 head; + bytes20 tail; } - struct Commit { - uint points; - uint userId; - } struct User { string login; @@ -56,15 +53,18 @@ contract DGitDB is DGitDBI, Owned { address addr; } - function setClaimed(uint256 _repoid, bytes20 _commitid, uint _userid, uint _points) + function setClaimed(uint256 _repoid, bytes20 _head, bytes20 _tail, uint _points) only_owner { - repositories[_repoid].commits[_commitid].userId = _userid; - repositories[_repoid].commits[_commitid].points = _points; + repositories[_repoid].head = _head; + repositories[_repoid].tail = _tail; repositories[_repoid].points += _points; } - function getClaimed(uint256 _repoid, bytes20 _commitid) constant returns (uint){ - return repositories[_repoid].commits[_commitid].userId; + function getClaimedHead(uint256 _repoid) constant returns (bytes20){ + return repositories[_repoid].head; + } + function getClaimedTail(uint256 _repoid) constant returns (bytes20){ + return repositories[_repoid].tail; } function addRepository(uint256 _id, uint256 _owner, string _name, string _full_name, address _addr) only_owner { diff --git a/scripts/oraclize-args/testarg.py b/scripts/oraclize-args/testarg.py index 716977a..072de87 100644 --- a/scripts/oraclize-args/testarg.py +++ b/scripts/oraclize-args/testarg.py @@ -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)