[why] for non-gitee repos: we may sometimes can not get the author email from the http request feedback when checking the commit. users may still receive a fail email even if they send 'apply account' email correctly.
[how] both gitee and non-gitee will clone the repo tree and check the commit: - check commit id exists - check commit author matches the email
Signed-off-by: Luan Shengde shdluan@163.com --- .../lib/parse-apply-account-email.rb | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/container/mail-robot/lib/parse-apply-account-email.rb b/container/mail-robot/lib/parse-apply-account-email.rb index a41a89a..8baf7b7 100755 --- a/container/mail-robot/lib/parse-apply-account-email.rb +++ b/container/mail-robot/lib/parse-apply-account-email.rb @@ -6,7 +6,6 @@ require 'json' require 'mail' require 'rest-client' -require_relative 'gitee-commit-url-check'
# used to parse mail_content for my_commit_url and my_ssh_pubkey # be called by AssignAccount when it needs to extract required data: @@ -91,29 +90,34 @@ class ParseApplyAccountEmail end
def commit_url_availability(url, base_url) - hub_name = url.split('/')[2] - - # it requires authentication when sending request to get the commit information - # clone the repo and then validate the commit for the email address - if hub_name.eql? 'gitee.com' - gitee_commit(url, base_url) - else - non_gitee_commit(url) - end - end + repo_url = [base_url, 'git'].join('.') + repo_dir = repo_url.split('/')[-1] + commit_id = url.split('/')[-1] + + Dir.chdir '/tmp' + %x(/usr/bin/git clone --bare #{repo_url} #{repo_dir}) + + # get all commit IDs and check commit id exists + repo_commits = %x(git -C #{repo_dir} log --pretty=format:'%H').split(/\n/) + check_commit_exist(commit_id, repo_commits)
- def gitee_commit(url, base_url) - my_gitee_commit = GiteeCommitUrlCheck.new(@my_info, url, base_url) - my_gitee_commit.gitee_commit_check + # get the auther's email for the commit + author_email = %x(/usr/bin/git -C #{repo_dir} show -s --format=%aE #{commit_id}).chomp + check_commit_email(author_email) + + FileUtils.rm_rf repo_dir end
- def non_gitee_commit(url) - url_fdback = RestClient.get(url).body - email_index = url_fdback.index @my_info['my_email'] + def check_commit_exist(commit_id, repo_commits) + return if repo_commits.include? commit_id.chomp + + raise 'NO_COMMIT_ID' + end
- return unless email_index.nil? + def check_commit_email(author_email) + return if author_email.eql? @my_info['my_email'].chomp
- raise 'COMMIT_URL_NOT_AVAILABLE' + raise 'COMMIT_AUTHOR_ERROR' end
def parse_pub_key
On Tue, Feb 02, 2021 at 09:23:43AM +0800, Luan Shengde wrote:
[why] for non-gitee repos: we may sometimes can not get the author email from the http request feedback when checking the commit. users may still receive a fail email even if they send 'apply account' email correctly.
[how] both gitee and non-gitee will clone the repo tree and check the commit:
- check commit id exists
- check commit author matches the email
Signed-off-by: Luan Shengde shdluan@163.com
.../lib/parse-apply-account-email.rb | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/container/mail-robot/lib/parse-apply-account-email.rb b/container/mail-robot/lib/parse-apply-account-email.rb index a41a89a..8baf7b7 100755 --- a/container/mail-robot/lib/parse-apply-account-email.rb +++ b/container/mail-robot/lib/parse-apply-account-email.rb @@ -6,7 +6,6 @@ require 'json' require 'mail' require 'rest-client' -require_relative 'gitee-commit-url-check'
# used to parse mail_content for my_commit_url and my_ssh_pubkey # be called by AssignAccount when it needs to extract required data: @@ -91,29 +90,34 @@ class ParseApplyAccountEmail end
def commit_url_availability(url, base_url)
- hub_name = url.split('/')[2]
- # it requires authentication when sending request to get the commit information
- # clone the repo and then validate the commit for the email address
- if hub_name.eql? 'gitee.com'
gitee_commit(url, base_url)
- else
non_gitee_commit(url)
- end
- end
- repo_url = [base_url, 'git'].join('.')
- repo_dir = repo_url.split('/')[-1]
This is no need, git use this as the default
- commit_id = url.split('/')[-1]
- Dir.chdir '/tmp'
- %x(/usr/bin/git clone --bare #{repo_url} #{repo_dir})
Use %x(git -C /tmp clone --bare #{repo_url})
Thanks, Xueliang
- # get all commit IDs and check commit id exists
- repo_commits = %x(git -C #{repo_dir} log --pretty=format:'%H').split(/\n/)
- check_commit_exist(commit_id, repo_commits)
- def gitee_commit(url, base_url)
- my_gitee_commit = GiteeCommitUrlCheck.new(@my_info, url, base_url)
- my_gitee_commit.gitee_commit_check
- # get the auther's email for the commit
- author_email = %x(/usr/bin/git -C #{repo_dir} show -s --format=%aE #{commit_id}).chomp
- check_commit_email(author_email)
- FileUtils.rm_rf repo_dir end
- def non_gitee_commit(url)
- url_fdback = RestClient.get(url).body
- email_index = url_fdback.index @my_info['my_email']
- def check_commit_exist(commit_id, repo_commits)
- return if repo_commits.include? commit_id.chomp
- raise 'NO_COMMIT_ID'
- end
- return unless email_index.nil?
- def check_commit_email(author_email)
- return if author_email.eql? @my_info['my_email'].chomp
- raise 'COMMIT_URL_NOT_AVAILABLE'
raise 'COMMIT_AUTHOR_ERROR' end
def parse_pub_key
-- 2.23.0
- repo_url = [base_url, 'git'].join('.')
- repo_dir = repo_url.split('/')[-1]
This is no need, git use this as the default
I need to remove the repo after check. so I need to get the repo name.
- commit_id = url.split('/')[-1]
- Dir.chdir '/tmp'
- %x(/usr/bin/git clone --bare #{repo_url} #{repo_dir})
Use %x(git -C /tmp clone --bare #{repo_url})
I will optimize it
Thanks, Luan Shengde
Thanks, Xueliang
- # get all commit IDs and check commit id exists
- repo_commits = %x(git -C #{repo_dir} log --pretty=format:'%H').split(/\n/)
- check_commit_exist(commit_id, repo_commits)
- def gitee_commit(url, base_url)
- my_gitee_commit = GiteeCommitUrlCheck.new(@my_info, url, base_url)
- my_gitee_commit.gitee_commit_check
- # get the auther's email for the commit
- author_email = %x(/usr/bin/git -C #{repo_dir} show -s --format=%aE #{commit_id}).chomp
- check_commit_email(author_email)
- FileUtils.rm_rf repo_dir end
- def non_gitee_commit(url)
- url_fdback = RestClient.get(url).body
- email_index = url_fdback.index @my_info['my_email']
- def check_commit_exist(commit_id, repo_commits)
- return if repo_commits.include? commit_id.chomp
- raise 'NO_COMMIT_ID'
- end
- return unless email_index.nil?
- def check_commit_email(author_email)
- return if author_email.eql? @my_info['my_email'].chomp
- raise 'COMMIT_URL_NOT_AVAILABLE'
raise 'COMMIT_AUTHOR_ERROR' end
def parse_pub_key
-- 2.23.0