1. add upload issue info function
2. add query issue latest info function 3. add query issue all info function
This commit is contained in:
parent
e4250e7578
commit
208dbbeb13
|
|
@ -8,5 +8,5 @@ var (
|
|||
RepoCurBalanceDownOverFlow int64 = -1005 // 当前项目总 Token 数低于0
|
||||
UserBblanceNotEnough int64 = -1006 // 用户余额不足
|
||||
|
||||
ContractAddress string = "0xE46EE87f19049d5705989f49305b136d0732a0Cf"
|
||||
ContractAddress string = "0x5Bf5c94F6841581047A93477526D9A84c8bfedb6"
|
||||
)
|
||||
|
|
|
|||
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
|
|
@ -11,6 +11,8 @@ contract OpenSource {
|
|||
string constant PUSH_TABLE = "push";
|
||||
string constant PULL_REQUEST_TABLE = "pull_request";
|
||||
string constant PULL_REQUEST_COMMENT_TABLE = "pull_request_comment";
|
||||
string constant ISSUE_TABLE = "issue";
|
||||
string constant ISSUE_COMMENT_TABLE = "issue_comment";
|
||||
|
||||
constructor() public {
|
||||
tableFactory = TableFactory(0x1001); //The fixed address is 0x1001 for TableFactory
|
||||
|
|
@ -21,6 +23,8 @@ contract OpenSource {
|
|||
tableFactory.createTable(PUSH_TABLE, "push_id", "push_number,repo_id,reponame,ownername,username,branch,commit_shas,time");
|
||||
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");
|
||||
tableFactory.createTable(ISSUE_COMMENT_TABLE, "issue_comment_id", "content");
|
||||
}
|
||||
|
||||
// create repo
|
||||
|
|
@ -513,12 +517,114 @@ contract OpenSource {
|
|||
for (int256 i = 0; i < entries.size(); ++i) {
|
||||
Entry entry = entries.get(i);
|
||||
|
||||
pull_request_id_comment_list[uint256(i)] = entry.getString("pull_request_id_comment");
|
||||
pull_request_id_comment_list[uint256(i)] = entry.getString("pull_request_comment_id");
|
||||
content_list[uint256(i)] = entry.getString("content");
|
||||
}
|
||||
|
||||
return (pull_request_id_comment_list, content_list);
|
||||
}
|
||||
|
||||
// add issue info
|
||||
function addIssueData(string memory issue_id, string memory content)
|
||||
public
|
||||
returns (int256)
|
||||
{
|
||||
Table issue_table = tableFactory.openTable(ISSUE_TABLE);
|
||||
Entry issue_entry = issue_table.newEntry();
|
||||
issue_entry.set("issue_id", issue_id);
|
||||
issue_entry.set("content", content);
|
||||
|
||||
int256 count = issue_table.insert(issue_id, issue_entry);
|
||||
return count;
|
||||
}
|
||||
|
||||
// select issue latest info
|
||||
function selectIssueInfo(string memory issue_id)
|
||||
public
|
||||
view
|
||||
returns (string memory, string memory)
|
||||
{
|
||||
Table issue_table = tableFactory.openTable(ISSUE_TABLE);
|
||||
Condition condition = issue_table.newCondition();
|
||||
Entries entries = issue_table.select(issue_id, condition);
|
||||
if (entries.size() == 0) {
|
||||
return ("", "");
|
||||
}
|
||||
Entry entry = entries.get(entries.size()-1);
|
||||
return (entry.getString("issue_id"), entry.getString("content"));
|
||||
}
|
||||
|
||||
// select issue all info
|
||||
function selectIssueAllInfo(string memory issue_id)
|
||||
public
|
||||
view
|
||||
returns (string[] memory, string[] memory)
|
||||
{
|
||||
Table issue_table = tableFactory.openTable(ISSUE_TABLE);
|
||||
Condition condition = issue_table.newCondition();
|
||||
Entries entries = issue_table.select(issue_id, condition);
|
||||
string[] memory issue_list = new string[](uint256(entries.size()));
|
||||
string[] memory content_list = new string[](uint256(entries.size()));
|
||||
|
||||
for (int256 i = 0; i < entries.size(); ++i) {
|
||||
Entry entry = entries.get(i);
|
||||
|
||||
issue_list[uint256(i)] = entry.getString("issue_id");
|
||||
content_list[uint256(i)] = entry.getString("content");
|
||||
}
|
||||
|
||||
return (issue_list, content_list);
|
||||
}
|
||||
|
||||
// add issue comment info
|
||||
function addIssueCommentData(string memory issue_comment_id, string memory content)
|
||||
public
|
||||
returns (int256)
|
||||
{
|
||||
Table issue_comment_table = tableFactory.openTable(ISSUE_COMMENT_TABLE);
|
||||
Entry issue_comment_entry = issue_comment_table.newEntry();
|
||||
issue_comment_entry.set("issue_comment_id", issue_comment_id);
|
||||
issue_comment_entry.set("content", content);
|
||||
|
||||
int256 count = issue_comment_table.insert(issue_comment_id, issue_comment_entry);
|
||||
return count;
|
||||
}
|
||||
|
||||
// select issue comment latest info
|
||||
function selectIssueInfo(string memory issue_comment_id)
|
||||
public
|
||||
view
|
||||
returns (string memory, string memory)
|
||||
{
|
||||
Table issue_comment_table = tableFactory.openTable(ISSUE_COMMENT_TABLE);
|
||||
Condition condition = issue_comment_table.newCondition();
|
||||
Entries entries = issue_comment_table.select(issue_comment_id, condition);
|
||||
if (entries.size() == 0) {
|
||||
return ("", "");
|
||||
}
|
||||
Entry entry = entries.get(entries.size()-1);
|
||||
return (entry.getString("issue_comment_id"), entry.getString("content"));
|
||||
}
|
||||
|
||||
// select issue comment all info
|
||||
function selectIssueAllInfo(string memory issue_comment_id)
|
||||
public
|
||||
view
|
||||
returns (string[] memory, string[] memory)
|
||||
{
|
||||
Table issue_comment_table = tableFactory.openTable(ISSUE_COMMENT_TABLE);
|
||||
Condition condition = issue_comment_table.newCondition();
|
||||
Entries entries = issue_comment_table.select(issue_comment_id, condition);
|
||||
string[] memory issue_comment_list = new string[](uint256(entries.size()));
|
||||
string[] memory content_list = new string[](uint256(entries.size()));
|
||||
|
||||
for (int256 i = 0; i < entries.size(); ++i) {
|
||||
Entry entry = entries.get(i);
|
||||
|
||||
issue_comment_list[uint256(i)] = entry.getString("issue_comment_id");
|
||||
content_list[uint256(i)] = entry.getString("content");
|
||||
}
|
||||
|
||||
return (issue_comment_list, content_list);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,6 +48,11 @@ type FiscoBcos struct {
|
|||
ParentID string `json:"parent_id"`
|
||||
// pull_request_number, repo_id, reponame, ownername, username, action, content, created_at, updated_at
|
||||
|
||||
// repo issue 相关
|
||||
IssueID string `json:"issue_id"`
|
||||
IssueNumber uint64 `json:"issue_number"`
|
||||
// repo_id, reponame, ownername, action, title, content, created_at, updated_at
|
||||
|
||||
// user 相关
|
||||
Username string `json:"username"` // 用户名
|
||||
Amount uint64 `json:"amount"` // 转账金额
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package structs
|
||||
|
||||
type UploadIssueOption struct {
|
||||
IssueID string `json:"issue_id"`
|
||||
IssueNumber uint64 `json:"issue_number"`
|
||||
RepoID string `json:"repo_id"`
|
||||
Reponame string `json:"reponame"`
|
||||
Ownername string `json:"ownername"`
|
||||
Username string `json:"username"`
|
||||
Action string `json:"action"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ResponseIssue struct {
|
||||
UploadIssueOption
|
||||
Response
|
||||
}
|
||||
|
||||
type ResponseIssueArr struct {
|
||||
UploadIssueOptionArr
|
||||
Response
|
||||
}
|
||||
|
||||
type UploadIssueOptionArr []UploadIssueOption
|
||||
|
|
@ -24,6 +24,8 @@ var (
|
|||
ResPullRequestUploadUnsucc = &Response{Status: 9, Message: "pull request upload unsuccessfully!"}
|
||||
ResPullRequestCommentUploadSucc = &Response{Status: 0, Message: "pull request comment upload successfully!"}
|
||||
ResPullRequestCommentUploadUnsucc = &Response{Status: 10, Message: "pull request comment upload unsuccessfully!"}
|
||||
ResIssueUploadSucc = &Response{Status: 0, Message: "issue upload successfully!"}
|
||||
ResIssueUploadUnsucc = &Response{Status: 10, Message: "issue upload unsuccessfully!"}
|
||||
|
||||
ResUserNotExisted = &Response{Status: 100, Message: "user not exist!"}
|
||||
ResUserAddAmountSucc = &Response{Status: 0, Message: "user adds amount successfully!"}
|
||||
|
|
|
|||
|
|
@ -103,6 +103,26 @@ func HandleAllRoutes(ctx *macaron.Context, opt api.FiscoBcos, logger *log.Logger
|
|||
repo.SelectPullRequestCommentLatestInfo(ctx, opt.PullRequestCommentID, logger)
|
||||
case "query pull request comment all info":
|
||||
repo.SelectPullRequestCommentAllInfo(ctx, opt.PullRequestCommentID, logger)
|
||||
case "upload issue info":
|
||||
repo.UploadIssueInfo(ctx,
|
||||
api.UploadIssueOption{
|
||||
IssueID: opt.IssueID,
|
||||
IssueNumber: opt.IssueNumber,
|
||||
RepoID: opt.RepoID,
|
||||
Reponame: opt.Reponame,
|
||||
Ownername: opt.Ownername,
|
||||
Username: opt.Username,
|
||||
Action: opt.Action,
|
||||
Title: opt.Title,
|
||||
CreatedAt: opt.CreatedAt,
|
||||
UpdatedAt: opt.UpdatedAt,
|
||||
Content: opt.Content,
|
||||
},
|
||||
logger)
|
||||
case "query issue latest info":
|
||||
repo.SelectIssueLatestInfo(ctx, opt.IssueID, logger)
|
||||
case "query issue all info":
|
||||
repo.SelectIssueAllInfo(ctx, opt.IssueID, logger)
|
||||
case "query user balance of single repo":
|
||||
user.SelectUserBalance(ctx, opt.Username, opt.TokenName, logger)
|
||||
case "query user balance of all repos":
|
||||
|
|
|
|||
|
|
@ -354,3 +354,114 @@ func SelectPullRequestCommentAllInfo(ctx *macaron.Context, pullRequestCommentID
|
|||
UploadPullReuqestCommentOptionArr: uploadPullReuqestCommentOptionArr,
|
||||
})
|
||||
}
|
||||
|
||||
// 查询 issue 最新数据
|
||||
func SelectIssueLatestInfo(ctx *macaron.Context, issueID string, logger *log.Logger) {
|
||||
if issueID == "" {
|
||||
ctx.JSON(http.StatusOK, api.StringEmpty)
|
||||
return
|
||||
}
|
||||
|
||||
configs, err := conf.ParseConfigFile("config.toml")
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
config := &configs[0]
|
||||
|
||||
client, err := client.Dial(config)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
// load the contract
|
||||
contractAddress := common.HexToAddress(contract.ContractAddress)
|
||||
instance, err := opensource.NewOpenSource(contractAddress, client)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
|
||||
|
||||
_, strJSON, err := openSourceSession.SelectIssueInfo(issueID) // call Insert API
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("issueID: %v \n", strJSON)
|
||||
|
||||
var uploadIssueOption api.UploadIssueOption
|
||||
err = json.Unmarshal([]byte(strJSON), &uploadIssueOption)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, &structs.ResponseIssue{
|
||||
Response: structs.Response{
|
||||
Status: 0,
|
||||
Message: "query success!",
|
||||
},
|
||||
UploadIssueOption: uploadIssueOption,
|
||||
})
|
||||
}
|
||||
|
||||
// 查询 issue 所有数据
|
||||
func SelectIssueAllInfo(ctx *macaron.Context, issueID string, logger *log.Logger) {
|
||||
if issueID == "" {
|
||||
ctx.JSON(http.StatusOK, api.StringEmpty)
|
||||
return
|
||||
}
|
||||
|
||||
configs, err := conf.ParseConfigFile("config.toml")
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
config := &configs[0]
|
||||
|
||||
client, err := client.Dial(config)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
// load the contract
|
||||
contractAddress := common.HexToAddress(contract.ContractAddress)
|
||||
instance, err := opensource.NewOpenSource(contractAddress, client)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
|
||||
|
||||
_, strJSONArr, err := openSourceSession.SelectIssueAllInfo(issueID) // call Insert API
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("pullRequestID: %v \n", strJSONArr)
|
||||
|
||||
var uploadIssueOption api.UploadIssueOption
|
||||
var uploadIssueOptionArr api.UploadIssueOptionArr
|
||||
for i := 0; i < len(strJSONArr); i++ {
|
||||
err = json.Unmarshal([]byte(strJSONArr[i]), &uploadIssueOption)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
uploadIssueOptionArr = append(uploadIssueOptionArr, uploadIssueOption)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &structs.ResponseIssueArr{
|
||||
Response: structs.Response{
|
||||
Status: 0,
|
||||
Message: "query success!",
|
||||
},
|
||||
UploadIssueOptionArr: uploadIssueOptionArr,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,3 +227,54 @@ func UploadPullRequestCommentInfo(ctx *macaron.Context, opt api.UploadPullReuqes
|
|||
}
|
||||
ctx.JSON(http.StatusOK, structs.ResPullRequestCommentUploadUnsucc)
|
||||
}
|
||||
|
||||
// 上传 issue数据
|
||||
func UploadIssueInfo(ctx *macaron.Context, opt api.UploadIssueOption, logger *log.Logger) {
|
||||
issueID := opt.IssueID
|
||||
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 {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
config := &configs[0]
|
||||
|
||||
client, err := client.Dial(config)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
// load the contract
|
||||
contractAddress := common.HexToAddress(contract.ContractAddress)
|
||||
instance, err := opensource.NewOpenSource(contractAddress, client)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
openSourceSession := &opensource.OpenSourceSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
|
||||
|
||||
tx, receipt, err := openSourceSession.AddIssueData(issueID, string(bytesJson)) // call Insert API
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, api.UnknownErr(err))
|
||||
return
|
||||
}
|
||||
logger.Printf("tx sent: %s\n", tx.Hash().Hex())
|
||||
// insertedLines, err := strconv.Atoi(receipt.Output[2:])
|
||||
code, err := parseOutput(opensource.OpenSourceABI, "addIssueData", receipt)
|
||||
if err != nil {
|
||||
logger.Panic("error when transfer string to int: ", err)
|
||||
}
|
||||
if code.Int64() > 0 {
|
||||
logger.Printf("inserted lines: %v\n", code)
|
||||
ctx.JSON(http.StatusOK, structs.ResIssueUploadSucc)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, structs.ResIssueUploadUnsucc)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue