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

Retarget Pulls Based on Pulls on Merge #18478

Closed
wants to merge 5 commits into from

Conversation

kvaster
Copy link
Contributor

@kvaster kvaster commented Jan 31, 2022

Sometimes you need to work on feature which depends on another feature which is in a review process. In this case you may create PR based on that feature insteadof main branch. Currently such PR will be closed without possibility to reopen in case parent feature will be approved, merged and it's branch will be deleted. Automatic target branch change will make life a lot easier in such cases. Github and Bitbucket behaves in such way.

Example:
PR1: main <- feature 1
PR2: feature <- feature2

Currently merging PR1 and deleteing it's branch will lead to PR2 closed without possibility to reopen without loosing it's review histort.

With this change PR2 will change it's target branch to main (PR2: main <- feature2) after PR1 will be merged and it's branch will be deleted.

fixes #18408

@kvaster kvaster changed the title Rebase PRs on merge if possible Rebase PRs on merge if possible, fixes #18408 Jan 31, 2022
@lunny
Copy link
Member

lunny commented Jan 31, 2022

The PRs should be rebased when base branch updated but not when merging or deleting the branch.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 31, 2022
@kvaster
Copy link
Contributor Author

kvaster commented Jan 31, 2022

I think I've used wrong words. This PR is about changing PR's target branch. I will change names.

@kvaster kvaster changed the title Rebase PRs on merge if possible, fixes #18408 Change branch pulls target branch insteadof closing them on base branch merge and delete, fixes #18408 Jan 31, 2022
@kvaster
Copy link
Contributor Author

kvaster commented Jan 31, 2022

I've updated descritpion and names inside PR. Hopefully it's more clear now...

@kvaster kvaster changed the title Change branch pulls target branch insteadof closing them on base branch merge and delete, fixes #18408 Try to keep branch PRs open when branch is deleted cause of it's PR merged and closed, fixes #18408 Feb 1, 2022
@kvaster
Copy link
Contributor Author

kvaster commented Feb 18, 2022

Any chances to discuss possibility of such change ? Other git systems are using such approach and it is really usefull and it breaks nothing... And changes are very small.

@stale
Copy link

stale bot commented Apr 27, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label Apr 27, 2022
@spiffytortoise
Copy link

Chiming in since a stale label got added.

Having PRs get their base branch updated when a PR for the base branch is merged like this would be great. My team previously used Bitbucket's equivalent feature often for landing complex features in multiple stages.

@stale stale bot removed the issue/stale label Apr 27, 2022
@lunny
Copy link
Member

lunny commented Apr 28, 2022

I think Gitea should not change the target branch automatically but it could be changed manually.

@kvaster
Copy link
Contributor Author

kvaster commented Apr 28, 2022

Currently you're loosing all PRs discussions in such case. Can it be optional setting for gitea behaviour ?

@kvaster
Copy link
Contributor Author

kvaster commented Apr 28, 2022

Usually you and reviewer's don't care about 'child' branches. And 'option' (I will make PR for option) for automatic target branch change may be useful. Also this PR will have no any significant changes to codebase.

@spiffytortoise
Copy link

spiffytortoise commented Apr 28, 2022

How would the workflow for manually changing the target branch look? I can think of two ways currently that both have problems:

Example PRs:

main <- feature1
feature1 <- feature2

Manual Scenario 1, merge oldest to newest:

  1. Merge feature1 into main. Don't delete the feature1 branch, or else the feature2 PR will close.
  2. Change the base branch of feature2's PR from feature1 to main.
  3. Delete the feature1 branch.
  4. Merge feature2 into main.

It's too easy to delete feature1 at the wrong time and permanently close the feature2 PR by accident. (#18478)

Manual Scenario 2, merge newest to oldest:

  1. Merge feature2 into feature1.
  2. feature1's PR ends up with feature2's changes in its diff.
  3. Merge feature1 into main.

The diff change in step 2 adds a bunch of noise to the PR, which makes it more difficult to understand the PR after.

Auto-Update Scenario, merge oldest to newest:

In comparison, this is how Bitbucket Server works:

  1. Merge feature1 into main. Check "Delete feature1 and update the base branch of PRs targeting feature1 to main".
  2. Bitbucket atomically updates the base branch of feature2 from feature1 to main, without any additional diff being added or displayed in feature2's PR.
  3. Merge feature2 into main.

If using a rebase or rebase-and-merge strategy, the history ends up linear with any of these scenarios.

Why should Gitea not update PR base branches automatically?

@kvaster
Copy link
Contributor Author

kvaster commented May 8, 2022

I've updated PR according to upstream.

Any suggestion in what section to add flag for enabling/disabling this feature ?

@kvaster
Copy link
Contributor Author

kvaster commented May 8, 2022

One more PR update - make an option for retarget.

@6543 6543 changed the title Try to keep branch PRs open when branch is deleted cause of it's PR merged and closed, fixes #18408 Try to keep branch PRs open when branch is deleted cause of it's PR merged and closed May 8, 2022
@6543
Copy link
Member

