Skip to content

gh issue artifact stack 5/11: Add delete - #14568

Open
BagToad wants to merge 2 commits into
bagtoad/artifact-viewfrom
bagtoad/artifact-delete
Open

BagToad wants to merge 2 commits into
bagtoad/artifact-viewfrom
bagtoad/artifact-delete

Conversation

@BagToad

@BagToad BagToad commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Part of the pull request stack tracked in #14563.

This adds gh issue artifact delete from #14527.

Description

Issue artifacts are Markdown documents and links attached to an issue. The previous pull requests added the gh issue artifact command group, list and view. This one adds delete, which deletes artifacts by number. A deleted artifact can't be restored, so in a terminal gh asks first:

$ gh issue artifact delete 142 2 5
! Deleted artifacts cannot be recovered.
? Delete artifacts 2 (OAuth callback plan) and 5 (Barista feedback notes) from monalisa/monas-cafe#142? Yes
✓ Deleted artifact 2 (OAuth callback plan) from monalisa/monas-cafe#142
✓ Deleted artifact 5 (Barista feedback notes) from monalisa/monas-cafe#142
  • One prompt names every artifact, and its default is No. Declining deletes nothing and exits 2, like other gh prompts.

  • --yes skips the prompt. Without a terminal, --yes is required, like gh label delete.

  • Without --yes, a number that can't be found stops the command before the prompt, with X Failed to delete artifact 9: Not Found and No artifacts were deleted.

  • With --yes, every number is attempted. Each artifact gets its own line, failures show the API's message, and any failure exits 1.

  • Piped, each artifact gets one line with five tab-separated columns: status, number, name, source and reason. delete has no source, so that column is empty:

    $ gh issue artifact delete 142 2 9 --yes | cat -t
    deleted^I2^IOAuth callback plan^I^I
    failed^I9^I^I^INot Found
    
  • Like list and view, it refuses pull requests after one lookup and GitHub Enterprise Server before any artifact request. Types gh doesn't know are deleted as usual.

The client gains Delete. The shared package gains the result lines, which the later commands in the stack reuse.

How did you test this change?

I recorded the built gh in bagtoad/issue-artifacts-demo, each case on a fresh issue and checked with gh issue artifact list: confirming the prompt, declining it, three artifacts with --yes, a missing number with --yes, piped output, --yes required without a terminal, and a missing number stopping the command before the prompt. It leaves out issue URL arguments, pull requests, GitHub Enterprise Server and types gh doesn't know.

recording.mp4

Open chapters and agent notes

Key points

  • No artifact URLs yet. [Design] gh issue artifact delete #14527 also names artifacts by their URLs. The API doesn't return artifact URLs yet, as discussed in RFC: gh issue artifact #14529, so delete takes an issue and numbers, and its help leaves URLs out. A later pull request in this stack will add them.

  • Every number is looked up first. The prompt and the result lines name each artifact, so deleteRun gets every artifact before deleting any:

    for _, number := range opts.ArtifactNumbers {
    	// The lookup gives the name, or the API's error
    	a, err := c.Get(repo, opts.IssueNumber, number)
    	...
    }
    
    if !opts.Confirmed {
    	// Without --yes, one failed lookup stops the command before the prompt
    	if slices.ContainsFunc(lookups, func(l lookup) bool { return l.err != nil }) {
    		...
    		fmt.Fprintln(opts.IO.ErrOut, "No artifacts were deleted.")
    		return cmdutil.SilentError
    	}
    	...
    	if !confirmed {
    		// Exits 2
    		return cmdutil.CancelError
    	}
    }

    With --yes, a number whose lookup fails gets a failed line, and gh sends no delete request for it. The other numbers are still deleted.

  • The result lines are shared. download, create and edit report each artifact the same way, so PrintSuccess and PrintFailure live in the shared package. In a terminal, successes go to stdout and failures to stderr, like gh issue edit with several issues. Piped, every line goes to stdout, like gh pr checks rows. The line already names the artifact, so its reason is only the API's message: Not Found, not HTTP 404: Not Found (<url>).

  • Streams around the prompt. The warning goes to stdout, before the prompt, like gh issue delete and gh issue comment --delete-last. No artifacts were deleted. goes to stderr, after the failed lines.

  • A repeated number isn't merged. Each argument gets one line, so delete 142 2 2 --yes deletes artifact 2, then reports Failed to delete artifact 2: Not Found.

Notes for reviewers

Start with the delete run function, which shows the order of the checks, the lookups, the prompt and the deletes. Then read the shared result lines. TestDeleteRun has a row for each rule, including a failed lookup before the prompt, a failed delete after a lookup, a type gh doesn't know and a repeated number.

One detail isn't in #14527:

  • [Design] gh issue artifact delete #14527 shows prompts for one and two artifacts. With three or more, delete separates them with commas, including one before "and", like gh's other lists: Delete artifacts 2 (OAuth callback plan), 3 (Staging OAuth runbook), and 5 (Barista feedback notes) from monalisa/monas-cafe#142?

Related issues:

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @BagToad will read and reply directly. Name the account.
  • An agent will draft replies and @BagToad will read them before they are posted.
  • Nobody has explicitly committed to replying.

Delete removes one artifact from an issue, for gh issue artifact delete.
The API can't restore a deleted artifact.
delete asks before deleting, since a deleted artifact can't be restored.
It looks up every number first, so the prompt names each artifact, and
without --yes a number that can't be found stops the command before
anything is deleted. --yes skips the prompt and is required when gh
can't prompt, like gh label delete.

Commands that act on several artifacts report one line per artifact.
The shared package gains those result lines, so each such command prints
the same terminal lines and the same five-column piped lines.
@BagToad
BagToad requested a review from a team as a code owner October 1, 2026 16:59
@BagToad
BagToad requested review from babakks and removed request for a team October 1, 2026 16:59
@BagToad
BagToad added this pull request to stack #14573 October 1, 2026 16:59
@BagToad BagToad changed the title gh issue artifact stack 5/10: Add delete gh issue artifact stack 5/11: Add delete Oct 2, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant