From bbd0517175c320f499150d5eb592617b0d9a3f77 Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Tue, 23 Apr 2024 13:52:08 +0300 Subject: [PATCH] Only auto approve or set auto complete when a PR is created or is updated (#1101) This reduces the number of network calls and paves way for re-approval or PRs --- updater/bin/update_script.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/updater/bin/update_script.rb b/updater/bin/update_script.rb index cfd539d9..919caec0 100644 --- a/updater/bin/update_script.rb +++ b/updater/bin/update_script.rb @@ -781,6 +781,7 @@ def show_diff(original_file, updated_file) end pull_request_id = nil + created_or_updated = false if conflict_pull_request_commit && conflict_pull_request_id ############################################## # Update pull request with conflict resolved # @@ -799,6 +800,8 @@ def show_diff(original_file, updated_file) pr_updater.update pull_request = existing_pull_request pull_request_id = conflict_pull_request_id + + created_or_updated = true elsif !existing_pull_request # Only create PR if there is none existing ######################################## # Create a pull request for the update # @@ -844,6 +847,8 @@ def show_diff(original_file, updated_file) else puts "Seems PR is already present." end + + created_or_updated = true else pull_request = existing_pull_request # One already existed pull_request_id = pull_request["pullRequestId"] @@ -854,7 +859,7 @@ def show_diff(original_file, updated_file) next unless pull_request_id # Auto approve this Pull Request - if $options[:auto_approve_pr] + if $options[:auto_approve_pr] && created_or_updated puts "Auto Approving PR #{pull_request_id}" azure_client.pull_request_approve( @@ -878,7 +883,7 @@ def show_diff(original_file, updated_file) # - [Changelog](....) # - [Commits](....) merge_commit_message = "Merged PR #{pull_request_id}: #{msg.pr_name}\n\n#{msg.commit_message}" - if $options[:set_auto_complete] + if $options[:set_auto_complete] && created_or_updated auto_complete_user_id = pull_request["createdBy"]["id"] puts "Setting auto complete on ##{pull_request_id}." azure_client.autocomplete_pull_request(