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

Handle existing upgrade PRs #267

Merged
merged 8 commits into from
Nov 27, 2024
Merged

Handle existing upgrade PRs #267

merged 8 commits into from
Nov 27, 2024

Conversation

alextu
Copy link
Member

@alextu alextu commented Nov 26, 2024

Fix #252

  • Do not execute the update if a branch with the same version already exists
  • Do not create the PR if a closed one for the same version already exists
    PRs can be recreated by setting options.recreateClosedPullRequests to true.

Fix #211

  • Close existing open PR targeting older versions

@alextu
Copy link
Member Author

alextu commented Nov 26, 2024

@StefMa please take a look as well, if you can try this on your side that would be great as well 🙂

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Member

@erichaagdev erichaagdev left a comment

Choose a reason for hiding this comment

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

Requesting changes because ignoreClosedPullRequests should be renamed to recreateClosedPullRequests.

build.gradle Show resolved Hide resolved
@alextu alextu merged commit 48b4fc4 into main Nov 27, 2024
13 checks passed
@alextu alextu deleted the atual/check-branch branch November 27, 2024 15:11
return;
}
PullRequestUtils utils = new PullRequestUtils(pullRequests(params));
if (utils.openPrExists(params.prBranch)) {
Copy link
Contributor

@StefMa StefMa Nov 27, 2024

Choose a reason for hiding this comment

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

I'm not sure if I understand correctly, but will this branch ever reached? 🤔

We have the check above branchExist.
If it exist -> return
Here we are asking for openPrExists (for this branch name?)
If so, return

However, if that branchExist (because there is an openPr), then we return already in Line 71?! 🤔
No?

It other words:
If there NO branch, then there is NO PR.
But if a branch exist (and maybe a PR), this will never be reached because we return early in Line 74.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback, you're right: there should not be a case where a branch does not exist and an opened PR exists with the same branch, I forgot that GitHub closes the PR automatically in that case. I will fix this in a new PR

Copy link
Member Author

Choose a reason for hiding this comment

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

@StefMa please check #269

Comment on lines +16 to 18
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it makes finally sense to extract the GitHub API communcation behind an interface so we can test it easiliy 😇

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, tbh I'd rather have better e2e testing, we'll see what we do next.

Copy link
Contributor

@StefMa StefMa left a comment

Choose a reason for hiding this comment

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

Havent tested it yet, will do probably tomorrow mroning (UTC+1) 😅
One question about an if branch that might not be reached.
Also a suggeston to move the Github API calls to an interface to abstract it away.
Right now it feels a bit messy to use it directly "everywhere"...
Also it makes testing a bit hard.

Otherwise looks good to me 🙃
Thanks for the addtitions.
Cant wait to have them 🚀

Oh.. and sorry for the review after merge 🙈
I didn't find the time until now..

@StefMa
Copy link
Contributor

StefMa commented Nov 28, 2024

Tested:
Downgrade Gradle to 8.11. Pushed that to a branch named gradle-8.11.
Set baseBranch to gradle-8.11.

First run:
Open PR (StefMa#1).
Run it, output is:

GitHub branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'

Expected ✅

Second run:
Closed the PR not deleted the branch.
Run it, output is:

GitHub branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'

I guess the output should be

A closed pull request from branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'. Use `recreateClosedPullRequests` option to recreate it.

Third run:
Deleted the branch
Run it, output is:

A closed pull request from branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'. Use `recreateClosedPullRequests` option to recreate it.

I guess the output should be

PR created 

Because its not there?! 🤷 🤔

Fourth run:
Branch is still deleted, added recreateClosedPullRequests.
Run it, output is:

https://github.com/StefMa/wrapper-upgrade-gradle-plugin/pull/2

Expected ✅

| `options.gitCommitExtraArgs` | List of additional git commit arguments |
| `options.allowPreRelease` | Boolean: `true` will get the latest Maven/Gradle version even if it's a pre-release. Default is `false`. |
| `options.labels` | Optional list of label (names) that will be added to the pull request. |
| `options.recreateClosedPullRequests` | Boolean: `true` will recreate the pull request if a closed pull request with the same branch name exists. `false` will not recreate the pull request. Default is `false`. |
Copy link
Contributor

Choose a reason for hiding this comment

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

I just stumbled over this while testing it.
Maybe we should remove the last s.
Its just a single PR, right?
options.recreateClosedPullRequest

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will rename it

@alextu
Copy link
Member Author

alextu commented Nov 28, 2024

Second run: Closed the PR not deleted the branch. Run it, output is:

GitHub branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'

I guess the output should be

A closed pull request from branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'. Use `recreateClosedPullRequests` option to recreate it.

That message would be misleading as the branch still exists and we should not do anything if the branch exists. I would stick with the current simple approach and message: existing branch = don't go further.

Third run: Deleted the branch Run it, output is:

A closed pull request from branch 'wrapperbot/wrapper-upgrade-gradle-plugin/gradle-wrapper-8.11.1' to upgrade Gradle Wrapper to 8.11.1 already exists for project 'wrapper-upgrade-gradle-plugin'. Use `recreateClosedPullRequests` option to recreate it.

I guess the output should be

PR created 

Because its not there?! 🤷 🤔

Not sure to understand the suggestion 🤔. As I see it: a PR exists and is closed, so we notified the user and no new PR is created.

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