mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-31 03:41:16 +00:00
small fixes
This commit is contained in:
+15
-12
@@ -20,21 +20,18 @@ contract DGitI {
|
||||
}
|
||||
|
||||
contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
using StringLib for string;
|
||||
|
||||
DGitI dGit;
|
||||
function GitHubAPIOraclize(){
|
||||
dGit = DGitI(msg.sender);
|
||||
oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
|
||||
}
|
||||
using StringLib for string;
|
||||
DGitI dGit
|
||||
|
||||
string private cred = "f94095ba1d48038d4a81,36ae0e8b1bc5ad261c936e8f7f730f6c827c221f";
|
||||
string private credentials = "?client_id=f94095ba1d48038d4a81&client_secret=36ae0e8b1bc5ad261c936e8f7f730f6c827c221f";
|
||||
string private script = "QmU6pSQMDSg8do9eZLAfjzZYcC9JpsMZeB4ZoteGkSe94y";
|
||||
|
||||
enum OracleType { SET_REPOSITORY, SET_USER, CLAIM_COMMIT, UPDATE_ISSUE }
|
||||
mapping (bytes32 => OracleType) claimType; //temporary db enumerating oraclize calls
|
||||
mapping (bytes32 => CommitClaim) commitClaim; //temporary db for oraclize commit token claim calls
|
||||
mapping (bytes32 => UserClaim) userClaim; //temporary db for oraclize user register queries
|
||||
|
||||
|
||||
//stores temporary data for oraclize user register request
|
||||
struct UserClaim {
|
||||
address sender;
|
||||
@@ -45,8 +42,13 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
string repository;
|
||||
bytes20 commitid;
|
||||
}
|
||||
//register or change a github user ethereum address. 100000000000000000
|
||||
|
||||
|
||||
function GitHubAPIOraclize(){
|
||||
dGit = DGitI(msg.sender);
|
||||
oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
|
||||
}
|
||||
|
||||
//register or change a github user ethereum address. 100000000000000000
|
||||
function register(address _sender, string _github_user, string _gistid)
|
||||
payable only_owner{
|
||||
bytes32 ocid = oraclize_query("nested", StringLib.concat("[identity] ${[URL] https://gist.githubusercontent.com/",_github_user,"/",_gistid,"/raw/}, ${[URL] json(https://api.github.com/gists/").concat(_gistid,credentials,").owner.[id,login]}"));
|
||||
@@ -56,7 +58,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
|
||||
function updateCommits(string _repository, bytes20 _commitid)
|
||||
payable only_owner{
|
||||
bytes32 ocid = oraclize_query("computation", [script, "repo-update",_repository.concat(",", toString(_commitid)),cred]);
|
||||
bytes32 ocid = oraclize_query("computation", [script, "update-new",_repository.concat(",", toString(_commitid)),cred]);
|
||||
claimType[ocid] = OracleType.CLAIM_COMMIT;
|
||||
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:_commitid});
|
||||
}
|
||||
@@ -73,7 +75,6 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
|
||||
event OracleEvent(bytes32 myid, string result, bytes proof);
|
||||
//oraclize response callback
|
||||
|
||||
function __callback(bytes32 myid, string result, bytes proof) {
|
||||
OracleEvent(myid,result,proof);
|
||||
if (msg.sender != oraclize.cbAddress()){
|
||||
@@ -148,6 +149,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
function setAPICredentials(string _client_id, string _client_secret)
|
||||
only_owner {
|
||||
cred = StringLib.concat(_client_id,",", _client_secret);
|
||||
credentials = StringLib.concat("?client_id=",_client_id,"&client_secret="+_client_secret);
|
||||
}
|
||||
|
||||
function setScript(string _script) only_owner{
|
||||
@@ -157,6 +159,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
function clearAPICredentials()
|
||||
only_owner {
|
||||
cred = "";
|
||||
credentials = "";
|
||||
}
|
||||
|
||||
function toString(bytes20 self) internal constant returns (string) {
|
||||
|
||||
@@ -1,33 +1,10 @@
|
||||
import sys, os, argparse
|
||||
import json, urllib2, datetime
|
||||
from collections import defaultdict
|
||||
start = ''
|
||||
|
||||
def logmsg(msg):
|
||||
sys.stderr.write("[GitHubOracle] "+msg+" \n")
|
||||
|
||||
|
||||
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 > 3:
|
||||
sys.exit("400 Error") #bad call
|
||||
|
||||
logmsg("Started " + os.environ['ARG0'] + "(" + os.environ['ARG1']+")")
|
||||
|
||||
|
||||
|
||||
#global
|
||||
|
||||
claimed = defaultdict(bool)
|
||||
count = 0
|
||||
repo_link = ""
|
||||
|
||||
args = os.environ['ARG1']
|
||||
|
||||
class GitHubAPI:
|
||||
|
||||
auth = 0
|
||||
@@ -258,10 +235,10 @@ class GitRepository:
|
||||
if(elem["source"]["type"] == "issue"):
|
||||
pr = str(elem["source"]["issue"]["number"])
|
||||
#print pr
|
||||
link_pull = repo_link + "/pulls/" + pr
|
||||
link_pull = self.repo_link + "/pulls/" + pr
|
||||
pull = json.load(requestAPI(link_pull))
|
||||
if(pull['merged_at']):
|
||||
link_pulls_commits = repo_link + "/pulls/" + pr + "/commits"
|
||||
link_pulls_commits = self.repo_link + "/pulls/" + pr + "/commits"
|
||||
commits = json.load(api.request(link_pulls_commits))
|
||||
for commit in commits:
|
||||
if(commit['url']):
|
||||
@@ -284,6 +261,19 @@ def userRegister(github_user,gistid):
|
||||
logmsg("Wrong condition: "+github_user+" != "+login);
|
||||
sys.exit("403 Forbidden")
|
||||
|
||||
#Script start
|
||||
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 > 3:
|
||||
sys.exit("400 Error") #bad call
|
||||
|
||||
logmsg("Started " + os.environ['ARG0'] + "(" + os.environ['ARG1']+")")
|
||||
|
||||
#global
|
||||
script = os.environ['ARG0']
|
||||
args = [x.strip() for x in os.environ['ARG1'].split(',')]
|
||||
api = GitHubAPI()
|
||||
@@ -291,21 +281,17 @@ api = GitHubAPI()
|
||||
if api.checkLimit(5):
|
||||
if script == 'update-new':
|
||||
repository = GitRepository(api, args[0])
|
||||
try:
|
||||
if argn > 1:
|
||||
repository.setBranch(args[1])
|
||||
if argn > 2:
|
||||
repository.setHead(args[2])
|
||||
except IndexError:
|
||||
a = None
|
||||
|
||||
repository.updateCommits()
|
||||
|
||||
print "["+json.dumps(repository.data['id'])+",",
|
||||
print json.dumps(repository.data['full_name']) + "," + json.dumps(repository.branch['name']) + ",",
|
||||
print json.dumps(repository.head) + "," + json.dumps(repository.tail) + ",",
|
||||
print str(len(repository.points)) + ",",
|
||||
print json.dumps(repository.points.items()),
|
||||
print "]"
|
||||
|
||||
elif script == 'update-old':
|
||||
repository = GitRepository(api, args[0])
|
||||
repository.setBranch(args[1])
|
||||
@@ -320,7 +306,6 @@ if api.checkLimit(5):
|
||||
print str(len(repository.points)) + ",",
|
||||
print json.dumps(repository.points.items()),
|
||||
print "]"
|
||||
|
||||
elif script == 'repository-add':
|
||||
repository = GitRepository(api, args[0])
|
||||
print "["+json.dumps(repository.data['id'])+",",
|
||||
|
||||
Reference in New Issue
Block a user