changed to commit-update

This commit is contained in:
Ricardo Guilherme Schmidt
2017-04-05 06:34:24 +00:00
parent 9f10c8f69a
commit 62daed8abb
3 changed files with 79 additions and 41 deletions
+2
View File
@@ -19,5 +19,7 @@ library Bytes32Lib {
return string(bytesStringTrimmed);
}
}
+43 -15
View File
@@ -27,6 +27,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
dGit = DGitI(msg.sender);
}
string private credentials = ""; //store encrypted values of api access credentials
string private cred = "";
string private secret = "";
string private client = "";
string private script = "QmS3kHrUQ12ovovKPk9vxKjDPm7kVWcieaMcZc9w8JbNQt";
@@ -55,16 +56,13 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
userClaim[ocid] = UserClaim({sender: _sender, githubid: _github_user});
}
function claimCommit(string _repository, string _commitid)
function updateCommits(string _repository, bytes20 _commitid)
payable only_owner{
//uint256 repoid = db.getRepositoryId(_repository);
//if (repoid == 0) throw;
bytes20 commitid = _commitid.parseBytes20();
//if(db.getClaimed(repoid,commitid) == 0) throw;
string memory commit_url = StringLib.concat("https://api.github.com/repos/",_repository,"/commits/", _commitid, credentials));
bytes32 ocid = oraclize_query("URL", StringLib.concat("[identity] ${[URL] json(",commit_url,").[author,stats].[id,total]}"));
string memory cred = StringLib.concat(" -c ${[decrypt] ", _client_id,"} -s ${[decrypt] ", _client_secret,"}");
string memory commit_url = StringLib.concat("-S update-commits -r",_repository," -H ", toString(_commitid), cred);
bytes32 ocid = oraclize_query("computation", ['']);
claimType[ocid] = OracleType.CLAIM_COMMIT;
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:commitid});
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:_commitid});
}
function addRepository(string _repository)
@@ -87,7 +85,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
}else if(claimType[myid]==OracleType.SET_USER){
_register(myid, result);
}else if(claimType[myid]==OracleType.CLAIM_COMMIT){
_claimCommit(myid, result);
_updateCommits(myid, result);
}else if(claimType[myid] == OracleType.SET_REPOSITORY){
_setRepository(myid, result);
}else if(claimType[myid] == OracleType.UPDATE_ISSUE){
@@ -128,15 +126,25 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
(subscribers,pos) = JSONLib.getNextUInt(v,pos);
dGit.__setRepository(projectId,full_name,watchers,subscribers);
}
function _claimCommit(bytes32 myid, string result)
//034dacf29ac24ca92691d1ae2520882cc93a4df7,"a6690859cc20e27d2aad9ce1278778be10b7cc5a", 4, [('adrian-tiberius', 10), ('kagel', 10854), ('tpatja', 14509), ('jarradh', 1367)]
function _updateCommits(bytes32 myid, string result)
internal {
uint256 total; uint256 userId;
bytes memory v = bytes(result);
uint8 pos = 0;
(userId,pos) = JSONLib.getNextUInt(v,pos);
(total,pos) = JSONLib.getNextUInt(v,pos);
dGit.__claimCommit(commitClaim[myid].repository,commitClaim[myid].commitid,userId,total);
string memory temp;
uint numAuthors;
(temp,pos) = JSONLib.getNextString(v,pos);
bytes20 head = temp.toBytes20();
(temp,pos) = JSONLib.getNextString(v,pos);
bytes20 tail = temp.toBytes20();
(numAuthors,pos) = JSONLib.getNextUInt(v,pos);
uint userId;
uint points;
for(uint i; i < numAuthors; i++){
(userId,pos) = JSONLib.getNextUInt(v,pos);
(points,pos) = JSONLib.getNextUInt(v,pos);
dGit._setCommiter(commitClaim[myid].repository,userId,points);
}
delete commitClaim[myid];
}
@@ -145,6 +153,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
only_owner {
client = _client_id;
secret = _client_secret;
cred = StringLib.concat(" -c ${[decrypt] ", _client_id,"} -s ${[decrypt] ", _client_secret,"}");
credentials = StringLib.concat("?client_id=${[decrypt] ", _client_id,"}&client_secret=${[decrypt] ", _client_secret,"}");
}
@@ -158,7 +167,26 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
function clearAPICredentials()
only_owner {
credentials = "";
cred = "";
}
function toString(bytes20 self) internal constant returns (string) {
bytes memory bytesString = new bytes(20);
uint charCount = 0;
for (uint j = 0; j < 20; j++) {
byte char = byte(bytes20(uint(self) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
}
+34 -26
View File
@@ -3,23 +3,26 @@ import json, urllib2, datetime
from collections import defaultdict
start = ''
print "#############################"
print "#############################"
print "#############################"
parser = argparse.ArgumentParser()
parser.add_argument('--client')
parser.add_argument('--secret')
parser.add_argument('--script')
parser.add_argument('--username')
parser.add_argument('--userid')
parser.add_argument('--repoid')
parser.add_argument('--reponame')
parser.add_argument('--issueid')
parser.add_argument('--pullid')
parser.add_argument('--commitid')
parser.add_argument('--tail')
parser.add_argument('--head')
parser.add_argument('-S','--script')
parser.add_argument('-U','--username')
parser.add_argument('-u','--userid')
parser.add_argument('-R','--repoid')
parser.add_argument('-r','--reponame')
parser.add_argument('-C','--commitid')
parser.add_argument('-B','--branch')
parser.add_argument('-T','--tail')
parser.add_argument('-H','--head')
parser.add_argument('-I','--issueid')
parser.add_argument('-P','--pullid')
parser.add_argument('-c','--client')
parser.add_argument('-s','--secret')
argn = []
@@ -142,6 +145,10 @@ def updateIssue(issueid):
def updateCommits(branchname, head, tail):
if(branchname is None):
req = urllib2.Request(repo_link+auth)
repo = json.load(urllib2.urlopen(req))
branchname = json.dumps(repo['default_branch'])[1:-1]
if(head is None and tail is not None): #tail only = error
print "bad call"
return
@@ -162,13 +169,14 @@ def updateCommits(branchname, head, tail):
_head = tail
commit_link = repo_link + "/commits/" + _head + auth
print commit_link
#print commit_link
req = urllib2.Request(commit_link)
_head = json.load(urllib2.urlopen(req))
ntail = loadPoints(_head)
print head + "," + json.dumps(ntail['sha']) + ",",
print points.items(),
print json.dumps(head) + "," + json.dumps(ntail['sha']) + ", ",
print str(len(points)) + ", ",
print json.dumps(points.items()),
#https://api.github.com/repos/status-im/github-oracle/compare/master...6e2528a9eb3fec21ca0679ec0c2a0935c2aa6656 COMPARE IF COMMIT IS IN `master`
@@ -194,7 +202,7 @@ def setClaimedChunk(head, tail):
for commit in commits:
if(claimed[commit['sha']] != True):
claimed[commit['sha']] = True
print "claimed "+str(count)+": "+commit['sha']
#print "claimed "+str(count)+": "+commit['sha']
count += 1
head = commit['sha']
if(len(commit['parents']) == 2):
@@ -216,11 +224,11 @@ def loadPoints(head):
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) + ": " + head['sha'] +" x"+ str(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) + ": " + 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))
@@ -242,5 +250,5 @@ elif args.script == 'commit-points':
elif args.script == 'commit-data':
commitData(args.commitid)
elif args.script== 'update-commits':
updateCommits("master", args.head, args.tail)
updateCommits(args.branch, args.head, args.tail)