1. update commit interface

2. update push interface
This commit is contained in:
sulenn 2021-05-12 23:00:30 +08:00
parent b2fb44c544
commit c17bf815ce
14 changed files with 133 additions and 182 deletions

16
ca.crt
View File

@ -1,12 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIBvTCCAWSgAwIBAgIUeIXPs/XIBoUJyZf6wvVh9AQCICEwCgYIKoZIzj0EAwIw
MIIBvjCCAWSgAwIBAgIUb3qQVNwwO9ACvI5KYQtOInJccMUwCgYIKoZIzj0EAwIw
NTEOMAwGA1UEAwwFY2hhaW4xEzARBgNVBAoMCmZpc2NvLWJjb3MxDjAMBgNVBAsM
BWNoYWluMCAXDTIxMDUxMjA3NDc1N1oYDzIxMjEwNDE4MDc0NzU3WjA1MQ4wDAYD
BWNoYWluMCAXDTIxMDUxMjE0NDMzOFoYDzIxMjEwNDE4MTQ0MzM4WjA1MQ4wDAYD
VQQDDAVjaGFpbjETMBEGA1UECgwKZmlzY28tYmNvczEOMAwGA1UECwwFY2hhaW4w
VjAQBgcqhkjOPQIBBgUrgQQACgNCAAQdE5CUxQQcoEdarzOv6UkgnbeYX/5TBLNA
NximBnjxKiuR0UzsAgtzJpY9AeRZ+kWS1qRGr8YGMJKBlQcqWl6qo1MwUTAdBgNV
HQ4EFgQUpJFYS0UVs1CfI/7LjqWgWhevTlAwHwYDVR0jBBgwFoAUpJFYS0UVs1Cf
I/7LjqWgWhevTlAwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNHADBEAiAs
13YUosDe5uKbFQG2JiOp5M9qihcx0pfpYyP6lhgQOQIgE48GxZGKD0pnu70JcbQt
aDJAMqOETMMq6583hqxeULo=
VjAQBgcqhkjOPQIBBgUrgQQACgNCAATTFARicYMzAhCgtLlZuPqjUBQw+Q/lZTez
++QCBIKxEjGSbnTxvsn8SE3rMbxI8CAPnZyoh0EqZtczJol6KRILo1MwUTAdBgNV
HQ4EFgQUSsuLmNcqa5pN7izdi36C+gfOJaYwHwYDVR0jBBgwFoAUSsuLmNcqa5pN
7izdi36C+gfOJaYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAgNIADBFAiBa
JE5AMPb+6iZzpcyK459e+902Hc7Q/gd6xklQLU8U6AIhAMRhP6UQ/jfQ0InfJk8Z
nrxv/WfiIZrgZv2Sf9z4r+hT
-----END CERTIFICATE-----

View File

