Skip to content

Commit

Permalink
Only auto approve or set auto complete when a PR is created or is upd…
Browse files Browse the repository at this point in the history
…ated (#1101)

This reduces the number of network calls and paves way for re-approval or PRs
  • Loading branch information
mburumaxwell authored Apr 23, 2024
1 parent 4ffc72b commit bbd0517
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions updater/bin/update_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand All @@ -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 #
Expand Down Expand Up @@ -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"]
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit bbd0517

Please sign in to comment.