mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-27 09:51:10 +00:00
isolated GitHubAPI
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* Contract that oracle github API
|
||||
*
|
||||
* GitHubOracle register users and create GitHubToken contracts
|
||||
* Registration requires user create a gist with only their account address
|
||||
* GitHubOracle will create one GitHubToken contract per repository
|
||||
* GitHubToken mint tokens by commit only for registered users in GitHubOracle
|
||||
* GitHubToken is a LockableCoin, that accept donatations and can be withdrawn by Token Holders
|
||||
* The lookups are done by Oraclize that charge a small fee
|
||||
* The contract itself will never charge any fee
|
||||
*
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
import "lib/oraclize/oraclizeAPI_0.4.sol";
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
import "./GitHubAPI.sol";
|
||||
import "./DGitDB.sol";
|
||||
import "./GitRepository.sol";
|
||||
|
||||
contract DGit is Owned, DGitI {
|
||||
|
||||
DGitDBI public db;
|
||||
GitHubAPI public gitHubApi;
|
||||
|
||||
function initialize() only_owner {
|
||||
db = DBFactory.newStorage();
|
||||
gitHubApi = QueryFactory.newGitHubAPI();
|
||||
}
|
||||
|
||||
function register(string _github_user, string _gistid) payable{
|
||||
gitHubApi.register.value(msg.value)(msg.sender,_github_user,_gistid);
|
||||
}
|
||||
function claimCommit(string _repository, string _commitid) payable{
|
||||
gitHubApi.claimCommit.value(msg.value)(_repository,_commitid);
|
||||
}
|
||||
function addRepository(string _repository) payable{
|
||||
gitHubApi.addRepository.value(msg.value)(_repository);
|
||||
}
|
||||
function updateIssue(string _repository, string issue) payable{
|
||||
gitHubApi.updateIssue.value(msg.value)(_repository,issue);
|
||||
}
|
||||
function getRepository(uint projectId) constant returns (address){
|
||||
return db.getRepositoryAddress(projectId);
|
||||
}
|
||||
function getRepository(string full_name) constant returns (address){
|
||||
return db.getRepositoryAddress(full_name);
|
||||
}
|
||||
|
||||
modifier only_gitapi{
|
||||
if (msg.sender != address(gitHubApi)) throw;
|
||||
_;
|
||||
}
|
||||
|
||||
event UserSet(string githubLogin);
|
||||
function __register(address addrLoaded, uint256 userId, string login)
|
||||
only_gitapi {
|
||||
UserSet(login);
|
||||
db.addUser(userId, login, 0, addrLoaded);
|
||||
}
|
||||
|
||||
event GitRepositoryRegistered(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers);
|
||||
function __setRepository(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers) only_gitapi //[83725290, "ethereans/github-token", 4, 2]
|
||||
{
|
||||
uint256 ownerId; string memory name; //TODO
|
||||
address repository = db.getRepositoryAddress(projectId);
|
||||
if(repository == 0x0){
|
||||
GitRepositoryRegistered(projectId,full_name,watchers,subscribers);
|
||||
repository = GitFactory.newGitRepository(projectId,full_name);
|
||||
db.addRepository(projectId,ownerId,name,full_name,repository);
|
||||
}
|
||||
GitRepositoryI(repository).setStats(subscribers,watchers);
|
||||
}
|
||||
|
||||
event NewClaim(string repository, bytes20 commitid, uint userId, uint total );
|
||||
function __claimCommit(string repository, bytes20 commitid, uint userId, uint total)
|
||||
only_gitapi {
|
||||
NewClaim(repository,commitid,userId,total);
|
||||
GitRepositoryI repoaddr = GitRepositoryI(db.getRepositoryAddress(repository));
|
||||
repoaddr.claim(commitid, db.getUserAddress(userId), total);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,25 @@ pragma solidity ^0.4.8;
|
||||
*/
|
||||
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
import "./GitHubOracleStorageI.sol";
|
||||
contract GitHubOracleStorage is GitHubOracleStorageI, Owned {
|
||||
|
||||
contract DGitDBI {
|
||||
function addRepository(uint256 _id, uint256 _owner, string _name, string _full_name, address _addr);
|
||||
function addUser(uint256 _id, string _login, uint8 _type, address _addr);
|
||||
function setRepositoryAddress(uint256 _repositoryId, address _repositoryAddress);
|
||||
function setRepositoryName(uint256 _repositoryId, string _full_name, string _name);
|
||||
function setUserAddress(uint userId, address account);
|
||||
function setUserName(uint256 _userId, string _name);
|
||||
function getRepositoryId(string _full_name) constant returns (uint256);
|
||||
function getRepositoryName(uint256 _id) constant returns (string);
|
||||
function getRepositoryAddress(uint256 _id) constant returns(address);
|
||||
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);
|
||||
}
|
||||
|
||||
contract DGitDB is DGitDBI, Owned {
|
||||
|
||||
mapping (string => uint256) repositoryNames;
|
||||
mapping (string => uint256) userNames;
|
||||
@@ -23,24 +40,40 @@ contract GitHubOracleStorage is GitHubOracleStorageI, Owned {
|
||||
string name;
|
||||
string full_name;
|
||||
address addr;
|
||||
uint256 claimed;
|
||||
uint points;
|
||||
mapping (bytes20 => Commit) commits;
|
||||
|
||||
}
|
||||
|
||||
struct Commit {
|
||||
uint points;
|
||||
uint userId;
|
||||
}
|
||||
|
||||
struct User {
|
||||
string login;
|
||||
uint8 utype;
|
||||
address addr;
|
||||
uint256 claimed;
|
||||
}
|
||||
|
||||
function setClaimed(uint256 _repoid, bytes20 _commitid, uint _userid, uint _points)
|
||||
only_owner {
|
||||
repositories[_repoid].commits[_commitid].userId = _userid;
|
||||
repositories[_repoid].commits[_commitid].points = _points;
|
||||
repositories[_repoid].points += _points;
|
||||
}
|
||||
|
||||
function getClaimed(uint256 _repoid, bytes20 _commitid) constant returns (uint){
|
||||
return repositories[_repoid].commits[_commitid].userId;
|
||||
}
|
||||
|
||||
function addRepository(uint256 _id, uint256 _owner, string _name, string _full_name, address _addr) only_owner {
|
||||
repositories[_id] = Repository({owner:_owner,name:_name,full_name:_full_name,addr:_addr,claimed:0});
|
||||
repositories[_id] = Repository({owner:_owner,name:_name,full_name:_full_name,addr:_addr,points:0});
|
||||
repositoryNames[_full_name] = _id;
|
||||
}
|
||||
|
||||
function addUser(uint256 _id, string _login, uint8 _utype, address _addr) only_owner{
|
||||
users[_id] = User({login:_login,utype:_utype,addr:_addr, claimed:0});
|
||||
users[_id] = User({login:_login,utype:_utype,addr:_addr});
|
||||
userNames[_login] = _id;
|
||||
}
|
||||
|
||||
@@ -88,4 +121,12 @@ contract GitHubOracleStorage is GitHubOracleStorageI, Owned {
|
||||
return repositories[_id].full_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
library DBFactory {
|
||||
|
||||
function newStorage() returns (DGitDBI){
|
||||
return new DGitDB();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +1,41 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* Contract that oracle github API
|
||||
*
|
||||
* GitHubOracle register users and create GitHubToken contracts
|
||||
* Registration requires user create a gist with only their account address
|
||||
* GitHubOracle will create one GitHubToken contract per repository
|
||||
* GitHubToken mint tokens by commit only for registered users in GitHubOracle
|
||||
* GitHubToken is a LockableCoin, that accept donatations and can be withdrawn by Token Holders
|
||||
* The lookups are done by Oraclize that charge a small fee
|
||||
* The contract itself will never charge any fee
|
||||
*
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
import "lib/StringLib.sol";
|
||||
import "lib/JSONLib.sol";
|
||||
pragma solidity ^0.4.9;
|
||||
|
||||
import "lib/oraclize/oraclizeAPI_0.4.sol";
|
||||
import "lib/StringLib.sol";
|
||||
import "lib/JSONLib.sol";
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
import "./factory/GRFactory.sol";
|
||||
import "./factory/DBFactory.sol";
|
||||
import "./storage/GitHubOracleStorageI.sol";
|
||||
|
||||
|
||||
contract GitHubOracle is Owned, usingOraclize {
|
||||
contract GitHubAPI{
|
||||
function register(address _sender, string _github_user, string _gistid) payable;
|
||||
function claimCommit(string _repository, string _commitid) payable;
|
||||
function addRepository(string _repository) payable;
|
||||
function updateIssue(string _repository, string issue) payable;
|
||||
}
|
||||
|
||||
using StringLib for string;
|
||||
|
||||
GitHubOracleStorageI public db;
|
||||
contract DGitI {
|
||||
function __register(address addrLoaded, uint256 userId, string login);
|
||||
function __setRepository(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers);
|
||||
function __claimCommit(string repository, bytes20 commitid, uint userid, uint total);
|
||||
}
|
||||
|
||||
contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
using StringLib for string;
|
||||
|
||||
DGitI dGit;
|
||||
function GitHubAPIOraclize(){
|
||||
dGit = DGitI(msg.sender);
|
||||
}
|
||||
string private credentials = ""; //store encrypted values of api access credentials
|
||||
string private secret = "";
|
||||
string private client = "";
|
||||
string private script = "QmS3kHrUQ12ovovKPk9vxKjDPm7kVWcieaMcZc9w8JbNQt";
|
||||
|
||||
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
|
||||
|
||||
string private credentials = ""; //store encrypted values of api access credentials
|
||||
string private secret = "";
|
||||
string private client = "";
|
||||
string private script = "";
|
||||
|
||||
//stores temporary data for oraclize user register request
|
||||
struct UserClaim {
|
||||
address sender;
|
||||
@@ -49,66 +44,38 @@ contract GitHubOracle is Owned, usingOraclize {
|
||||
//stores temporary data for oraclize repository commit claim
|
||||
struct CommitClaim {
|
||||
string repository;
|
||||
string commitid;
|
||||
bytes20 commitid;
|
||||
}
|
||||
|
||||
function GitHubOracle(){ //
|
||||
db = DBFactory.newStorage();
|
||||
}
|
||||
|
||||
//register or change a github user ethereum address 100000000000000000
|
||||
function register(string _github_user, string _gistid)
|
||||
payable {
|
||||
//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]}"));
|
||||
claimType[ocid] = OracleType.SET_USER;
|
||||
userClaim[ocid] = UserClaim({sender: msg.sender, githubid: _github_user});
|
||||
userClaim[ocid] = UserClaim({sender: _sender, githubid: _github_user});
|
||||
}
|
||||
|
||||
function claimCommit(string _repository, string _commitid)
|
||||
payable {
|
||||
payable only_owner{
|
||||
//uint256 repoid = db.getRepositoryId(_repository);
|
||||
//if (repoid == 0) throw;
|
||||
bytes20 commitid = _commitid.parseBytes20();
|
||||
//if(db.getClaimed(repoid,commitid) == 0) throw;
|
||||
bytes32 ocid = oraclize_query("URL", StringLib.concat("json(https://api.github.com/repos/",_repository,"/commits/", _commitid, credentials).concat(").[author,stats].[id,total]"));
|
||||
claimType[ocid] = OracleType.CLAIM_COMMIT;
|
||||
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:_commitid});
|
||||
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:commitid});
|
||||
}
|
||||
|
||||
function addRepository(string _repository)
|
||||
payable {
|
||||
payable only_owner{
|
||||
bytes32 ocid = oraclize_query("URL", StringLib.concat("json(https://api.github.com/repos/",_repository,credentials,").$.id,full_name,watchers,subscribers_count"),4000000);
|
||||
claimType[ocid] = OracleType.SET_REPOSITORY;
|
||||
}
|
||||
|
||||
function getRepository(uint projectId) constant returns (address){
|
||||
return db.getRepositoryAddress(projectId);
|
||||
}
|
||||
|
||||
function getRepository(string full_name) constant returns (address){
|
||||
return db.getRepositoryAddress(full_name);
|
||||
}
|
||||
|
||||
function setScript(string _script){
|
||||
script = _script;
|
||||
}
|
||||
|
||||
//owner management
|
||||
function setAPICredentials(string _client_id, string _client_secret)
|
||||
only_owner {
|
||||
credentials = StringLib.concat("?client_id=${[decrypt] ", _client_id,"}&client_secret=${[decrypt] ", _client_secret,"}");
|
||||
function updateIssue(string _repository, string issue) payable only_owner{
|
||||
bytes32 ocid = oraclize_query("computation", [script, StringLib.concat("--reponame ",_repository, " --issueid ", issue, " --script issue-status").concat(" --client ", client, " --secret ", secret)]);
|
||||
}
|
||||
|
||||
function clearAPICredentials()
|
||||
only_owner {
|
||||
credentials = "";
|
||||
}
|
||||
|
||||
|
||||
function bountyIssue(uint repositoryId, uint issueId) payable{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Internal Functions
|
||||
//
|
||||
|
||||
event OracleEvent(bytes32 myid, string result, bytes proof);
|
||||
//oraclize response callback
|
||||
|
||||
@@ -126,7 +93,6 @@ contract GitHubOracle is Owned, usingOraclize {
|
||||
delete claimType[myid]; //should always be deleted
|
||||
}
|
||||
|
||||
event UserSet(string githubLogin);
|
||||
function _register(bytes32 myid, string result)
|
||||
internal {
|
||||
uint256 userId; string memory login; address addrLoaded;
|
||||
@@ -136,34 +102,25 @@ contract GitHubOracle is Owned, usingOraclize {
|
||||
(addrLoaded,pos) = JSONLib.getNextAddr(v,pos);
|
||||
(userId,pos) = JSONLib.getNextUInt(v,pos);
|
||||
(login,pos) = JSONLib.getNextString(v,pos);
|
||||
if(userClaim[myid].sender == addrLoaded && userClaim[myid].githubid.compare(login) == 0){
|
||||
UserSet(login);
|
||||
db.addUser(userId, login, utype, addrLoaded);
|
||||
} //TODO: update user login and address;
|
||||
if(userClaim[myid].sender == addrLoaded){
|
||||
dGit.__register(addrLoaded, userId, login);
|
||||
}
|
||||
delete userClaim[myid]; //should always be deleted
|
||||
}
|
||||
|
||||
event GitRepositoryRegistered(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers);
|
||||
function _setRepository(bytes32 myid, string result) internal //[83725290, "ethereans/github-token", 4, 2]
|
||||
{
|
||||
uint256 projectId; string memory full_name; uint256 watchers; uint256 subscribers;
|
||||
uint256 ownerId; string memory name; //TODO
|
||||
//uint256 ownerId; string memory name; //TODO
|
||||
bytes memory v = bytes(result);
|
||||
uint8 pos = 0;
|
||||
(projectId,pos) = JSONLib.getNextUInt(v,pos);
|
||||
(full_name,pos) = JSONLib.getNextString(v,pos);
|
||||
(watchers,pos) = JSONLib.getNextUInt(v,pos);
|
||||
(subscribers,pos) = JSONLib.getNextUInt(v,pos);
|
||||
address repository = db.getRepositoryAddress(projectId);
|
||||
if(repository == 0x0){
|
||||
GitRepositoryRegistered(projectId,full_name,watchers,subscribers);
|
||||
repository = GRFactory.newGitRepository(projectId,full_name);
|
||||
db.addRepository(projectId,ownerId,name,full_name,repository);
|
||||
}
|
||||
GitRepositoryI(repository).setStats(subscribers,watchers);
|
||||
dGit.__setRepository(projectId,full_name,watchers,subscribers);
|
||||
}
|
||||
|
||||
event NewClaim(string repository, string commitid, uint userid, uint total );
|
||||
function _claimCommit(bytes32 myid, string result)
|
||||
internal {
|
||||
uint256 total; uint256 userId;
|
||||
@@ -171,13 +128,36 @@ contract GitHubOracle is Owned, usingOraclize {
|
||||
uint8 pos = 0;
|
||||
(userId,pos) = JSONLib.getNextUInt(v,pos);
|
||||
(total,pos) = JSONLib.getNextUInt(v,pos);
|
||||
NewClaim(commitClaim[myid].repository,commitClaim[myid].commitid,userId,total);
|
||||
GitRepositoryI repository = GitRepositoryI(db.getRepositoryAddress(commitClaim[myid].repository));
|
||||
repository.claim(commitClaim[myid].commitid.parseBytes20(), db.getUserAddress(userId), total);
|
||||
delete commitClaim[myid]; //should always be deleted
|
||||
dGit.__claimCommit(commitClaim[myid].repository,commitClaim[myid].commitid,userId,total);
|
||||
delete commitClaim[myid];
|
||||
}
|
||||
|
||||
//owner management
|
||||
function setAPICredentials(string _client_id, string _client_secret)
|
||||
only_owner {
|
||||
client = _client_id;
|
||||
secret = _client_secret;
|
||||
credentials = StringLib.concat("?client_id=${[decrypt] ", _client_id,"}&client_secret=${[decrypt] ", _client_secret,"}");
|
||||
}
|
||||
|
||||
|
||||
function setScript(string _script) only_owner{
|
||||
script = _script;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function clearAPICredentials()
|
||||
only_owner {
|
||||
credentials = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
library QueryFactory {
|
||||
|
||||
function newGitHubAPI() returns (GitHubAPI){
|
||||
return new GitHubAPIOraclize();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* DO NOT USE: under development
|
||||
*/
|
||||
import "./GitHubOracle.sol";
|
||||
|
||||
|
||||
contract GitHubIssues {
|
||||
|
||||
//Address of the oracle, used for github login address lookup
|
||||
GitHubOracle public oracle;
|
||||
//stores repository name, used for claim calls
|
||||
string private repository;
|
||||
uint private uid;
|
||||
mapping (uint => Issue) issues;
|
||||
|
||||
struct Issue {
|
||||
bool state;
|
||||
uint balance;
|
||||
uint unlock;
|
||||
address claimer;
|
||||
bool claimed;
|
||||
}
|
||||
|
||||
|
||||
modifier only_oracle {
|
||||
if (msg.sender != address(oracle)) throw;
|
||||
_;
|
||||
}
|
||||
|
||||
function GitHubIssues(uint _uid, string _repository, GitHubOracle _oracle) {
|
||||
uid = _uid;
|
||||
oracle = _oracle;
|
||||
repository = _repository;
|
||||
}
|
||||
|
||||
function setState(uint num, bool open){
|
||||
//issues[num] = open;
|
||||
}
|
||||
|
||||
function placeBounty(uint num){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,25 @@ pragma solidity ^0.4.8;
|
||||
import "lib/ethereans/bank/CollaborationBank.sol";
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
import "./BountyBank.sol";
|
||||
import "./GitRepositoryI.sol";
|
||||
import "./GitRepositoryToken.sol";
|
||||
import "./GitRepositoryStorage.sol";
|
||||
|
||||
|
||||
contract GitRepositoryI {
|
||||
function isClaimed(bytes20 _commitid) constant returns (bool);
|
||||
function claim(bytes20 _commitid, address _user, uint _total);
|
||||
function setStats(uint256 _subscribers, uint256 _watchers);
|
||||
}
|
||||
|
||||
contract GitRepository is GitRepositoryI, Owned {
|
||||
|
||||
//Address of the oracle, used for github login address lookup
|
||||
GitRepositoryStorage public db;
|
||||
GitRepositoryToken public token;
|
||||
CollaborationBank public donationBank;
|
||||
BountyBank public bountyBank;
|
||||
mapping (address=>uint) beers;
|
||||
mapping (address=>uint) donators;
|
||||
|
||||
string public name;
|
||||
uint256 public uid;
|
||||
mapping (bytes20 => bool) public commits;
|
||||
|
||||
uint256 public subscribers;
|
||||
uint256 public watchers;
|
||||
@@ -44,11 +51,12 @@ contract GitRepository is GitRepositoryI, Owned {
|
||||
|
||||
function () payable {
|
||||
donationBank.deposit();
|
||||
beers[msg.sender] = msg.value;
|
||||
donators[msg.sender] += msg.value;
|
||||
}
|
||||
|
||||
function GitRepository(uint256 _uid, string _name) {
|
||||
db = new GitRepositoryStorage(_uid,_name);
|
||||
uid = _uid;
|
||||
name = _name;
|
||||
token = new GitRepositoryToken(_name);
|
||||
donationBank = new CollaborationBank(token);
|
||||
token.linkLocker(donationBank);
|
||||
@@ -59,18 +67,16 @@ contract GitRepository is GitRepositoryI, Owned {
|
||||
function isClaimed(bytes20 _commitid)
|
||||
constant
|
||||
returns (bool) {
|
||||
return db.commits(_commitid) != 0x0;
|
||||
return commits[_commitid];
|
||||
}
|
||||
|
||||
//oracle claim request
|
||||
function claim(bytes20 _commitid, address _user, uint _total)
|
||||
only_owner {
|
||||
if(_total > 0 && !token.lock()){
|
||||
if(_user != 0x0 && db.commits(_commitid) != 0x0){
|
||||
Claim(_commitid);
|
||||
db.setClaimed(_commitid,_user);
|
||||
token.mint(_user, _total);
|
||||
}
|
||||
if(_total > 0 && !token.lock() && _user != 0x0 && !commits[_commitid]){
|
||||
Claim(_commitid);
|
||||
commits[_commitid] = true;
|
||||
token.mint(_user, _total);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +85,23 @@ contract GitRepository is GitRepositoryI, Owned {
|
||||
subscribers = _subscribers;
|
||||
watchers = _watchers;
|
||||
}
|
||||
|
||||
|
||||
function bountyState(uint issue, bool open) only_owner {
|
||||
if (open) bountyBank.open(issue);
|
||||
else bountyBank.close(issue);
|
||||
}
|
||||
|
||||
function bountyState(uint issue, address claimer, uint points) only_owner {
|
||||
bountyBank.setClaimer(issue,claimer,points);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
library GitFactory {
|
||||
|
||||
function newGitRepository(uint256 _uid, string _name) returns (GitRepositoryI){
|
||||
GitRepository repo = new GitRepository(_uid,_name);
|
||||
return repo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
import "../storage/GitHubOracleStorage.sol";
|
||||
|
||||
|
||||
library DBFactory {
|
||||
|
||||
function newStorage() returns (GitHubOracleStorageI){
|
||||
GitHubOracleStorage db = new GitHubOracleStorage();
|
||||
return db;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
import "../git-repository/GitRepository.sol";
|
||||
//import "./GitRepositoryFactoryI.sol";
|
||||
|
||||
library GRFactory {
|
||||
|
||||
function newGitRepository(uint256 _uid, string _name) returns (GitRepositoryI){
|
||||
GitRepository repo = new GitRepository(_uid,_name);
|
||||
return repo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
import "./GitRepositoryI.sol";
|
||||
|
||||
contract GitRepositoryFactoryI {
|
||||
function newGitRepository(uint256 _uid, string _name) external returns (GitRepositoryI);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
contract GitRepositoryI {
|
||||
function isClaimed(bytes20 _commitid) constant returns (bool);
|
||||
function claim(bytes20 _commitid, address _user, uint _total);
|
||||
function setStats(uint256 _subscribers, uint256 _watchers);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* Contract that oracle github API
|
||||
*
|
||||
* GitHubRegistry is a storage contract
|
||||
*
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
|
||||
contract GitRepositoryStorage is Owned {
|
||||
|
||||
string public name;
|
||||
uint256 public uid;
|
||||
|
||||
//storage of sha3(login) of github users
|
||||
mapping (bytes32 => address) users;
|
||||
|
||||
mapping (bytes20 => address) public commits;
|
||||
|
||||
function setClaimed(bytes20 _commitid, address _claimer)
|
||||
only_owner {
|
||||
commits[_commitid] = _claimer;
|
||||
}
|
||||
|
||||
function setUser(bytes32 _user, address _account)
|
||||
only_owner {
|
||||
users[_user] = _account;
|
||||
if(_account == 0x0){
|
||||
delete users[_user];
|
||||
}
|
||||
}
|
||||
|
||||
function GitRepositoryStorage(uint256 _uid, string _name){
|
||||
uid = _uid;
|
||||
name = _name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
/**
|
||||
* Contract that oracle github API
|
||||
*
|
||||
* GitHubRegistry is a storage contract
|
||||
*
|
||||
* By Ricardo Guilherme Schmidt
|
||||
* Released under GPLv3 License
|
||||
*/
|
||||
|
||||
contract GitHubOracleStorageI {
|
||||
|
||||
function addRepository(uint256 _id, uint256 _owner, string _name, string _full_name, address _addr);
|
||||
function addUser(uint256 _id, string _login, uint8 _type, address _addr);
|
||||
function setRepositoryAddress(uint256 _repositoryId, address _repositoryAddress);
|
||||
function setRepositoryName(uint256 _repositoryId, string _full_name, string _name);
|
||||
function setUserAddress(uint userId, address account);
|
||||
function setUserName(uint256 _userId, string _name);
|
||||
function getRepositoryId(string _full_name) constant returns (uint256);
|
||||
function getRepositoryName(uint256 _id) constant returns (string);
|
||||
function getRepositoryAddress(uint256 _id) constant returns(address);
|
||||
function getRepositoryAddress(string _full_name) constant returns(address);
|
||||
function getUserAddress(uint256 _id) constant returns(address);
|
||||
function getUserAddress(string _login) constant returns(address);
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
var assert = require('assert');
|
||||
var helper = require('ethereum-sandbox-helper');
|
||||
var Workbench = require('ethereum-sandbox-workbench');
|
||||
|
||||
var workbench = new Workbench({
|
||||
contractsDirectory: 'contracts',
|
||||
solcVersion: '0.4.2',
|
||||
defaults: {
|
||||
from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'
|
||||
}
|
||||
});
|
||||
|
||||
var contract;
|
||||
|
||||
workbench.startTesting('contract', function(contracts) {
|
||||
it('Deploy Contract', function() {
|
||||
return contracts.Contract.new()
|
||||
.then(function(result) {
|
||||
if (result.address) contract = result;
|
||||
else throw new Error('Contract is not deployed');
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
it('Prints string', function() {
|
||||
var str = "hello, ethereum!";
|
||||
return contract.test(str)
|
||||
.then(function(txHash) {
|
||||
return workbench.waitForReceipt(txHash);
|
||||
})
|
||||
.then(function (receipt) {
|
||||
assert.equal(helper.hexToString(receipt.logs[0].data), str);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"contracts": "contracts",
|
||||
|
||||
"deploy": ["GitHubOracle"],
|
||||
"deploy": ["DGit"],
|
||||
|
||||
"plugins": {
|
||||
"oraclize": {
|
||||
|
||||
@@ -1,29 +1,36 @@
|
||||
#
|
||||
# Scenario1
|
||||
#
|
||||
# Created on: 26/03/2017 03:32:05
|
||||
# Created on: 27/03/2017 03:30:55
|
||||
#
|
||||
|
||||
# Call method addRepository(string)
|
||||
# Call method initialize()
|
||||
- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'
|
||||
to: '0xaefa01276783e1436e5b461c099edccb0448dcf6'
|
||||
value: '0x16345785d8a0000'
|
||||
call: addRepository(string)
|
||||
args:
|
||||
- status-im/github-oracle
|
||||
to: '0x086ca7abad7f9773db72e2efd83dd22f5f408862'
|
||||
value: '0x0'
|
||||
call: initialize()
|
||||
args: []
|
||||
|
||||
# Call method register(string,string)
|
||||
- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'
|
||||
to: '0xaefa01276783e1436e5b461c099edccb0448dcf6'
|
||||
to: '0x086ca7abad7f9773db72e2efd83dd22f5f408862'
|
||||
value: '0x0'
|
||||
call: 'register(string,string)'
|
||||
args:
|
||||
- 3esmit
|
||||
- 31a58f2ddf2258697cce1b969e7c298b
|
||||
|
||||
# Call method addRepository(string)
|
||||
- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'
|
||||
to: '0x086ca7abad7f9773db72e2efd83dd22f5f408862'
|
||||
value: '0x8ac7230489e80000'
|
||||
call: addRepository(string)
|
||||
args:
|
||||
- status-im/github-oracle
|
||||
|
||||
# Call method claimCommit(string,string)
|
||||
- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'
|
||||
to: '0xaefa01276783e1436e5b461c099edccb0448dcf6'
|
||||
to: '0x086ca7abad7f9773db72e2efd83dd22f5f408862'
|
||||
value: '0x0'
|
||||
call: 'claimCommit(string,string)'
|
||||
args:
|
||||
@@ -0,0 +1,101 @@
|
||||
import os, argparse
|
||||
import json, urllib2, datetime
|
||||
from collections import defaultdict
|
||||
start = ''
|
||||
|
||||
script = os.environ['ARG0']
|
||||
args = os.environ['ARG1']
|
||||
auth = os.environ['ARG2']
|
||||
|
||||
|
||||
if(auth):
|
||||
#check if is client secret or token
|
||||
|
||||
|
||||
|
||||
|
||||
repo_link = ""
|
||||
if(args):
|
||||
repo_link = "https://api.github.com/repos/" + args.reponame
|
||||
else:
|
||||
repo_link = "https://api.github.com/repositories/" + args.repoid
|
||||
|
||||
|
||||
|
||||
|
||||
if script == 'issue-status':
|
||||
issueStatus(args.issueid)
|
||||
elif script == 'issue-commits':
|
||||
issueCommits(args.issueid)
|
||||
elif script == 'related-issues':
|
||||
relatedIssues(args.issueid)
|
||||
elif script == 'commit-points':
|
||||
pullCommitPoints(args.pullid)
|
||||
elif script == 'commit-data':
|
||||
commitData(args.commit)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def relatedIssues(issue):
|
||||
link_issue = repo_link + "/issues/" + issue + "/timeline" + auth
|
||||
print link_issue
|
||||
req = urllib2.Request(link_issue)
|
||||
req.add_header("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"):
|
||||
#print elem["source"]["issue"]["number"];
|
||||
pullCommitPoints(json.dumps(elem["source"]["issue"]["number"]))
|
||||
|
||||
|
||||
|
||||
def issueStatus(issue):
|
||||
link_issue = repo_link + "/issues/" + issue + auth
|
||||
issue = json.load(urllib2.urlopen(link_issue))
|
||||
if(issue['state'] == "closed"):
|
||||
print datetime.datetime.strptime( json.dumps(issue['closed_at'])[1:-1], "%Y-%m-%dT%H:%M:%SZ" ).strftime('%s') +","+ json.dumps(issue['closed_by']['login'])
|
||||
else:
|
||||
print "open"
|
||||
|
||||
|
||||
def pullCommitPoints(pr):
|
||||
link_pull = repo_link + "/pulls/" + pr + auth
|
||||
pull = json.load(urllib2.urlopen(link_pull))
|
||||
if(pull['merged_at']):
|
||||
link_pulls_commits = repo_link + "/pulls/" + pr + "/commits" +auth
|
||||
points = defaultdict(int)
|
||||
commits = json.load(urllib2.urlopen(link_pulls_commits))
|
||||
for commit in commits:
|
||||
if(commit['url']):
|
||||
link_commit = json.dumps(commit['url'])[1:-1] +auth
|
||||
_commit = json.load(urllib2.urlopen(link_commit))
|
||||
author = json.dumps(_commit['author']['login'])[1:-1]
|
||||
points[author] += int(json.dumps(_commit['stats']['total']))
|
||||
print points.items()
|
||||
|
||||
|
||||
def issueCommits(args.issueid):
|
||||
link_issue = repo_link + "/issues/" + issue + "/timeline" + auth
|
||||
req = urllib2.Request(link_issue)
|
||||
req.add_header("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"):
|
||||
#print elem["source"]["issue"]["number"];
|
||||
pullCommitPoints(json.dumps(elem["source"]["issue"]["number"]))
|
||||
|
||||
def commitData(commit):
|
||||
link_commit = repo_link +"/commits/"+ commit;
|
||||
req = urllib2.Request(link_commit)
|
||||
req.add_header("Accept", "application/vnd.github.mockingbird-preview")
|
||||
commit = json.load(urllib2.urlopen(req))
|
||||
print json.dumps(commit)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user