Skip to content

Commit 2d782fc

Browse files
committed
Retrieve repo outside of survey function
1 parent 71a66cc commit 2d782fc

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

pkg/cmd/pr/merge/merge.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/spf13/cobra"
2020
)
2121

22+
var cancelError = errors.New("cancelError")
23+
2224
type MergeOptions struct {
2325
HttpClient func() (*http.Client, error)
2426
Config func() (config.Config, error)
@@ -137,7 +139,12 @@ func mergeRun(opts *MergeOptions) error {
137139
mergeMethod := opts.MergeMethod
138140

139141
if opts.InteractiveMode {
140-
mergeMethod, deleteBranch, err = prInteractiveMerge(opts, crossRepoPR, baseRepo, apiClient)
142+
r, err := api.GitHubRepo(apiClient, baseRepo)
143+
if err != nil {
144+
return err
145+
}
146+
147+
mergeMethod, deleteBranch, err = prInteractiveMerge(opts, r, crossRepoPR)
141148
if err != nil {
142149
if errors.Is(err, cancelError) {
143150
fmt.Fprintln(opts.IO.ErrOut, "Cancelled.")
@@ -229,35 +236,17 @@ func mergeRun(opts *MergeOptions) error {
229236
return nil
230237
}
231238

232-
var cancelError = errors.New("cancelError")
233-
234-
func prInteractiveMerge(opts *MergeOptions, crossRepoPR bool, repo ghrepo.Interface, apiClient *api.Client) (api.PullRequestMergeMethod, bool, error) {
235-
var baseRepo *api.Repository
236-
237-
if r, ok := repo.(*api.Repository); ok {
238-
baseRepo = r
239-
} else {
240-
var err error
241-
baseRepo, err = api.GitHubRepo(apiClient, repo)
242-
if err != nil {
243-
return 0, false, fmt.Errorf("could not fetch merge options: %w", err)
244-
}
245-
}
246-
239+
func prInteractiveMerge(opts *MergeOptions, baseRepo *api.Repository, crossRepoPR bool) (api.PullRequestMergeMethod, bool, error) {
247240
var mergeOpts []string
248-
249241
if baseRepo.MergeCommitAllowed {
250242
mergeOpts = append(mergeOpts, "Create a merge commit")
251243
}
252-
253244
if baseRepo.RebaseMergeAllowed {
254245
mergeOpts = append(mergeOpts, "Rebase and merge")
255246
}
256-
257247
if baseRepo.SquashMergeAllowed {
258248
mergeOpts = append(mergeOpts, "Squash and merge")
259249
}
260-
261250
if len(mergeOpts) == 0 {
262251
return 0, false, fmt.Errorf("no merge options enabled, please enable at least one for your repo")
263252
}

0 commit comments

Comments
 (0)