Support auto detecting branch for PRs (#525)

Fix #524

Co-authored-by: harryzcy <harry@harryzheng.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/525
Co-authored-by: harryzcy <harryzcy@noreply.gitea.com>
Co-committed-by: harryzcy <harryzcy@noreply.gitea.com>
This commit is contained in:
harryzcy
2024-07-26 19:21:48 +00:00
committed by techknowlogick
parent 4ba3139224
commit 100c5a9eee
3 changed files with 131 additions and 12 deletions

View File

@ -4,11 +4,11 @@
package pulls
import (
"fmt"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
@ -44,7 +44,8 @@ var CmdPullsMerge = cli.Command{
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() != 1 {
return fmt.Errorf("Must specify a PR index")
// If no PR index is provided, try interactive mode
return interact.MergePull(ctx)
}
idx, err := utils.ArgToIndex(ctx.Args().First())
@ -52,18 +53,10 @@ var CmdPullsMerge = cli.Command{
return err
}
success, _, err := ctx.Login.Client().MergePullRequest(ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
return task.PullMerge(ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
Style: gitea.MergeStyle(ctx.String("style")),
Title: ctx.String("title"),
Message: ctx.String("message"),
})
if err != nil {
return err
}
if !success {
return fmt.Errorf("Failed to merge PR. Is it still open?")
}
return nil
},
}