From b570c2b4cd4d13b38f1a136678ff29e02bd7ae11 Mon Sep 17 00:00:00 2001 From: EdmondFrank Date: Thu, 1 Jun 2023 15:38:29 +0800 Subject: [PATCH] Feat bot account commit supports DCO signing Signed-off-by: EdmondFrank --- .env.example | 5 +++++ app/controllers/concerns/common.rb | 2 ++ app/controllers/concerns/gitee_application.rb | 3 ++- app/controllers/concerns/github_application.rb | 3 ++- app/services/export_server.rb | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 2486632c..98dcd300 100644 --- a/.env.example +++ b/.env.example @@ -112,3 +112,8 @@ export NOTIFICATION_EXPLORE_URL=/explore export NOTIFICATION_WECHAT_ACCOUNT_BIND_TEMPLATE_ID=OPENTM415757701 export NOTIFICATION_WECHAT_REPORT_GENERATE_TEMPLATE_ID=OPENTM407521893 export NOTIFICATION_WECHAT_REPORT_SUBSCRIPTION_UPDATE_TEMPLATE_ID=OPENTM412612104 + +# CI Bots +export BOT_NAME=compass-bot +export BOT_EMAIL=compass-bot@gitee.com + diff --git a/app/controllers/concerns/common.rb b/app/controllers/concerns/common.rb index f282d19e..f108c43c 100644 --- a/app/controllers/concerns/common.rb +++ b/app/controllers/concerns/common.rb @@ -9,6 +9,8 @@ module Common CELERY_SERVER = ENV.fetch('CELERY_SERVER') { 'http://localhost:8000' } SUPPORT_DOMAINS = ['gitee.com', 'github.com', 'raw.githubusercontent.com'] SUPPORT_DOMAIN_NAMES = ['gitee', 'github'] + BOT_NAME = ENV.fetch('BOT_NAME') { 'compass-bot' } + BOT_EMAIL = ENV.fetch('BOT_EMAIL') { 'compass-bot@gitee.com' } GITEE_REPO = ENV.fetch('GITEE_WORKFLOW_REPO') GITHUB_REPO = ENV.fetch('GITHUB_WORKFLOW_REPO') META_REPO = ENV.fetch('WORKFLOW_REPO_NAME') { 'compass-projects-information' } diff --git a/app/controllers/concerns/gitee_application.rb b/app/controllers/concerns/gitee_application.rb index 43f17180..2143d365 100644 --- a/app/controllers/concerns/gitee_application.rb +++ b/app/controllers/concerns/gitee_application.rb @@ -59,10 +59,11 @@ def gitee_create_branch(branch_name, refs: 'main') end def gitee_post_file(path, message, content_base64, branch_name) + signed_off_message = message + "\n\nSigned-off-by: #{BOT_NAME} <#{BOT_EMAIL}>" resp = Faraday.post( "#{GITEE_API_ENDPOINT}/repos/#{gitee_owner}/#{gitee_repo}/contents/#{path}", - { message: message, content: content_base64, branch: branch_name, access_token: GITEE_TOKEN }.to_json, + { message: signed_off_message, content: content_base64, branch: branch_name, access_token: GITEE_TOKEN }.to_json, { 'Content-Type' => 'application/json'} ) case JSON.parse(resp.body).symbolize_keys diff --git a/app/controllers/concerns/github_application.rb b/app/controllers/concerns/github_application.rb index affb4b46..2bb0d915 100644 --- a/app/controllers/concerns/github_application.rb +++ b/app/controllers/concerns/github_application.rb @@ -83,11 +83,12 @@ def github_create_ref(branch_name, sha) end def github_put_file(path, message, content_base64, branch_name) + signed_off_message = message + "\n\nSigned-off-by: #{BOT_NAME} <#{BOT_EMAIL}>" resp = RestClient::Request.new( method: :put, url: "#{GITHUB_API_ENDPOINT}/repos/#{github_owner}/#{github_repo}/contents/#{path}", - payload: { message: message, content: content_base64, branch: branch_name }.to_json, + payload: { message: signed_off_message, content: content_base64, branch: branch_name }.to_json, headers: { 'Content-Type' => 'application/json' , 'Authorization' => "Bearer #{GITHUB_TOKEN}" }, proxy: PROXY ).execute diff --git a/app/services/export_server.rb b/app/services/export_server.rb index 90f4e283..e6c35ac1 100644 --- a/app/services/export_server.rb +++ b/app/services/export_server.rb @@ -33,7 +33,7 @@ def execute return end - output, status = Open3.capture2("git commit -m 'Update at #{DateTime.now.to_s}'", :chdir=>chdir) + output, status = Open3.capture2("git commit -s -m 'Update at #{DateTime.now.to_s}'", :chdir=>chdir) if !status.success? job_logger.error "failed to git commit, error: #{output}" return