Skip to content

Commit 1128439

Browse files
committed
issue/pr create: hide "Add metadata" if viewer does not have triage permission
1 parent d7e6d21 commit 1128439

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

api/queries_repo.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,24 @@ func (r Repository) ViewerCanPush() bool {
6666
}
6767
}
6868

69+
// ViewerCanTriage is true when the requesting user can triage issues and pull requests
70+
func (r Repository) ViewerCanTriage() bool {
71+
switch r.ViewerPermission {
72+
case "ADMIN", "MAINTAIN", "WRITE", "TRIAGE":
73+
return true
74+
default:
75+
return false
76+
}
77+
}
78+
6979
func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
7080
query := `
7181
query($owner: String!, $name: String!) {
7282
repository(owner: $owner, name: $name) {
7383
id
7484
hasIssuesEnabled
7585
description
86+
viewerPermission
7687
}
7788
}`
7889
variables := map[string]interface{}{

command/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
428428
interactive := !(cmd.Flags().Changed("title") && cmd.Flags().Changed("body"))
429429

430430
if interactive {
431-
err := titleBodySurvey(cmd, &tb, apiClient, baseRepo, title, body, defaults{}, templateFiles, false)
431+
err := titleBodySurvey(cmd, &tb, apiClient, baseRepo, title, body, defaults{}, templateFiles, false, repo.ViewerCanTriage())
432432
if err != nil {
433433
return fmt.Errorf("could not collect title and/or body: %w", err)
434434
}

command/pr_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
217217
templateFiles = githubtemplate.Find(rootDir, "PULL_REQUEST_TEMPLATE")
218218
}
219219

220-
err := titleBodySurvey(cmd, &tb, client, baseRepo, title, body, defs, templateFiles, true)
220+
err := titleBodySurvey(cmd, &tb, client, baseRepo, title, body, defs, templateFiles, true, baseRepo.ViewerCanTriage())
221221
if err != nil {
222222
return fmt.Errorf("could not collect title and/or body: %w", err)
223223
}

command/title_body_survey.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func selectTemplate(templatePaths []string) (string, error) {
126126
return string(templateContents), nil
127127
}
128128

129-
func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClient *api.Client, repo ghrepo.Interface, providedTitle, providedBody string, defs defaults, templatePaths []string, allowReviewers bool) error {
129+
func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClient *api.Client, repo ghrepo.Interface, providedTitle, providedBody string, defs defaults, templatePaths []string, allowReviewers, allowMetadata bool) error {
130130
editorCommand := os.Getenv("GH_EDITOR")
131131
if editorCommand == "" {
132132
ctx := contextForCommand(cmd)
@@ -192,7 +192,6 @@ func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClie
192192
}
193193

194194
allowPreview := !issueState.HasMetadata()
195-
allowMetadata := true
196195
confirmA, err := confirmSubmission(allowPreview, allowMetadata)
197196
if err != nil {
198197
return fmt.Errorf("unable to confirm: %w", err)
@@ -324,8 +323,8 @@ func titleBodySurvey(cmd *cobra.Command, issueState *issueMetadataState, apiClie
324323
issueState.Milestone = ""
325324
}
326325

327-
allowPreview := !issueState.HasMetadata()
328-
allowMetadata := false
326+
allowPreview = !issueState.HasMetadata()
327+
allowMetadata = false
329328
confirmA, err = confirmSubmission(allowPreview, allowMetadata)
330329
if err != nil {
331330
return fmt.Errorf("unable to confirm: %w", err)

0 commit comments

Comments
 (0)