mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(pr): prefer an open pull request over a merged one recorded by checkout
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
2 files changed
+27
-6
No files matched your search
+15
-5
@@ -223,9 +223,10 @@ func (a *application) pullSelector(cmd *cobra.Command, args []string) (target, i
|
||||
return t, n, nil
|
||||
}
|
||||
|
||||
// currentPull finds the pull request of the checked-out branch: the one pr checkout recorded,
|
||||
// else the open pull request whose head is the branch's upstream (and the upstream remote's
|
||||
// owner), else one whose head has the local branch's name, else N from a pr/N branch.
|
||||
// currentPull finds the pull request of the checked-out branch: the one pr checkout recorded
|
||||
// while it is open, else the open pull request whose head is the branch's upstream (and the
|
||||
// upstream remote's owner), else one whose head has the local branch's name, else N from a pr/N
|
||||
// branch, else the recorded pull request even though it is no longer open.
|
||||
func (a *application) currentPull(ctx context.Context) (target, int64, error) {
|
||||
branch, err := git.CurrentBranchConfig(ctx, a.gitProbe(), a.options.cwd)
|
||||
if err != nil {
|
||||
@@ -235,10 +236,16 @@ func (a *application) currentPull(ctx context.Context) (target, int64, error) {
|
||||
if err != nil {
|
||||
return t, 0, err
|
||||
}
|
||||
service := services.Pulls{Client: t.client, Repository: t.Repo}
|
||||
// A recorded pull request that was merged or closed only counts when no open one has the branch.
|
||||
recorded := int64(0)
|
||||
if branch.PullNumber > 0 && (branch.BaseRemote == "" || a.remoteOwns(ctx, t, branch.BaseRemote)) {
|
||||
return t, branch.PullNumber, nil
|
||||
if pull, err := service.View(ctx, branch.PullNumber); err != nil || pull.State == "open" {
|
||||
return t, branch.PullNumber, nil
|
||||
}
|
||||
recorded = branch.PullNumber
|
||||
}
|
||||
pulls, err := (services.Pulls{Client: t.client, Repository: t.Repo}).ListOpen(ctx)
|
||||
pulls, err := service.ListOpen(ctx)
|
||||
if err != nil {
|
||||
return t, 0, err
|
||||
}
|
||||
@@ -261,6 +268,9 @@ func (a *application) currentPull(ctx context.Context) (target, int64, error) {
|
||||
return t, n, nil
|
||||
}
|
||||
}
|
||||
if recorded > 0 {
|
||||
return t, recorded, nil
|
||||
}
|
||||
return t, 0, fmt.Errorf("no open pull request for branch %q in %s; pass a number, URL or branch", branch.Name, t.Repo)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user