Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retrieve active pull requests against chosen target branch #728

Closed
wants to merge 2 commits into from

Conversation

THETCR
Copy link

@THETCR THETCR commented Aug 1, 2023

With the current behaviour PRs are not updated or closed when the target branch deviates from the default branch.

@mburumaxwell
Copy link
Contributor

What happens if the branch is not set in the options/configuration?

@THETCR
Copy link
Author

THETCR commented Aug 2, 2023

When creating a new instance of Dependabot::Source the branch property is also passed in directly.
So in it's current state there is no fallback at all.

You could choose to get the default branch as fallback and apply that everywhere, making it completely optional.

@THETCR
Copy link
Author

THETCR commented Aug 2, 2023

@mburumaxwell
Updated the PR to set the branch property to the repositories default branch when it's omitted by the end user.

@THETCR THETCR force-pushed the fix/active-pull-requests branch from 59a3137 to 7aa6c7e Compare August 2, 2023 20:17
@mburumaxwell
Copy link
Contributor

Wouldn't it be better to create a new variable named target_branch right at the point where we fetch pull requests instead of updating the global options?

@@ -554,8 +554,8 @@ def show_diff(original_file, updated_file)
credentials: $options[:credentials]
)
user_id = azure_client.get_user_id
default_branch_name = azure_client.fetch_default_branch($source.repo)
active_pull_requests = azure_client.pull_requests_active(user_id, default_branch_name)
$options[:branch] = azure_client.fetch_default_branch($source.repo) unless $options[:branch]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- $options[:branch] = azure_client.fetch_default_branch($source.repo) unless $options[:branch]
+ target_branch = $options[:branch] || azure_client.fetch_default_branch($source.repo)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a local variable and so creating a new reference in memory seems like a waste of resources, since you already have a pointer that was intended for this purpose.

After execution the branch property is not going to be changed by the end user anymore and there is no further mutation being done on target_branch, so I reckon this unnecessarily costs memory and CPU cycles.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mburumaxwell any feedback on the above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preference is to not do any changes to the $options object after the initial setup.

default_branch_name = azure_client.fetch_default_branch($source.repo)
active_pull_requests = azure_client.pull_requests_active(user_id, default_branch_name)
$options[:branch] = azure_client.fetch_default_branch($source.repo) unless $options[:branch]
active_pull_requests = azure_client.pull_requests_active(user_id, $options[:branch])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- active_pull_requests = azure_client.pull_requests_active(user_id, $options[:branch])
+ active_pull_requests = azure_client.pull_requests_active(user_id, target_branch)

@@ -922,7 +922,7 @@ def show_diff(original_file, updated_file)
# look for pull requests that are no longer needed to be abandoned
if $options[:close_unwanted]
puts "Looking for pull requests that are no longer needed."
active_pull_requests = azure_client.pull_requests_active(user_id, default_branch_name)
active_pull_requests = azure_client.pull_requests_active(user_id, $options[:branch])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-   active_pull_requests = azure_client.pull_requests_active(user_id, $options[:branch])
+   active_pull_requests = azure_client.pull_requests_active(user_id, target_branch)

@mburumaxwell
Copy link
Contributor

This should be fixed in #797

@mburumaxwell
Copy link
Contributor

Released yesterday. You may create a new issue if you experience trouble. Closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants