repo edit: fix interactive mode in GHES < 3.3
This commit is contained in:
parent
aff26cbcfc
commit
80f130184c
3 changed files with 41 additions and 2 deletions
|
|
@ -37,6 +37,7 @@ type RepositoryFeatures struct {
|
|||
IssueTemplateQuery bool
|
||||
PullRequestTemplateQuery bool
|
||||
VisibilityField bool
|
||||
AutoMerge bool
|
||||
}
|
||||
|
||||
var allRepositoryFeatures = RepositoryFeatures{
|
||||
|
|
@ -44,6 +45,7 @@ var allRepositoryFeatures = RepositoryFeatures{
|
|||
IssueTemplateQuery: true,
|
||||
PullRequestTemplateQuery: true,
|
||||
VisibilityField: true,
|
||||
AutoMerge: true,
|
||||
}
|
||||
|
||||
type detector struct {
|
||||
|
|
@ -107,6 +109,9 @@ func (d *detector) RepositoryFeatures() (RepositoryFeatures, error) {
|
|||
if field.Name == "visibility" {
|
||||
features.VisibilityField = true
|
||||
}
|
||||
if field.Name == "autoMergeAllowed" {
|
||||
features.AutoMerge = true
|
||||
}
|
||||
}
|
||||
|
||||
return features, nil
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ func TestRepositoryFeatures(t *testing.T) {
|
|||
IssueTemplateQuery: true,
|
||||
PullRequestTemplateQuery: true,
|
||||
VisibilityField: true,
|
||||
AutoMerge: true,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
|
|
@ -123,6 +124,23 @@ func TestRepositoryFeatures(t *testing.T) {
|
|||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "GHE has automerge field",
|
||||
hostname: "git.my.org",
|
||||
queryResponse: map[string]string{
|
||||
`query Repository_fields\b`: heredoc.Doc(`
|
||||
{ "data": { "Repository": { "fields": [
|
||||
{"name": "autoMergeAllowed"}
|
||||
] } } }
|
||||
`),
|
||||
},
|
||||
wantFeatures: RepositoryFeatures{
|
||||
IssueTemplateMutation: true,
|
||||
IssueTemplateQuery: true,
|
||||
AutoMerge: true,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/cli/cli/v2/api"
|
||||
fd "github.com/cli/cli/v2/internal/featuredetection"
|
||||
"github.com/cli/cli/v2/internal/ghinstance"
|
||||
"github.com/cli/cli/v2/internal/ghrepo"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
|
|
@ -48,6 +49,7 @@ type EditOptions struct {
|
|||
AddTopics []string
|
||||
RemoveTopics []string
|
||||
InteractiveMode bool
|
||||
Detector fd.Detector
|
||||
// Cache of current repo topics to avoid retrieving them
|
||||
// in multiple flows.
|
||||
topicsCache []string
|
||||
|
|
@ -158,9 +160,17 @@ func editRun(ctx context.Context, opts *EditOptions) error {
|
|||
repo := opts.Repository
|
||||
|
||||
if opts.InteractiveMode {
|
||||
detector := opts.Detector
|
||||
if detector == nil {
|
||||
detector = fd.NewDetector(opts.HTTPClient, repo.RepoHost())
|
||||
}
|
||||
repoFeatures, err := detector.RepositoryFeatures()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apiClient := api.NewClientFromHTTP(opts.HTTPClient)
|
||||
fieldsToRetrieve := []string{
|
||||
"autoMergeAllowed",
|
||||
"defaultBranchRef",
|
||||
"deleteBranchOnMerge",
|
||||
"description",
|
||||
|
|
@ -174,8 +184,14 @@ func editRun(ctx context.Context, opts *EditOptions) error {
|
|||
"rebaseMergeAllowed",
|
||||
"repositoryTopics",
|
||||
"squashMergeAllowed",
|
||||
"visibility",
|
||||
}
|
||||
if repoFeatures.VisibilityField {
|
||||
fieldsToRetrieve = append(fieldsToRetrieve, "visibility")
|
||||
}
|
||||
if repoFeatures.AutoMerge {
|
||||
fieldsToRetrieve = append(fieldsToRetrieve, "autoMergeAllowed")
|
||||
}
|
||||
|
||||
opts.IO.StartProgressIndicator()
|
||||
fetchedRepo, err := api.FetchRepository(apiClient, opts.Repository, fieldsToRetrieve)
|
||||
opts.IO.StopProgressIndicator()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue