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

feat(git)!: determine branch modification based on all branch commits #28225

Merged
merged 46 commits into from
Apr 23, 2024

Conversation

AaronMoat
Copy link
Contributor

@AaronMoat AaronMoat commented Apr 4, 2024

Changes

Extract all authors from the git log of the changes in the branch for a given PR against master and use those in isBranchModified

Context

Currently, the documentation for gitIgnoredAuthors states:

Specify commit authors ignored by Renovate.

By default, Renovate will treat any PR as modified if another Git author has added to the branch. When a PR is considered modified, Renovate won't perform any further commits such as if it's conflicted or needs a version update. If you have other bots which commit on top of Renovate PRs, and don't want Renovate to treat these PRs as modified, then add the other Git author(s) to gitIgnoredAuthors.

The current implementation, however, only looks at the latest commit. If you have a flow like:

  1. Renovate commit
  2. Human commit
  3. Bot commit (e.g. formatting)

This will mean isBranchModified returns false and the rebase flow throws away commits 2 and 3.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@CLAassistant
Copy link

CLAassistant commented Apr 4, 2024

CLA assistant check
All committers have signed the CLA.

lib/util/git/index.ts Outdated Show resolved Hide resolved
@AaronMoat AaronMoat changed the title Make ignoredAuthors analyse all commits, not latest fix: Make ignoredAuthors analyse all commits, not latest Apr 4, 2024
@AaronMoat AaronMoat requested a review from samchungy April 4, 2024 09:55
@AaronMoat AaronMoat marked this pull request as ready for review April 4, 2024 09:55
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

We had a couple of attempts at this same concept and both times it caused unintended consequences causing it to be rolled back. It's important we understand why that happened and how this fresh attempt avoids the same problem before merging

@AaronMoat
Copy link
Contributor Author

Good call @rarkins I hadn't thought about checking closed issues/discussions so I hadn't seen that context.

I have found #21505 - this comment stands out to me #21504 (comment) - and I support the assessment because the attempt used origin/${branchName}...origin/${baseBranch}. This is wrong: it includes all commits that are different between the two branches, not just the new ones. https://stackoverflow.com/a/24186641/16823396

Are you able to find what the other issue was?

@AaronMoat
Copy link
Contributor Author

AaronMoat commented Apr 4, 2024

Ah, was this the second time? https://github.com/renovatebot/renovate/pull/21558/files#r1361930608

I think this attempt also doesn't have that problem.

That being said, if it's been wrong twice, who's to say it can't be a third time. What do you recommend to gain confidence?

@RahulGautamSingh
Copy link
Collaborator

RahulGautamSingh commented Apr 4, 2024

That being said, if it's been wrong twice, who's to say it can't be a third time. What do you recommend to gain confidence?

This PR does things correctly I think ie. instead of the wrong way origin/${branchName}...origin/${baseBranch} it uses the correct one origin/${baseBranch}...origin/${branchName}.

In both the previous attempts the wrong way was merged. I think some real runs will help us gain confidence.
If you can first test all the cases which made the previous attempts fail , then we can discuss from there.

