Use action context logger in Octokit client

This will surface Octokit logs in the `OngoingTask` log stream.

For example, Octokit will now surface logs when GitHub API rate limits are hit. Previously these were only visible in the backend logs and did not use the structured Backstage logger.

Signed-off-by: Kevin Snyder <kevin.snyder@gusto.com>
This commit is contained in:
Kevin Snyder
2025-04-04 11:49:22 -07:00
parent c4c3b000f7
commit e784ba9de0
11 changed files with 76 additions and 48 deletions
@@ -242,7 +242,10 @@ export function createPublishGithubAction(options: {
owner,
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
const { remoteUrl, repoContentsUrl } = await ctx.checkpoint({
key: `create.github.repo.${owner}.${repo}`,
@@ -104,16 +104,18 @@ export function createGithubActionsDispatchAction(options: {
throw new InputError('Invalid repository owner provided in repoUrl');
}
const client = new Octokit(
await getOctokitOptions({
integrations,
host,
owner,
repo,
credentialsProvider: githubCredentialsProvider,
token: providedToken,
}),
);
const octokitOptions = await getOctokitOptions({
integrations,
host,
owner,
repo,
credentialsProvider: githubCredentialsProvider,
token: providedToken,
});
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
await ctx.checkpoint({
key: `create.workflow.dispatch.${owner}.${repo}.${workflowId}`,
@@ -97,16 +97,18 @@ export function createGithubAutolinksAction(options: {
throw new InputError('Invalid repository owner provided in repoUrl');
}
const client = new Octokit(
await getOctokitOptions({
integrations,
host,
owner,
repo,
credentialsProvider: githubCredentialsProvider,
token,
}),
);
const octokitOptions = await getOctokitOptions({
integrations,
host,
owner,
repo,
credentialsProvider: githubCredentialsProvider,
token,
});
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
await ctx.checkpoint({
key: `create.auto.link.${owner}.${repo}`,
@@ -128,7 +128,10 @@ export function createGithubBranchProtectionAction(options: {
owner,
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
const defaultBranch = await ctx.checkpoint({
key: `read.default.branch.${owner}.${repo}`,
@@ -124,7 +124,10 @@ export function createGithubDeployKeyAction(options: {
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
await client.rest.repos.createDeployKey({
owner: owner,
@@ -192,8 +192,10 @@ Wildcard characters will not match \`/\`. For example, to match tags that begin
owner,
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
const repositoryId = await ctx.checkpoint({
key: `get.repo.${owner}.${repo}`,
@@ -89,16 +89,18 @@ export function createGithubIssuesLabelAction(options: {
throw new InputError('Invalid repository owner provided in repoUrl');
}
const client = new Octokit(
await getOctokitOptions({
integrations,
credentialsProvider: githubCredentialsProvider,
host,
owner,
repo,
token: providedToken,
}),
);
const octokitOptions = await getOctokitOptions({
integrations,
credentialsProvider: githubCredentialsProvider,
host,
owner,
repo,
token: providedToken,
});
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
try {
await ctx.checkpoint({
@@ -112,7 +112,10 @@ export function createGithubPagesEnableAction(options: {
owner,
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
ctx.logger.info(
`Attempting to enable GitHub Pages for ${owner}/${repo} with "${buildType}" build type, on source branch "${sourceBranch}" and source path "${sourcePath}"`,
@@ -197,7 +197,10 @@ export function createGithubRepoCreateAction(options: {
owner,
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
const remoteUrl = await ctx.checkpoint({
key: `create.repo.and.topics.${owner}.${repo}`,
@@ -158,7 +158,10 @@ export function createGithubRepoPushAction(options: {
repo,
});
const client = new Octokit(octokitOptions);
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
const targetRepo = await client.rest.repos.get({ owner, repo });
@@ -149,16 +149,18 @@ export function createGithubWebhookAction(options: {
throw new InputError('Invalid repository owner provided in repoUrl');
}
const client = new Octokit(
await getOctokitOptions({
integrations,
credentialsProvider: githubCredentialsProvider,
host,
owner,
repo,
token: providedToken,
}),
);
const octokitOptions = await getOctokitOptions({
integrations,
credentialsProvider: githubCredentialsProvider,
host,
owner,
repo,
token: providedToken,
});
const client = new Octokit({
...octokitOptions,
log: ctx.logger,
});
// If this is a dry run, log and return
if (ctx.isDryRun) {