fix(issue create): resolve --type before creating the issue by umairnaeem0309 · Pull Request #14727 · cli/cli · GitHub
Skip to content

fix(issue create): resolve --type before creating the issue - #14727

Open
umairnaeem0309 wants to merge 1 commit into
cli:trunkfrom
umairnaeem0309:fix/issue-create-resolve-type-before-create
Open

umairnaeem0309 wants to merge 1 commit into
cli:trunkfrom
umairnaeem0309:fix/issue-create-resolve-type-before-create

Conversation

@umairnaeem0309

@umairnaeem0309 umairnaeem0309 commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

Fixes #14703.

gh issue create --type <name> resolved the type name only after api.IssueCreate had run. On a repository that has no issue types (all user-owned repositories, where repository.issueTypes is null) or with a misspelled name, the issue was created and then the command exited 1 without printing its URL, so scripts retried and filed duplicates.

This resolves --type before the mutation:

// Resolve --type before creating the issue. An unknown type used to be
// reported only after api.IssueCreate had run, so the issue existed but
// its URL was never printed and the command exited 1, which made
// automation retry and file duplicates. Nothing here depends on the new
// issue, and the interactive flow already holds the selected ID.
if opts.IssueType != "" && opts.issueTypeID == "" {
	opts.issueTypeID, err = issueShared.ResolveIssueTypeName(apiClient, baseRepo, opts.IssueType)
	if err != nil {
		return
	}
}

Notes on the shape of the fix:

  • It is placed in createRun immediately before api.IssueCreate, in the SubmitAction branch, so the preview/--web paths are untouched.
  • The opts.issueTypeID == "" guard means the interactive flow keeps reusing the ID it already resolved at the prompt (create.go:377), so no duplicate RepositoryIssueTypes query is introduced.
  • deferredUpdateIssueOptions still resolves --type as a fallback for callers that arrive without a resolved ID; its comment now says so.

I took the first of the two options in the issue ("Resolve --type before api.IssueCreate") rather than printing the URL and warning, because the unknown-type case is a user error that should have no side effects at all, and #13899 already covers the deferred-mutation error path for permission failures.

Tests

Test_createRun/create_with_type_not_found previously stubbed mutation IssueCreate before query RepositoryIssueTypes, which pinned the reported ordering. That stub is now gone:

// No IssueCreate stub: an unresolvable type must fail before the
// mutation, otherwise the issue exists but its URL is never printed
// and automation retries, filing duplicates.

The case still expects type "Bugz" not found; available types: Bug, Feature, Task, and the registry's Verify still requires the types query to have run. With the stub absent, any attempt to create the issue fails the test instead of passing silently — which is exactly the property the issue asks for.

Verification

go build ./...                              exit 0
go vet ./pkg/cmd/issue/create/              exit 0
gofmt -l pkg/cmd/issue/create/              no output
go test ./pkg/cmd/issue/...                 all 23 packages ok
go test ./pkg/cmd/issue/create/             ok
golangci-lint run ./pkg/cmd/issue/create/...    0 issues (v2.14.0, the version pinned in .github/golangci-lint-version)

Mutation check: flipping the new guard off (if false && …) makes Test_createRun/create_with_type_not_found fail, because IssueCreate is then attempted and no stub matches:

Error: Error message not equal:
  expected: "type \"Bugz\" not found; available types: Bug, Feature, Task"
  actual  : "Post https://api.github.com/graphql: no registered HTTP stubs matched …mutation IssueCreate…"

So the test genuinely detects the reported behaviour, rather than merely passing.

Out of scope, same class, happy to follow up

--parent, --blocked-by and --blocking are still resolved after api.IssueCreate in deferredUpdateIssueOptions, so an unresolvable reference there has the same "issue created, URL not printed, exit 1" shape. I kept this PR to --type so the change stays reviewable and each of those flags can get its own test; say the word and I will follow up with the same treatment for all three.

gh issue create --type <name> resolved the type name only after
api.IssueCreate had run. On a repository without issue types, or with a
misspelled name, the issue was created and then the command exited 1
without printing its URL, so scripts and agents retried and filed
duplicates.

Resolve the name before the mutation. The lookup needs nothing from the new
issue, and the interactive flow already carries the selected ID, so the
query only happens when --type was passed.

Signed-off-by: Umair Naeem <154259455+umairnaeem0309@users.noreply.github.com>
@umairnaeem0309
umairnaeem0309 requested a review from a team as a code owner October 17, 2026 15:21
@umairnaeem0309
umairnaeem0309 requested review from tidy-dev and a balanced review from Copilot and removed request for Copilot October 17, 2026 15:21
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed ready-for-review and removed needs-triage needs to be reviewed labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

TorresVisual added a commit to TorresVisual/null-ide that referenced this pull request Oct 18, 2026
Fork PR head reads through the base repo (verified on cli/cli#14727), so the fork-PR limit is dropped from the spec.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

@ywsfnra-boopasdf123 ywsfnra-boopasdf123 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// No IssueCreate stub: an unresolvable type must fail before the
// mutation, otherwise the issue exists but its URL is never printed
// and automation retries, filing duplicates.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh issue create --type creates the issue, then exits 1 with type "X" not found without printing its URL (causes duplicates on retry)

2 participants