X Tutup
Skip to content

Commit 5f67ddc

Browse files
committed
added to repo struct and working on fetching merge opts for repo
1 parent f1ea910 commit 5f67ddc

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

api/queries_repo.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type Repository struct {
3232

3333
Parent *Repository
3434

35+
MergeCommitAllowed bool
36+
SquashMergeAllowed bool
37+
RebaseMergeAllowed bool
38+
3539
// pseudo-field that keeps track of host name of this repo
3640
hostname string
3741
}
@@ -869,3 +873,30 @@ func MilestoneByNumber(client *Client, repo ghrepo.Interface, number int) (*Repo
869873

870874
return query.Repository.Milestone, nil
871875
}
876+
877+
func GetRepoPROpts(client *Client, repo ghrepo.Interface) (*Repository, error) {
878+
query := `
879+
query RepositoryInfo($owner: String!, $name: String!) {
880+
repository(owner: $owner, name: $name) {
881+
mergeCommitAllowed
882+
squashMergeAllowed
883+
rebaseMergeAllowed
884+
}
885+
}`
886+
variables := map[string]interface{}{
887+
"owner": repo.RepoOwner(),
888+
"name": repo.RepoName(),
889+
}
890+
891+
result := struct {
892+
Repository Repository
893+
}{}
894+
895+
err := client.GraphQL(repo.RepoHost(), query, variables, &result)
896+
897+
if err != nil {
898+
return nil, err
899+
}
900+
901+
return &result.Repository, nil
902+
}

pkg/cmd/pr/merge/merge.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func mergeRun(opts *MergeOptions) error {
140140
crossRepoPR := pr.HeadRepositoryOwner.Login != baseRepo.RepoOwner()
141141

142142
if opts.InteractiveMode {
143-
mergeMethod, deleteBranch, err = prInteractiveMerge(opts.DeleteLocalBranch, crossRepoPR)
143+
mergeMethod, deleteBranch, err = prInteractiveMerge(opts.DeleteLocalBranch, crossRepoPR, baseRepo, apiClient)
144144
if err != nil {
145145
return nil
146146
}
@@ -237,7 +237,9 @@ func mergeRun(opts *MergeOptions) error {
237237
return nil
238238
}
239239

240-
func prInteractiveMerge(deleteLocalBranch bool, crossRepoPR bool) (api.PullRequestMergeMethod, bool, error) {
240+
func prInteractiveMerge(deleteLocalBranch bool, crossRepoPR bool, repo ghrepo.Interface, apiClient *api.Client) (api.PullRequestMergeMethod, bool, error) {
241+
repoMergeOpts, err := api.GetRepoPROpts(apiClient, repo)
242+
241243
mergeMethodQuestion := &survey.Question{
242244
Name: "mergeMethod",
243245
Prompt: &survey.Select{

0 commit comments

Comments
 (0)
X Tutup