Files
spoon/apps/agent-worker/src/github.ts
T
Gabriel Brown 2dfa97ee4f
Build and Push Next App / quality (push) Failing after 48s
Build and Push Next App / build-next (push) Has been skipped
Add agent workflows & stuff
2026-06-21 21:15:15 -05:00

53 lines
1.2 KiB
TypeScript

import { createAppAuth } from '@octokit/auth-app';
import { Octokit } from '@octokit/rest';
import { env } from './env';
export const getInstallationToken = async (installationId: string) => {
const auth = createAppAuth({
appId: env.githubAppId,
privateKey: env.githubPrivateKey,
installationId,
});
const result = await auth({ type: 'installation' });
return result.token;
};
export const getInstallationOctokit = (installationId: string) =>
new Octokit({
authStrategy: createAppAuth,
auth: {
appId: env.githubAppId,
privateKey: env.githubPrivateKey,
installationId,
},
userAgent: 'Spoon Agent Worker',
request: {
headers: {
'X-GitHub-Api-Version': '2022-11-28',
},
},
});
export const openDraftPullRequest = async (args: {
installationId: string;
forkOwner: string;
forkRepo: string;
baseBranch: string;
workBranch: string;
title: string;
body: string;
}) => {
const octokit = getInstallationOctokit(args.installationId);
const result = await octokit.rest.pulls.create({
owner: args.forkOwner,
repo: args.forkRepo,
base: args.baseBranch,
head: args.workBranch,
title: args.title,
body: args.body,
draft: true,
});
return result.data;
};