mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-27 09:51:10 +00:00
added issue-update
This commit is contained in:
@@ -27,10 +27,8 @@ 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";
|
||||
string private cred = "f94095ba1d48038d4a81,36ae0e8b1bc5ad261c936e8f7f730f6c827c221f";
|
||||
string private script = "QmU6pSQMDSg8do9eZLAfjzZYcC9JpsMZeB4ZoteGkSe94y";
|
||||
|
||||
enum OracleType { SET_REPOSITORY, SET_USER, CLAIM_COMMIT, UPDATE_ISSUE }
|
||||
mapping (bytes32 => OracleType) claimType; //temporary db enumerating oraclize calls
|
||||
@@ -149,26 +147,18 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
//owner management
|
||||
function setAPICredentials(string _client_id, string _client_secret)
|
||||
only_owner {
|
||||
client = _client_id;
|
||||
secret = _client_secret;
|
||||
cred = StringLib.concat("${[decrypt] ", _client_id,"},${[decrypt] ", _client_secret,"}");
|
||||
credentials = StringLib.concat("?client_id=${[decrypt] ", _client_id,"}&client_secret=${[decrypt] ", _client_secret,"}");
|
||||
cred = StringLib.concat(_client_id,",", _client_secret);
|
||||
}
|
||||
|
||||
|
||||
function setScript(string _script) only_owner{
|
||||
script = _script;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearAPICredentials()
|
||||
only_owner {
|
||||
credentials = "";
|
||||
cred = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function toString(bytes20 self) internal constant returns (string) {
|
||||
bytes memory bytesString = new bytes(20);
|
||||
uint charCount = 0;
|
||||
|
||||
Binary file not shown.
@@ -2,13 +2,20 @@ import sys, os, argparse
|
||||
import json, urllib2, datetime
|
||||
from collections import defaultdict
|
||||
start = ''
|
||||
verbose = 0
|
||||
try:
|
||||
argn = int(os.environ['ARGN'])
|
||||
except KeyError:
|
||||
sys.exit("400 Error") #bad call
|
||||
if argn < 2:
|
||||
sys.exit("404 Error") #no default function
|
||||
|
||||
if argn == 4:
|
||||
if os.environ['ARG3'] == "--verbose":
|
||||
verbose = 1
|
||||
else: #only --verbose option accepted
|
||||
sys.exit("400 Error") #bad call
|
||||
if argn > 4:
|
||||
sys.exit("400 Error") #bad call
|
||||
|
||||
def oAuth(client, secret, code):
|
||||
# POST https://github.com/login/oauth/access_token
|
||||
@@ -45,7 +52,6 @@ if argn > 2:
|
||||
|
||||
args = os.environ['ARG1']
|
||||
|
||||
|
||||
def requestAPI(api_link, arguments_get=None, arguments_post=None):
|
||||
if arguments_get is None:
|
||||
arguments_get = []
|
||||
@@ -74,7 +80,6 @@ def getRepositoryURL(repository, name=True):
|
||||
repo_link = "https://api.github.com/repositories/"
|
||||
return repo_link + repository
|
||||
|
||||
|
||||
def repositoryAdd(full_name):
|
||||
repository = json.load(requestAPI(getRepositoryURL(full_name)))
|
||||
print "["+json.dumps(repository['id'])+",",
|
||||
@@ -125,7 +130,7 @@ def loadPoints(head, old_head="", claim_head=True):
|
||||
commits = json.load(requestAPI(commit_link, [['per_page', '100'], ["sha", head]]))
|
||||
for commit in commits:
|
||||
if commit['sha'] != old_head:
|
||||
print "claim "+str(count)+": "+commit['sha'] + " ",
|
||||
#print "claim "+str(count)+": "+commit['sha'] + " ",
|
||||
count += 1
|
||||
if len(commit['parents']) < 2 and commit['author'] is not None and (claim_head or commit['sha'] != head):
|
||||
if len(points) > 5 and points[author] == 0:
|
||||
@@ -133,11 +138,11 @@ def loadPoints(head, old_head="", claim_head=True):
|
||||
commit = json.load(requestAPI(commit['url']))
|
||||
author = json.dumps(commit['author']['login'])[1:-1]
|
||||
points[author] += int(commit['stats']['additions'])
|
||||
print author + " +" + str(commit['stats']['additions']) + " -"+ str(commit['stats']['deletions']) + " |= " + str(commit['stats']['total'])
|
||||
else:
|
||||
print "<invalid>"
|
||||
#print author + " +" + str(commit['stats']['additions']) + " -"+ str(commit['stats']['deletions']) + " |= " + str(commit['stats']['total'])
|
||||
#else:
|
||||
#print "<invalid>"
|
||||
else:
|
||||
print "ended "+str(count)+": "+commit['sha']
|
||||
#print "ended "+str(count)+": "+commit['sha']
|
||||
break
|
||||
head = commit['sha']
|
||||
if len(commits) < 100:
|
||||
@@ -153,6 +158,34 @@ def userRegister(github_user,gistid):
|
||||
else:
|
||||
sys.exit("403 Forbidden")
|
||||
|
||||
def updateIssue(repository,issueid):
|
||||
global repo_link
|
||||
link_issue = repo_link + "/issues/" + issueid
|
||||
issue = json.load(requestAPI(link_issue))
|
||||
print issue['state'] + ", " + datetime.datetime.strptime( json.dumps(issue['closed_at'])[1:-1], "%Y-%m-%dT%H:%M:%SZ" ).strftime('%s') + ", ",
|
||||
|
||||
link_issue = repo_link + "/issues/" + issueid + "/timeline"
|
||||
requestAPI(link_issue, None, ["Accept","application/vnd.github.mockingbird-preview"])
|
||||
|
||||
issue = json.load(urllib2.urlopen(req))
|
||||
|
||||
for elem in issue:
|
||||
if(elem["event"] == "cross-referenced"):
|
||||
if(elem["source"]["type"] == "issue"):
|
||||
pr = str(elem["source"]["issue"]["number"])
|
||||
#print pr
|
||||
link_pull = repo_link + "/pulls/" + pr
|
||||
pull = json.load(requestAPI(link_pull))
|
||||
if(pull['merged_at']):
|
||||
link_pulls_commits = repo_link + "/pulls/" + pr + "/commits"
|
||||
commits = json.load(requestAPI(link_pulls_commits))
|
||||
for commit in commits:
|
||||
if(commit['url']):
|
||||
_commit = json.load(requestAPI(commit['url']))
|
||||
author = _commit['author']['login']
|
||||
points[author] += int(json.dumps(_commit['stats']['total']))
|
||||
print points.items()
|
||||
|
||||
script = os.environ['ARG0']
|
||||
args = [x.strip() for x in os.environ['ARG1'].split(',')]
|
||||
|
||||
@@ -172,5 +205,7 @@ elif script == 'repo-add':
|
||||
repositoryAdd(args[0])
|
||||
elif script == "user-add":
|
||||
userRegister(args[0],args[1])
|
||||
elif script == "issue-update":
|
||||
issueUpdate(args[0],args[1])
|
||||
else:
|
||||
sys.exit("501 Not implemented")
|
||||
|
||||
Reference in New Issue
Block a user