Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
4a1ec34c71
10 files changed
+656
-8
No files matched your search
@@ -68,7 +68,11 @@ async function main(): Promise<void> {
|
||||
const payload = workflowCallEventName
|
||||
? buildPayloadFromWorkflowCallEnv(workflowCallEventName)
|
||||
: readPayloadFromGitHubEventPath();
|
||||
const octokit = createGitHubClient();
|
||||
const repository = payload.repository;
|
||||
const octokit = await createGitHubClient({
|
||||
owner: repository.owner.login,
|
||||
repo: repository.name
|
||||
});
|
||||
const eventName = workflowCallEventName ?? process.env.GITHUB_EVENT_NAME;
|
||||
|
||||
if (!eventName) {
|
||||
|
||||
+13
-1
@@ -28,7 +28,16 @@ const envBoolean = z.preprocess((value) => {
|
||||
|
||||
const configSchema = z.object({
|
||||
port: z.coerce.number().int().positive().default(3000),
|
||||
githubToken: z.string().min(1),
|
||||
githubToken: optionalString,
|
||||
githubAppId: optionalString,
|
||||
githubAppPrivateKey: optionalString,
|
||||
githubAppInstallationId: z.preprocess((value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return value;
|
||||
}, z.coerce.number().int().positive().optional()),
|
||||
codexModel: optionalString.default("gpt-5.4"),
|
||||
codexReasoningEffort: z.preprocess((value) => {
|
||||
return value === "" ? undefined : value;
|
||||
@@ -46,6 +55,9 @@ const configSchema = z.object({
|
||||
export const config = configSchema.parse({
|
||||
port: process.env.PORT,
|
||||
githubToken: process.env.GITHUB_TOKEN,
|
||||
githubAppId: process.env.GITHUB_APP_ID,
|
||||
githubAppPrivateKey: process.env.GITHUB_APP_PRIVATE_KEY,
|
||||
githubAppInstallationId: process.env.GITHUB_APP_INSTALLATION_ID,
|
||||
codexModel: process.env.CODEX_MODEL,
|
||||
codexReasoningEffort: process.env.CODEX_REASONING_EFFORT,
|
||||
codexBaseUrl: process.env.CODEX_BASE_URL,
|
||||
|
||||
+72
-1
@@ -1,8 +1,79 @@
|
||||
import { createAppAuth } from "@octokit/auth-app";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { config } from "../config.js";
|
||||
import { logger } from "../logger.js";
|
||||
|
||||
export async function createGitHubClient(params?: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
}): Promise<Octokit> {
|
||||
if (config.githubAppId && config.githubAppPrivateKey) {
|
||||
try {
|
||||
const privateKey = normalizePrivateKey(config.githubAppPrivateKey);
|
||||
const auth = createAppAuth({
|
||||
appId: config.githubAppId,
|
||||
privateKey
|
||||
});
|
||||
|
||||
const installationId =
|
||||
config.githubAppInstallationId ??
|
||||
(params ? await resolveInstallationId(auth, params.owner, params.repo) : undefined);
|
||||
|
||||
if (!installationId) {
|
||||
throw new Error("GitHub App installation id is not configured and could not be resolved from the repository.");
|
||||
}
|
||||
|
||||
const installationAuthentication = await auth({
|
||||
type: "installation",
|
||||
installationId
|
||||
});
|
||||
|
||||
return new Octokit({
|
||||
auth: installationAuthentication.token
|
||||
});
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
{
|
||||
error,
|
||||
githubAppId: config.githubAppId,
|
||||
githubAppInstallationId: config.githubAppInstallationId,
|
||||
owner: params?.owner,
|
||||
repo: params?.repo
|
||||
},
|
||||
"Failed to create GitHub App installation client; falling back to GITHUB_TOKEN."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.githubToken) {
|
||||
throw new Error(
|
||||
"GitHub authentication is not configured. Provide GITHUB_TOKEN, or set GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY."
|
||||
);
|
||||
}
|
||||
|
||||
export function createGitHubClient(): Octokit {
|
||||
return new Octokit({
|
||||
auth: config.githubToken
|
||||
});
|
||||
}
|
||||
|
||||
function normalizePrivateKey(value: string): string {
|
||||
return value.includes("\\n") ? value.replace(/\\n/g, "\n") : value;
|
||||
}
|
||||
|
||||
async function resolveInstallationId(
|
||||
auth: ReturnType<typeof createAppAuth>,
|
||||
owner: string,
|
||||
repo: string
|
||||
): Promise<number | undefined> {
|
||||
const appAuthentication = await auth({ type: "app" });
|
||||
const appOctokit = new Octokit({
|
||||
auth: appAuthentication.token
|
||||
});
|
||||
|
||||
const { data } = await appOctokit.request("GET /repos/{owner}/{repo}/installation", {
|
||||
owner,
|
||||
repo
|
||||
});
|
||||
|
||||
return data.id;
|
||||
}
|
||||
@@ -385,7 +385,7 @@ async function maybeMergePullRequest(
|
||||
owner,
|
||||
repo,
|
||||
issue_number: pullNumber,
|
||||
body: `Lenient check passed, but this PR will not be merged until ${approvalRequirement} approves the current head commit.`
|
||||
body: `Lenient check passed, but this PR will not be merged until ${approvalRequirement} approves the current head commit.\n\nNext step: in the GitHub pull request UI, click "Review changes" and submit an "Approve" review. No extra command is needed.`
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user