6543 commented May 8, 2022

#18478 (comment)

hmm I think we can add some nice integration tests for mentioned cases

example:

t.Run("MergePR", doAPIMergePullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index))
t.Run("EnsureCanSeePull", doEnsureCanSeePull(baseCtx, pr))
t.Run("CheckPR", func(t *testing.T) {
oldMergeBase := pr.MergeBase
pr2, err := doAPIGetPullRequest(baseCtx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
assert.NoError(t, err)
assert.Equal(t, oldMergeBase, pr2.MergeBase)
})
t.Run("EnsurDiffNoChange", doEnsureDiffNoChange(baseCtx, pr, diffHash, diffLength))
// Then: Delete the head branch & make sure that doesn't break the PR page or change its diff
t.Run("DeleteHeadBranch", doBranchDelete(baseCtx, baseCtx.Username, baseCtx.Reponame, headBranch))

....

@6543 6543 added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label May 8, 2022
@6543 6543 changed the title Try to keep branch PRs open when branch is deleted cause of it's PR merged and closed Retarget Pulls Based on Pulls on Merge May 8, 2022
@lafriks
Copy link
Member

lafriks commented May 9, 2022

Does option is really needed for this? I mean is there a use case where re-targeting would be undesirable?

@6543
Copy link
Member

6543 commented May 9, 2022

I personaly would not mind if it always try retargeting ...
cc @lunny

@lunny
Copy link
Member

lunny commented May 10, 2022

I personaly would not mind if it always try retargeting ... cc @lunny

Maybe manually allowing to retarget pulls base branch even if base branch(or base repository) was deleted is better or it's the first step of this auto retarget.

@6543
Copy link
Member

6543 commented May 10, 2022

@kvaster in any case - we need integration tests, if you need help just tell us (here or chat via discord/matrix)

@kvaster
Copy link
Contributor Author

kvaster commented May 10, 2022

Will try to do this myself today and will get back tomorrow if will need any help.

@night-gold
Copy link

Hello, is this still an ongoing PR or has it been abandoned?

modules/setting/repository.go Outdated Show resolved Hide resolved
modules/setting/repository.go Outdated Show resolved Hide resolved
routers/web/repo/pull.go Outdated Show resolved Hide resolved
@kvaster
Copy link
Contributor Author

kvaster commented Dec 6, 2022

Actually we're using this patch already for long time, but it was difficult for me to write tests... However I can do necessary changes to PR itself...

@codecov-commenter
Copy link

codecov-commenter commented Mar 26, 2023

Codecov Report

Merging #18478 (1e270a4) into main (f521e88) will increase coverage by 0.00%.
The diff coverage is 41.40%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff            @@
##             main   #18478    +/-   ##
========================================
  Coverage   47.14%   47.15%            
========================================
  Files        1149     1155     +6     
  Lines      151446   152431   +985     
========================================
+ Hits        71397    71872   +475     
- Misses      71611    72071   +460     
- Partials     8438     8488    +50     
Impacted Files Coverage Δ
cmd/dump.go 0.66% <0.00%> (-0.01%) ⬇️
cmd/web.go 0.00% <0.00%> (ø)
models/actions/run.go 1.64% <0.00%> (-0.08%) ⬇️
models/actions/runner.go 1.44% <ø> (ø)
models/packages/package.go 45.45% <0.00%> (-1.13%) ⬇️
models/user/search.go 77.50% <0.00%> (-6.29%) ⬇️
modules/actions/workflows.go 0.00% <0.00%> (ø)
modules/context/context.go 64.54% <0.00%> (-3.53%) ⬇️
modules/doctor/storage.go 30.65% <0.00%> (-1.29%) ⬇️
modules/setting/git.go 45.45% <ø> (ø)
... and 37 more

... and 47 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

routers/web/repo/pull.go Outdated Show resolved Hide resolved
@zeripath
Copy link
Contributor

Thanks for this PR - sorry it's taking so long to get in.

A few thoughts:

  1. Could you explain why this retargeting only occurs if the new target is in the same repo? Is this to copy Github's behaviour?
  2. I think it might be better to make this on by default.
  3. I suspect we would be better off making this setting part of PullRequestsConfig and allowing repos to set this on/off by themselves.

@kvaster
Copy link
Contributor Author

kvaster commented Mar 26, 2023

Telling the truth, I was not aware about retargeting to another repository, but now I think it might be also usefull.
I also think it will not hurt anybody if it will be on by default. And an option inside repository itself will be even better.

@kvaster
Copy link
Contributor Author

kvaster commented Mar 26, 2023

It was started something long ago. I think I've not prepare code for retargeting to new repository cause ChangeTargetBranch function was already implemented while there was no ChangeTargetBranchAndRepo...

@denyskon
Copy link
Member

denyskon commented Jan 3, 2024

Closing in favor of #28539. If there is a reason to, feel free to reopen.

@denyskon denyskon closed this Jan 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow cascade PRs