--attach stack 4/8: Upload an asset to GitHub - #14180
Merged
Merged
Conversation
--attach stack 4/8: Upload an asset to GitHub
BagToad
marked this pull request as ready for review
August 18, 2026 05:56
Contributor
There was a problem hiding this comment.
Pull request overview
Adds infrastructure for uploading validated attachments to GitHub’s user-attachment endpoint.
Changes:
- Adds upload-host derivation for GitHub.com and GHE tenants.
- Adds credential, host, repository, and permission validation.
- Implements uploads, response handling, and tests.
Show a summary per file
| File | Description |
|---|---|
internal/ghinstance/host.go |
Builds attachment upload URLs. |
internal/ghinstance/host_test.go |
Tests upload-host derivation. |
internal/attachments/client.go |
Implements uploader validation and requests. |
internal/attachments/client_test.go |
Tests uploads, validation, and failures. |
Review details
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
Closed
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
BagToad
force-pushed
the
bagtoad/attach-upload
branch
from
August 18, 2026 14:55
c01bcd5 to
7dddd61
Compare
Closed
9 tasks
babakks
approved these changes
Aug 20, 2026
babakks
left a comment
Member
There was a problem hiding this comment.
Thanks for this one, @BagToad! 🙏
Solid, well-tested addition. The validation ordering in NewUploader is thoughtfully justified in the doc comments, the allowlist checks are clean, and the status-aware uploadError messages do a nice job translating the endpoint's quirks (like the 404-for-no-write-access case) into something actionable. The test coverage is thorough too.
A few themes in my comments, none blocking:
- Future integration with #14104: the new
DoRequestmethod there means we can likely drop the hand-built request and the go-ghTODOdown the line. Worth a couple of pointers in the code so the follow-up is easy to find. - Test ergonomics: an
os.Openindirection (mirroringlookupEnvFuncelsewhere) would lettestAssetstub the reader and skip real temp files. - Small polish: an optional
429branch for rate limits, a clearer stand-in for the intentionalWRTIEtypo, a couple of comments that reference far-away table rows, and some error-message nitpicks.
Nothing here needs to hold up the stack. Nice work! 🚀
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the pull request stack tracked in #14186.
Description
This is the fourth layer of the stack. It adds the uploader that posts a file to GitHub's user attachments endpoint and returns the asset URL, plus a small helper that builds the upload host for a given GitHub host. Nothing here is reachable from a command yet.
Three refusals happen before any request is made, in this order:
The host is checked first on purpose. On an enterprise server no token and no permission would ever make an upload work, so any other order would name a fault the user cannot fix.
How did you test this change?
The whole stack was built and files were uploaded to a private test repository from two accounts. One had write access and every upload succeeded. One had read only access, and every command refused before any request left the machine, which was confirmed by counting the requests rather than by trusting the message.
The upload host was also checked against a GitHub Enterprise Cloud tenant host, where it derives from the target host correctly.
Key points
The uploader never stores the token. It is told what kind of credential is active and nothing more, and the credential actually sent is chosen by the transport from the request host, like all
ghrequests.The upload host is derived from the target host, so a tenant with data residency uploads to its own host rather than to github.com.
Refusing early matters more here than in most places, because an upload cannot be undone.
Notes for reviewers
Read the three refusals first, and the reason the host is checked before the rest.
A note in the code explains why the request is built by hand rather than through the usual REST client. The endpoint requires both a content type and a content length on every request, and the shared client sets neither.
Authorship and follow-up
Who wrote this:
Who answers review comments: