octokit/app.js

[BUG]: Requesting workflow logs returns a 403 but still has the correct redirect URL in the response

favna opened this issue · 3 comments

What happened?

I noticed that when requesting the job logs with GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logs using @octokit/app a 403 error is thrown, even though when logging the response in a catch block the URL is returned anyway. I used this as logs: https://github.com/sapphiredev/sapphiredev/blob/a7fa7bc367c04d88b6115437703010086b7cd2dc/src/processGitHubWebhookRequest.ts#L161-L176

Versions

  • @octokit/app: 14.0.2
  • @octokit/plugin-rest-endpoint-methods: 11.0.1
  • @octokit/plugin-retry: 7.0.3
  • NodeJS: Cloudflare Workers compatibility date 2023-07-01 with node_compat true

Relevant log output

(log) publishJobId= 22756401703
  (log) an error occurred when fetching the logs
  (error) error= HttpError: Unknown error: {}
  (error) error message= Unknown error: {}
  (error) error cause= null
  (error) error stack= HttpError: Unknown error: {}
    at index.js:2686:21
    at async sendRequestWithRetries (index.js:5750:16)
    at async requestWithGraphqlErrorHandling (index.js:11360:20)
    at async Job.doExecute (index.js:7264:22)
  (log) is instanceof RequestError
  (error) error status= 403
  (error) error request= {
  method: 'GET',
  url: 'https://api.github.com/repos/sapphiredev/framework/actions/jobs/22756401703/logs',
  headers: {
    accept: 'application/vnd.github+json',
    'user-agent': 'Sapphire Deployer/ (@octokit/core) (https://github.com/sapphiredev/sapphiredev/tree/main) Sapphire Deployer/ (@octokit/core) (https://github.com/sapphiredev/sapphiredev/tree/main) octokit-core.js/5.1.0 Cloudflare-Workers',
    'x-github-api-version': '2022-11-28',
    'x-github-delivery': '286bdcb0-e478-11ee-9fcd-a64f31adf246',
    authorization: 'token [REDACTED]'
  },
  request: {}
}
  (error) error response= {
  url: 'https://productionresultssa1.blob.core.windows.net/actions-results/[REDACTED]/workflow-job-run-[REDACTED]/logs/job/job-logs.txt?rsct=text%2Fplain&se=2024-03-17T16%3A15%3A23Z&sig=[REDACTED]&sp=r&spr=https&sr=b&st=2024-03-17T16%3A05%3A18Z&sv=2021-12-02',
  status: 403,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'Content-Length,Content-Type,Date,Server,x-ms-request-id',
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '865e396504f95950-IAD',
    connection: 'keep-alive',
    'content-length': '321',
    'content-type': 'application/xml',
    date: 'Sun, 17 Mar 2024 16:05:23 GMT',
    server: 'cloudflare',
    'x-ms-request-id': '8c971474-101e-00fa-0784-78c1fe000000'
  },
  data: {}
}

Code of Conduct

  • I agree to follow this project's Code of Conduct

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

Can you share a code example

Can you share a code example

I linked to a GitHub repo with a code example but sure I guess...

import { App } from '@octokit/app';

const jobId = 1; // INSERT REAL GITHUB ACTION JOB ID HERE

const app = new App({
	appId: 123,
	privateKey: '-----BEGIN PRIVATE KEY-----\n...',
	webhooks: {
		secret: 'secret'
	}
});

app.webhooks.on('workflow_run.completed', async ({ octokit }) => {
	// This will throw as mentioned
	const jobLogsData = await octokit.request('GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logs', {
		owner: 'octokit',
		repo: 'app.js',
		job_id: jobId,
		headers: {
			'X-GitHub-Api-Version': '2022-11-28',
			Accept: 'application/vnd.github+json'
		}
	});

	console.log(jobLogsData.url);
});