Skip to content

Commit 3190c71

Browse files
Copilotdsyme
andcommitted
fix: generate correct URLs for assets in private repos
Use `https://github.com/{repo}/blob/{branch}/{filename}?raw=true` format instead of `https://raw.githubusercontent.com/{repo}/{branch}/{filename}` for github.com asset uploads. The blob URL with `?raw=true` works for both public and private repos, while the raw.githubusercontent.com URL only works for public repos. Fixes #<issue> Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
1 parent 5fb3a81 commit 3190c71

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

actions/setup/js/safe_outputs_handlers.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function createHandlers(server, appendSafeOutput, config = {}) {
166166
try {
167167
const serverHostname = new URL(githubServer).hostname;
168168
if (serverHostname === "github.com") {
169-
url = `https://raw.githubusercontent.com/${repo}/${normalizedBranchName}/${targetFileName}`;
169+
url = `https://github.com/${repo}/blob/${normalizedBranchName}/${targetFileName}?raw=true`;
170170
} else {
171171
// GitHub Enterprise Server - raw content is served from the same host with /raw/ path
172172
url = `${githubServer}/${repo}/raw/${normalizedBranchName}/${targetFileName}`;

actions/setup/js/safe_outputs_handlers.test.cjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe("safe_outputs_handlers", () => {
138138
});
139139

140140
describe("uploadAssetHandler", () => {
141-
it("should generate raw.githubusercontent.com URL for github.com", () => {
141+
it("should generate blob URL with raw=true for github.com", () => {
142142
process.env.GH_AW_ASSETS_BRANCH = "test-branch";
143143
process.env.GITHUB_SERVER_URL = "https://github.com";
144144
process.env.GITHUB_REPOSITORY = "myorg/myrepo";
@@ -149,8 +149,9 @@ describe("safe_outputs_handlers", () => {
149149
handlers.uploadAssetHandler({ path: testFile });
150150

151151
const entry = mockAppendSafeOutput.mock.calls[0][0];
152-
expect(entry.url).toContain("raw.githubusercontent.com");
153-
expect(entry.url).toContain("myorg/myrepo");
152+
expect(entry.url).toContain("github.com/myorg/myrepo/blob/test-branch");
153+
expect(entry.url).toContain("?raw=true");
154+
expect(entry.url).not.toContain("raw.githubusercontent.com");
154155
});
155156

156157
it("should generate enterprise URL for GitHub Enterprise Server", () => {

docs/src/content/docs/reference/safe-outputs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ Agent output format: `{"type": "update_release", "tag": "v1.0.0", "operation": "
884884

885885
### Asset Uploads (`upload-asset:`)
886886

887-
Uploads files (screenshots, charts, reports) to orphaned git branch with predictable URLs: `https://raw.githubusercontent.com/{owner}/{repo}/{branch}/{filename}`. Agent registers files via `upload_asset` tool; separate job with `contents: write` commits them.
887+
Uploads files (screenshots, charts, reports) to orphaned git branch with predictable URLs: `https://github.com/{owner}/{repo}/blob/{branch}/{filename}?raw=true`. Agent registers files via `upload_asset` tool; separate job with `contents: write` commits them.
888888

889889
```yaml wrap
890890
safe-outputs:

0 commit comments

Comments
 (0)