Handle outside approvals and scheduled fallback
This commit is contained in:
1 parent
6d14749626
commit
22ee162cbf
5 files changed
+212
-28
No files matched your search
@@ -6,6 +6,7 @@ import { withRetry } from "../retry.js";
|
||||
import {
|
||||
processLenientCheckComment,
|
||||
processPullRequest,
|
||||
processScheduledLenientMerges,
|
||||
processPullRequestReviewApproval
|
||||
} from "../review/processor.js";
|
||||
|
||||
@@ -58,6 +59,10 @@ type PullRequestReviewPayload = {
|
||||
repository: GitHubRepository;
|
||||
};
|
||||
|
||||
type ScheduledPayload = {
|
||||
repository: GitHubRepository;
|
||||
};
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const workflowCallEventName = process.env.GHBOT_EVENT_NAME;
|
||||
const payload = workflowCallEventName
|
||||
@@ -133,19 +138,28 @@ async function main(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventName === "schedule") {
|
||||
const scheduledPayload = payload as ScheduledPayload;
|
||||
await processScheduledLenientMerges(octokit, {
|
||||
owner: scheduledPayload.repository.owner.login,
|
||||
repo: scheduledPayload.repository.name
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn({ eventName }, "Unhandled GitHub Actions event.");
|
||||
}
|
||||
|
||||
function readPayloadFromGitHubEventPath(): PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload {
|
||||
function readPayloadFromGitHubEventPath(): PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload | ScheduledPayload {
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH;
|
||||
if (!eventPath) {
|
||||
throw new Error("GITHUB_EVENT_PATH is required when workflow_call inputs are not provided.");
|
||||
}
|
||||
|
||||
return JSON.parse(fs.readFileSync(eventPath, "utf8")) as PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload;
|
||||
return JSON.parse(fs.readFileSync(eventPath, "utf8")) as PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload | ScheduledPayload;
|
||||
}
|
||||
|
||||
function buildPayloadFromWorkflowCallEnv(eventName: string): PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload {
|
||||
function buildPayloadFromWorkflowCallEnv(eventName: string): PullRequestPayload | IssueCommentPayload | PullRequestReviewPayload | ScheduledPayload {
|
||||
const action = process.env.GHBOT_EVENT_ACTION;
|
||||
const owner = process.env.GHBOT_REPOSITORY_OWNER;
|
||||
const repo = process.env.GHBOT_REPOSITORY_NAME;
|
||||
@@ -210,6 +224,12 @@ function buildPayloadFromWorkflowCallEnv(eventName: string): PullRequestPayload
|
||||
};
|
||||
}
|
||||
|
||||
if (eventName === "schedule") {
|
||||
return {
|
||||
repository
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`Unsupported GHBOT_EVENT_NAME: ${eventName}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user