Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/github/validation/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@ export async function checkHumanActor(
octokit: Octokit,
githubContext: GitHubContext,
) {
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
let actorType: string;

const actorType = userData.type;
try {
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
actorType = userData.type;
} catch (error: any) {
if (error.status === 404) {
// Bot/app actors (e.g. github-merge-queue[bot]) can't be looked up
// via the Users API — treat as a bot and fall through to allowedBots check
console.log(
`Actor "${githubContext.actor}" not found via Users API (likely a bot/app), treating as Bot`,
);
actorType = "Bot";
} else {
throw error;
}
}

console.log(`Actor type: ${actorType}`);

Expand Down