Some example test runs:

  1. simple update PR (up-to-date with base branch and no other commits except bot's)
  2. simple update PR (behind base branch and no other commits except bot's)
  3. modified update PR
  4. conflicted update PR
  5. rebased update PR but no external commits
  6. rebased updated PR but with external commits (ie. a modified PR which has been rebased after user requested)
  7. feat: compare all branch authors when deciding if a branch is modified #20739 (comment)

Some other mixes like simple update PR with commits from ignored authors.

@AaronMoat
Copy link
Contributor Author

AaronMoat commented Apr 6, 2024

This is the test cases without using the gitIgnoredAuthors configuration.

  1. ✅ Up to date, clean PR happily ignored (1.run-on-update-pr.log) AaronMoat/renovate-testing@85e6cfe
  2. ✅ PR that's behind is happy ignored (2.run-on-update-pr-when-behind.log) or rebased with behind-base-branch (2.behind-base-with-rebasewhen-behind-base-branch.log - AaronMoat/renovate-testing@d95d200)
  3. ✅ PR that's been modified successfully gets the "Edited/Blocked Notification". renamed - Update dependency graphql to v16.8.1 AaronMoat/renovate-testing#2 (comment) (3.modified-pr.log)
  4. ✅ rebased (4.conflicted.log, AaronMoat/renovate-testing@460a58f)
  5. Update dependency axios to v1.6.8 - recreate AaronMoat/renovate-testing#4 commit remade and force pushed. See logs 👇
  6. Update dependency chalk to v5.3.0 - recreate AaronMoat/renovate-testing#5 same, custom changes thrown away.
    5-6.rebase.log
  7. ✅ It shows as modified: Update dependency graphql to v16.8.1 - abandoned AaronMoat/renovate-testing#3 (comment) (7.github-ui-update.log)

I will do some testing with the gitIgnoredAuthors configuration once we're satisfied that this hasn't broken any of the standard behaviour.

@AaronMoat AaronMoat requested a review from rarkins April 6, 2024 04:56
lib/util/git/index.ts Outdated Show resolved Hide resolved
@RahulGautamSingh
Copy link
Collaborator

RahulGautamSingh commented Apr 6, 2024

Sorry, I'm a bit confused. What does rebased update PR mean?

In update PR created by the bot. There is a checkbox present which user can check to rebase the PR.
[] If you want to rebase/retry this PR, check this box

Reading: https://docs.renovatebot.com/updating-rebasing/

@AaronMoat
Copy link
Contributor Author

Cool, rebase is fine too (updated prior comment).

As well,

This all seems to be working as expected for the cases I have tested.

@AaronMoat AaronMoat requested a review from viceice April 8, 2024 23:27
lib/modules/platform/local/scm.ts Show resolved Hide resolved
lib/util/git/index.ts Outdated Show resolved Hide resolved
lib/modules/platform/types.ts Outdated Show resolved Hide resolved
@rarkins rarkins changed the title fix: Make ignoredAuthors analyse all commits, not latest fix(git): Make ignoredAuthors analyse all commits, not latest Apr 13, 2024
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Make baseBranch mandatory

RahulGautamSingh and others added 3 commits April 21, 2024 12:08
Removes fallback to checking depName for all matchPackageX and excludePackageX rules.

BREAKING CHANGE: matchPackageNames and related functions no longer fall back to checking depName. Rewrite packageRules to use matchDepNames instead.
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Does this make or require any change to caching?

…for tag lookups (renovatebot#28400)

Changes default Docker Hub lookups from index.docker.io to hub.docker.com, which is more efficient. If you are configuring a Docker Hub token for docker.io then you should now configure it for docker.com as well. 

Closes renovatebot#24666

BREAKING CHANGE: Docker Hub lookups prefer hub.docker.com over index.docker.io. Set RENOVATE_X_DOCKER_HUB_TAGS_DISABLE=true in env to revert behavior.
@AaronMoat
Copy link
Contributor Author

Hmm, good question on caching changes.

One potential thing is that the cache is solely based on the branch name and not the base branch. I guess if you now call isBranchModified for multiple different base branches then you could get into trouble? Is there a use case for this? I'll take your guidance on if we need to fix or not.

lib/util/git/index.ts Outdated Show resolved Hide resolved
@rarkins
Copy link
Collaborator

rarkins commented Apr 22, 2024

If the cashing is based on branchName + commitSha then it might already work fine. If a branch SHA was "unmodified" on a previous run then it shouldn't change to modified even if the base branch has received commits. There's potentially an edge case where a modified one changes to unmodified due to creative git use but in that case they can request a rebase/retry

@AaronMoat
Copy link
Contributor Author

Thanks all for the work on this 🙏 is someone happy to merge for me? Looks like I can't myself 😄

@rarkins rarkins merged commit 2ff1569 into renovatebot:v38 Apr 23, 2024
34 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2024
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking Breaking change, requires major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants