Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
favna opened this issue Mar 17, 2024 · 3 comments
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@favna
Copy link

favna commented Mar 17, 2024

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
@favna favna added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Mar 17, 2024
Copy link

👋 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! 🚀

@wolfy1339
Copy link
Member

Can you share a code example

@favna
Copy link
Author

favna commented Mar 17, 2024

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);
});

@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

3 participants