fix(release): download Markdown upload assets through the API
Problem
glab release download fails with 404 Not Found on a private project, while the same link downloads fine in a browser. The issue has been open since 2022 and was reported again in #8136 (closed).
glab release create stores an uploaded file as a project Markdown upload. The link it saves is a web route:
/-/project/<project_id>/uploads/<secret>/<filename>Only a browser session authenticates that route. glab release download sends the token instead, so GitLab redirects the request to the sign-in page, which answers 404 for a private project.
This follows the root cause and the fix that @phikai proposed in the issue.
What this changes
downloadAsset now recognizes a same-host Markdown upload link and reads the file through the project Markdown uploads API, which accepts the token:
GET /projects/:id/uploads/:secret/:filenameBoth link shapes are handled, because GitLab changed the format in 17.0:
| Link | Source |
|---|---|
/-/project/<id>/uploads/<secret>/<file> |
GitLab 17.0 and later |
/<namespace>/<project>/uploads/<secret>/<file> |
earlier versions |
An instance served from a subfolder is handled too, since the prefix comes from the client base URL.
Every other link keeps its existing download path. That covers package registry assets, release evidence, source archives, and links on another host.
Testing
Test_downloadAsset_MarkdownUpload_UsesUploadsAPI reproduces the report. The test server answers 404 on the web route and serves the file on the API route, which is how a private project behaves.
With the three-line fix removed, the test fails with the reported symptom:
--- FAIL: Test_downloadAsset_MarkdownUpload_UsesUploadsAPI
Error: Received unexpected error: 404 Not FoundWith the fix it passes, and the assertions confirm the API route was used and the web route was never requested.
Test_parseMarkdownUploadRef covers nine cases: both link shapes, a subgroup, a subfolder install, an escaped file name, and four links that must not be rewritten.
go test ./internal/commands/release/download/... -count=1 -race # ok
go build ./... # ok
gofmt -l <changed files> # no outputTwo notes on my local run, both present on a clean main checkout and unrelated to this change:
internal/commands/release/createfailsTestReleaseCreate_ExperimentalNotes/when_experimental_notes_points_to_existing_file.internal/commands/auth/dockerfails withoperating system "windows" is not supported.
What I could not verify
I have no self-managed instance, so I did not reproduce the original 404 against a live GitLab. The test reproduces the behavior the issue describes, and the API route matches the one the documentation specifies. The uploads API needs GitLab 17.4 or later, as noted in the issue.
Closes #1301 (closed)