Skip to content

Commit

Permalink
Remove the --admin and --auto flags and ask interactively instead
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Apr 26, 2024
1 parent 99b9b13 commit 03becbc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cli/gh-extension-precompile@v1.3.1
- uses: cli/gh-extension-precompile@v1.4.0
30 changes: 19 additions & 11 deletions api/merge-pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/leofeyer/gh-merge/util"
)

func MergePr(pr string, auto bool, admin bool) error {
func MergePr(pr string) error {
err := checkStatus(pr)
if err != nil {
return err
Expand All @@ -31,23 +31,31 @@ func MergePr(pr string, auto bool, admin bool) error {
fmt.Println(body)

prompt := util.Confirm("Merge '"+subject+"' now?", false)
if prompt == false {
if !prompt {
return errors.New("Cancelled.")
}

args := []string{"pr", "merge", pr, "--subject", subject, "--body", body, "--squash"}

if auto {
args = append(args, "--auto")
}

if admin {
args = append(args, "--admin")
}

data, _, err := gh.Exec(args...)
if err != nil {
return err
if !strings.Contains(err.Error(), "not mergeable: the base branch policy prohibits the merge") {
return err
}

fmt.Println("The pull request is not mergeable because the base branch policy prohibits the merge.")

prompt = util.Confirm("Merge with admin privileges instead?", false)
if prompt {
args = append(args, "--admin")
} else {
args = append(args, "--auto")
}

data, _, err = gh.Exec(args...)
if err != nil {
return err
}
}

fmt.Print(data.String())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/leofeyer/gh-merge

go 1.18
go 1.19

require (
github.com/cli/go-gh v1.2.1
Expand Down
12 changes: 1 addition & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import (
"github.com/spf13/cobra"
)

type Options struct {
Auto bool
Admin bool
}

func rootCmd() *cobra.Command {
opts := &Options{}

cmd := &cobra.Command{
Use: "gh merge <number>",
Short: "Merge a pull request",
Expand All @@ -26,7 +19,7 @@ func rootCmd() *cobra.Command {
return err
}

err = api.MergePr(number, opts.Auto, opts.Admin)
err = api.MergePr(number)
if err != nil {
return err
}
Expand All @@ -42,9 +35,6 @@ func rootCmd() *cobra.Command {
SilenceUsage: true,
}

cmd.Flags().BoolVarP(&opts.Auto, "auto", "", false, "enable auto-merging the pull request")
cmd.Flags().BoolVarP(&opts.Admin, "admin", "", false, "merge the pull request with admin rights")

return cmd
}

Expand Down

0 comments on commit 03becbc

Please sign in to comment.