X Tutup
Skip to content

Commit aeb7f33

Browse files
committed
Ensure issue create fails fast if issues are disabled
Before, a person would be prompted for title & body before unconditionally failing due to issues being disabled.
1 parent 66534e5 commit aeb7f33

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

api/queries_issue.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,8 @@ const fragments = `
4141
}
4242
`
4343

44-
func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*Issue, error) {
45-
repo, err := GitHubRepo(client, ghRepo)
46-
if err != nil {
47-
return nil, err
48-
}
49-
50-
if !repo.HasIssuesEnabled {
51-
return nil, fmt.Errorf("the '%s/%s' repository has disabled issues", ghRepo.RepoOwner(), ghRepo.RepoName())
52-
}
53-
44+
// IssueCreate creates an issue in a GitHub repository
45+
func IssueCreate(client *Client, repo *Repository, params map[string]interface{}) (*Issue, error) {
5446
query := `
5547
mutation CreateIssue($input: CreateIssueInput!) {
5648
createIssue(input: $input) {
@@ -76,7 +68,7 @@ func IssueCreate(client *Client, ghRepo Repo, params map[string]interface{}) (*I
7668
}
7769
}{}
7870

79-
err = client.GraphQL(query, variables, &result)
71+
err := client.GraphQL(query, variables, &result)
8072
if err != nil {
8173
return nil, err
8274
}

command/issue.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ func issueCreate(cmd *cobra.Command, args []string) error {
257257
return err
258258
}
259259

260+
repo, err := api.GitHubRepo(apiClient, baseRepo)
261+
if err != nil {
262+
return err
263+
}
264+
if !repo.HasIssuesEnabled {
265+
return fmt.Errorf("the '%s/%s' repository has disabled issues", baseRepo.RepoOwner(), baseRepo.RepoName())
266+
}
267+
260268
title, err := cmd.Flags().GetString("title")
261269
if err != nil {
262270
return errors.Wrap(err, "could not parse title")
@@ -291,7 +299,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
291299
"body": body,
292300
}
293301

294-
newIssue, err := api.IssueCreate(apiClient, baseRepo, params)
302+
newIssue, err := api.IssueCreate(apiClient, repo, params)
295303
if err != nil {
296304
return err
297305
}

0 commit comments

Comments
 (0)
X Tutup