@ -8,5 +8,5 @@ var (
RepoCurBalanceDownOverFlow int64 = -1005 // 当前项目总 Token 数低于0
UserBblanceNotEnough int64 = -1006 // 用户余额不足
ContractAddress string = "0x481D3A1dcD72cD618Ea768b3FbF69D78B46995b0"
ContractAddress string = "0x0a68F060B46e0d8f969383D260c34105EA13a9dd"
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@ contract OpenSource {
tableFactory.createTable(REPO_TABLE, "token_name", "owner,total_supply,cur_supply");
tableFactory.createTable(USER_TABLE, "user", "token_name,balance");
tableFactory.createTable(COMMIT_TABLE, "commit_hash", "content");
tableFactory.createTable(PUSH_TABLE, "push_id", "push_number,repo_id,reponame,ownername,username,branch,commit_shas,time");
tableFactory.createTable(PUSH_TABLE, "push_id", "content");
tableFactory.createTable(PULL_REQUEST_TABLE, "pull_request_id", "content");
tableFactory.createTable(PULL_REQUEST_COMMENT_TABLE, "pull_request_comment_id", "content");
tableFactory.createTable(ISSUE_TABLE, "issue_id", "content");
@ -345,20 +345,14 @@ contract OpenSource {
}
// add commit info
function addCommitData(string memory commit_hash, string memory repo_id, string memory author, string memory email,
string memory time, string memory content, string memory commit_diff)
function addCommitData(string memory commit_hash, string memory content)
public
returns (int256)
{
Table commit_table = tableFactory.openTable(COMMIT_TABLE);
Entry commit_entry = commit_table.newEntry();
commit_entry.set("commit_hash", commit_hash);
commit_entry.set("repo_id", repo_id);
commit_entry.set("author", author);
commit_entry.set("email", email);
commit_entry.set("time", time);
commit_entry.set("content", content);
commit_entry.set("commit_diff", commit_diff);
int256 count = commit_table.insert(commit_hash, commit_entry);
return count;
@ -368,36 +362,27 @@ contract OpenSource {
function selectCommitInfo(string memory commit_hash)
public
view
returns (string memory, string memory, string memory, string memory, string memory, string memory, string memory)
returns (string memory, string memory)
{
Table commit_table = tableFactory.openTable(COMMIT_TABLE);
Condition condition = commit_table.newCondition();
Entries entries = commit_table.select(commit_hash, condition);
if (entries.size() == 0) {
return ("", "", "", "","","","");
return ("", "");
}
Entry entry = entries.get(entries.size()-1);
return (entry.getString("commit_hash"), entry.getString("repo_id"), entry.getString("author"), entry.getString("email"),
entry.getString("time"), entry.getString("content"), entry.getString("commit_diff"));
return (entry.getString("commit_hash"), entry.getString("content"));
}
// add push info
function addPushData(string memory push_id, uint256 push_number, string memory repo_id, string memory reponame,
string memory ownername, string memory username, string memory branch, string memory commit_shas, string memory time)
function addPushData(string memory push_id, string memory content)
public
returns (int256)
{
Table push_table = tableFactory.openTable(PUSH_TABLE);
Entry push_entry = push_table.newEntry();
push_entry.set("push_id", push_id);
push_entry.set("push_number", push_number);
push_entry.set("repo_id", repo_id);
push_entry.set("reponame", reponame);
push_entry.set("ownername", ownername);
push_entry.set("username", username);
push_entry.set("branch", branch);
push_entry.set("commit_shas", commit_shas);
push_entry.set("time", time);
push_entry.set("content", content);
int256 count = push_table.insert(push_id, push_entry);
return count;
@ -407,17 +392,16 @@ contract OpenSource {
function selectPushInfo(string memory push_id)
public
view
returns (string memory, uint256, string memory, string memory, string memory, string memory, string memory, string memory , string memory)
returns (string memory, string memory)
{
Table push_table = tableFactory.openTable(PUSH_TABLE);
Condition condition = push_table.newCondition();
Entries entries = push_table.select(push_id, condition);
if (entries.size() == 0) {
return ("", 0, "", "", "","","","","");
return ("","");
}
Entry entry = entries.get(entries.size()-1);
return (entry.getString("push_id"), entry.getUInt("push_number"), entry.getString("repo_id"), entry.getString("reponame"), entry.getString("ownername"),
entry.getString("username"), entry.getString("branch"), entry.getString("commit_shas"), entry.getString("time"));
return (entry.getString("push_id"), entry.getString("content"));
}
// add pull request info

View File

@ -25,6 +25,7 @@ type FiscoBcos struct {
Reponame string `json:"reponame"`
Ownername string `json:"ownername"`
Branch string `json:"branch"`
Size uint64 `json:"size"`
CommitShas []string `json:"commit_shas"`
// repo_id, username, time

View File

@ -9,6 +9,7 @@ type UploadPushOption struct {
CommitShas []string `json:"commit_shas"`
RepoID string `json:"repo_id"`
Username string `json:"username"` // 用户名
Size uint64 `json:"size"`
Time string `json:"time"`
}

View File

@ -50,6 +50,7 @@ func HandleAllRoutes(ctx *macaron.Context, opt api.FiscoBcos, logger *log.Logger
Ownername: opt.Ownername,
Username: opt.Username,
Branch: opt.Branch,
Size: opt.Size,
CommitShas: opt.CommitShas,
Time: opt.Time,
},

View File

@ -5,7 +5,6 @@ import (
"fmt"
"log"
"net/http"
"strings"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
@ -50,28 +49,27 @@ func SelectCommitInfo(ctx *macaron.Context, commitHash string, logger *log.Logge
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
_, repoID, author, email, time, message, commitDiff, err := openSourceSession.SelectCommitInfo(commitHash) // call Insert API
_, strJSON, err := openSourceSession.SelectCommitInfo(commitHash) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
fmt.Printf("commitHash: %v, repoID: %v, author: %v, email: %v, curStimeupply: %v, message: %v, commitDiff: %v \n", commitHash, repoID, author, email, time, message, commitDiff)
fmt.Printf("commitHash: %v \n", strJSON)
var uploadCommitOption api.UploadCommitOption
err = json.Unmarshal([]byte(strJSON), &uploadCommitOption)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
ctx.JSON(http.StatusOK, &structs.ResponseCommit{
Response: structs.Response{
Status: 0,
Message: "query success!",
},
UploadCommitOption: structs.UploadCommitOption{
CommitHash: commitHash,
RepoID: repoID,
Author: author,
Email: email,
Time: time,
Content: message,
CommitDiff: commitDiff,
},
UploadCommitOption: uploadCommitOption,
})
}
@ -105,31 +103,27 @@ func SelectPushInfo(ctx *macaron.Context, pushID string, logger *log.Logger) {
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
_, pushNumber, repoID, reponame, ownername, username, branch, commitShas, time, err := openSourceSession.SelectPushInfo(pushID) // call Insert API
_, strJSON, err := openSourceSession.SelectPushInfo(pushID) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
fmt.Printf("pushID: %v, pushNumber: %v, repoID: %v, reponame: %v, ownername: %v, username: %v, branch: %v, commitShas: %v, commitShas: %v \n",
pushID, pushNumber, repoID, reponame, ownername, username, branch, commitShas, time)
fmt.Printf("pushID: %v \n", strJSON)
var uploadPushOption api.UploadPushOption
err = json.Unmarshal([]byte(strJSON), &uploadPushOption)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
ctx.JSON(http.StatusOK, &structs.ResponsePush{
Response: structs.Response{
Status: 0,
Message: "query success!",
},
UploadPushOption: structs.UploadPushOption{
PushID: pushID,
PushNumber: pushNumber.Uint64(),
RepoID: repoID,
Reponame: reponame,
Ownername: ownername,
Username: username,
Branch: branch,
CommitShas: strings.Split(commitShas, "-"),
Time: time,
},
UploadPushOption: uploadPushOption,
})
}

View File

@ -3,9 +3,7 @@ package repo
import (
"encoding/json"
"log"
"math/big"
"net/http"
"strings"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
@ -23,12 +21,11 @@ var ()
// 上传 commit 数据
func UploadCommitInfo(ctx *macaron.Context, opt api.UploadCommitOption, logger *log.Logger) {
commitHash := opt.CommitHash
repoID := opt.RepoID
author := opt.Author
email := opt.Email
time := opt.Time
content := opt.Content
commitDiff := opt.CommitDiff
bytesJson, err := json.Marshal(opt)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
@ -53,7 +50,7 @@ func UploadCommitInfo(ctx *macaron.Context, opt api.UploadCommitOption, logger *
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
tx, receipt, err := openSourceSession.AddCommitData(commitHash, repoID, author, email, time, content, commitDiff) // call Insert API
tx, receipt, err := openSourceSession.AddCommitData(commitHash, string(bytesJson)) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
@ -75,14 +72,11 @@ func UploadCommitInfo(ctx *macaron.Context, opt api.UploadCommitOption, logger *
// 上传 push 数据
func UploadPushInfo(ctx *macaron.Context, opt api.UploadPushOption, logger *log.Logger) {
pushID := opt.PushID
pushNumber := opt.PushNumber
repoID := opt.RepoID
reponame := opt.Reponame
ownername := opt.Ownername
username := opt.Username
branch := opt.Branch
commitShas := strings.Join(opt.CommitShas, "-") // 拼接字符串
time := opt.Time
bytesJson, err := json.Marshal(opt)
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return
}
configs, err := conf.ParseConfigFile("config.toml")
if err != nil {
@ -107,7 +101,7 @@ func UploadPushInfo(ctx *macaron.Context, opt api.UploadPushOption, logger *log.
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
tx, receipt, err := openSourceSession.AddPushData(pushID, big.NewInt(int64(pushNumber)), repoID, reponame, ownername, username, branch, commitShas, time) // call Insert API
tx, receipt, err := openSourceSession.AddPushData(pushID, string(bytesJson)) // call Insert API
if err != nil {
ctx.JSON(http.StatusOK, api.UnknownErr(err))
return

42
sdk.crt
View File

@ -1,33 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIBgjCCASmgAwIBAgIUZWL3lqfSuG4zMEFMujaXB/tF5VcwCgYIKoZIzj0EAwIw
MIIBgjCCASmgAwIBAgIUItID+RCUjGCXxfvSTdk5/tQwVY0wCg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