From 31a3e6ccea1c0e4c9f3cde9b50e2e74f68a52474 Mon Sep 17 00:00:00 2001 From: zhangxunhui Date: Mon, 30 Jan 2023 20:20:44 +0800 Subject: [PATCH] update push_activity_2_blockchain function --- app/controllers/application_controller.rb | 74 ++++++++++++----------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 096e0b19..0efbd890 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -367,6 +367,7 @@ class ApplicationController < ActionController::Base # RSS key authentication does not start a session User.find_by_rss_key(params[:key]) end + # User.current = User.find(2) # need to remove this statement before running in production end def user_trace_log @@ -963,7 +964,7 @@ class ApplicationController < ActionController::Base # # project_id = model['project_id'] # project = Project.find(project_id) - # if project['use_blockchain'] == 0 + # if project['use_blockchain'] == 0 || project['use_blockchain'] == false # # 无需执行上链操作 # return true # end @@ -1017,7 +1018,7 @@ class ApplicationController < ActionController::Base # project_id = issue['project_id'] # project = Project.find(project_id) # - # if project['use_blockchain'] == 0 + # if project['use_blockchain'] == 0 || project['use_blockchain'] == false # # 无需执行上链操作 # return true # end @@ -1079,7 +1080,7 @@ class ApplicationController < ActionController::Base # # 调用区块链接口 # project_id = model['project_id'] # project = Project.find(project_id) - # if project['use_blockchain'] == 0 + # if project['use_blockchain'] == 0 || project['use_blockchain'] == false # # 无需执行上链操作 # return true # end @@ -1109,7 +1110,7 @@ class ApplicationController < ActionController::Base # updated_at = model['updated_at'] # # # 查询pull request对应的commit信息 - # commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gpid']) + # commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gitea_number']) # commit_shas = [] # commits.each do |c| # commit_shas << c["Sha"] @@ -1141,7 +1142,7 @@ class ApplicationController < ActionController::Base # # 调用区块链接口 # project_id = model['project_id'] # project = Project.find(project_id) - # if project['use_blockchain'] == 0 + # if project['use_blockchain'] == 0 || project['use_blockchain'] == false # # 无需执行上链操作 # return true # end @@ -1155,7 +1156,7 @@ class ApplicationController < ActionController::Base # action = 'merged' # # # 查询pull request对应的commit信息 - # commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gpid']) + # commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gitea_number']) # commit_shas = [] # commits.each do |c| # commit_shas << c["Sha"] @@ -1216,7 +1217,7 @@ class ApplicationController < ActionController::Base # # 调用区块链接口 # project_id = model['project_id'] # project = Project.find(project_id) - # if project['use_blockchain'] == 0 + # if project['use_blockchain'] == 0 || project['use_blockchain'] == false # # 无需执行上链操作 # return true # end @@ -1260,7 +1261,7 @@ class ApplicationController < ActionController::Base project_id = model['project_id'] project = Project.find(project_id) - if project['use_blockchain'] == 0 + if project['use_blockchain'] == 0 || project['use_blockchain'] == false # 无需执行上链操作 return true end @@ -1286,8 +1287,8 @@ class ApplicationController < ActionController::Base # 调用区块链接口 param = { "request-type": "upload issue info", - "issue_id": "trustie-" + id.to_s, - "repo_id": "trustie-" + project_id.to_s, + "issue_id": "gitlink-" + id.to_s, + "repo_id": "gitlink-" + project_id.to_s, "issue_number": 0, # 暂时不需要改字段 "reponame": reponame, "ownername": ownername, @@ -1311,7 +1312,7 @@ class ApplicationController < ActionController::Base project_id = issue['project_id'] project = Project.find(project_id) - if project['use_blockchain'] == 0 + if project['use_blockchain'] == 0 || project['use_blockchain'] == false # 无需执行上链操作 return true end @@ -1333,11 +1334,11 @@ class ApplicationController < ActionController::Base if issue_classify == "issue" param = { "request-type": "upload issue comment info", - "issue_comment_id": "trustie-" + issue_comment_id.to_s, + "issue_comment_id": "gitlink-" + issue_comment_id.to_s, "issue_comment_number": 0, # 暂时不需要 "issue_number": 0, # 暂时不需要 - "issue_id": "trustie-" + issue_id.to_s, - "repo_id": "trustie-" + project.id.to_s, + "issue_id": "gitlink-" + issue_id.to_s, + "repo_id": "gitlink-" + project.id.to_s, "parent_id": parent_id.to_s, "reponame": reponame, "ownername": ownername, @@ -1349,12 +1350,12 @@ class ApplicationController < ActionController::Base elsif issue_classify == "pull_request" param = { "request-type": "upload pull request comment info", - "pull_request_comment_id": "trustie-" + issue_comment_id.to_s, + "pull_request_comment_id": "gitlink-" + issue_comment_id.to_s, "pull_request_comment_number": 0, # 不考虑该字段 "pull_request_number": 0, # 不考虑该字段 - "pull_request_id": "trustie-" + issue_id.to_s, + "pull_request_id": "gitlink-" + issue_id.to_s, "parent_id": parent_id.to_s, - "repo_id": "trustie-" + project.id.to_s, + "repo_id": "gitlink-" + project.id.to_s, "reponame": reponame, "ownername": ownername, "username": username, @@ -1371,7 +1372,7 @@ class ApplicationController < ActionController::Base # 调用区块链接口 project_id = model['project_id'] project = Project.find(project_id) - if project['use_blockchain'] == 0 + if project['use_blockchain'] == 0 || project['use_blockchain'] == false # 无需执行上链操作 return true end @@ -1401,16 +1402,16 @@ class ApplicationController < ActionController::Base updated_at = model['updated_at'] # 查询pull request对应的commit信息 - commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gpid']) + commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gitea_number']) commit_shas = [] commits.each do |c| commit_shas << c["Sha"] end param = { "request-type": "upload pull request info", - "pull_request_id": "trustie-" + pull_request_id.to_s, + "pull_request_id": "gitlink-" + pull_request_id.to_s, "pull_request_number": 0, # trustie没有该字段 - "repo_id": "trustie-" + project_id.to_s, + "repo_id": "gitlink-" + project_id.to_s, "ownername": ownername, "reponame": reponame, "username": username, @@ -1432,7 +1433,7 @@ class ApplicationController < ActionController::Base # 调用区块链接口 project_id = model['project_id'] project = Project.find(project_id) - if project['use_blockchain'] == 0 + if project['use_blockchain'] == 0 || project['use_blockchain'] == false # 无需执行上链操作 return true end @@ -1445,8 +1446,11 @@ class ApplicationController < ActionController::Base action = 'merged' + created_at = model['created_at'] + updated_at = model['updated_at'] + # 查询pull request对应的commit信息 - commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gpid']) + commits = Gitea::PullRequest::CommitsService.call(ownername, reponame, model['gitea_number']) commit_shas = [] commits.each do |c| commit_shas << c["Sha"] @@ -1455,9 +1459,9 @@ class ApplicationController < ActionController::Base # 将pull request相关信息写入链上 param = { "request-type": "upload pull request info", - "pull_request_id": "trustie-" + pull_request_id.to_s, + "pull_request_id": "gitlink-" + pull_request_id.to_s, "pull_request_number": 0, # trustie没有该字段 - "repo_id": "trustie-" + project_id.to_s, + "repo_id": "gitlink-" + project_id.to_s, "ownername": ownername, "reponame": reponame, "username": username, @@ -1477,16 +1481,16 @@ class ApplicationController < ActionController::Base # 将commit相关信息写入链上 commit_shas.each do |commit_sha| - commit_diff = Gitea::Commit::DiffService.call(ownername, reponame, commit_sha) - commit = Gitea::Commit::InfoService.call(ownername, reponame, commit_sha) + commit_diff = Gitea::Commit::DiffService.call(ownername, reponame, commit_sha, owner['gitea_token']) + commit = Gitea::Commit::InfoService.call(ownername, reponame, commit_sha, owner['gitea_token']) param = { "request-type": "upload commit info", "commit_hash": commit_sha, - "repo_id": "trustie-" + project_id.to_s, - "author": commit['author']['login'], - "author_email": commit['author']['email'], - "committer": commit['committer']['login'], - "committer_email": commit['committer']['email'], + "repo_id": "gitlink-" + project_id.to_s, + "author": commit['commit']['author']['name'], + "author_email": commit['commit']['author']['email'], + "committer": commit['commit']['committer']['name'], + "committer_email": commit['commit']['committer']['email'], "author_time": commit['commit']['author']['date'], "committer_time": commit['commit']['committer']['date'], "content": commit['commit']['message'], @@ -1502,7 +1506,7 @@ class ApplicationController < ActionController::Base # 调用区块链接口 project_id = model['project_id'] project = Project.find(project_id) - if project['use_blockchain'] == 0 + if project['use_blockchain'] == 0 || project['use_blockchain'] == false # 无需执行上链操作 return true end @@ -1518,9 +1522,9 @@ class ApplicationController < ActionController::Base # 将pull request相关信息写入链上 param = { "request-type": "upload pull request info", - "pull_request_id": "trustie-" + pull_request_id.to_s, + "pull_request_id": "gitlink-" + pull_request_id.to_s, "pull_request_number": 0, # trustie没有该字段 - "repo_id": "trustie-" + project_id.to_s, + "repo_id": "gitlink-" + project_id.to_s, "ownername": ownername, "reponame": reponame, "username": username,