cleanup GITEA_BOT_USERNAMES

This commit is contained in:
Anonymous 2026-01-30 08:22:13 +08:00
parent f70d7d5217
commit 011bea4cdc
2 changed files with 12 additions and 18 deletions

View File

@ -3,4 +3,3 @@ export const GITHUB_API_URL =
export const GITHUB_SERVER_URL =
process.env.GITHUB_SERVER_URL || "https://github.com";
export const USE_GITEA_API = process.env.USE_GITEA_API === "true" || process.env.USE_GITEA_API === "1";
export const GITEA_BOT_USERNAMES = (process.env.GITEA_BOT_USERNAMES || "").split(",")

View File

@ -7,31 +7,26 @@
import type { Octokit } from "@octokit/rest";
import type { GitHubContext } from "../context";
import { GITEA_BOT_USERNAMES, USE_GITEA_API } from "../api/config.ts";
import { USE_GITEA_API } from "../api/config.ts";
export async function checkHumanActor(
octokit: Octokit,
githubContext: GitHubContext,
) {
let actorType: string
if (USE_GITEA_API) {
if (!GITEA_BOT_USERNAMES.includes(githubContext.actor)) {
throw new Error(
`Workflow initiated by non-human actor: ${githubContext.actor}. Please add bot to GITEA_BOT_USERNAMES`,
);
}
// For Gitea environments, skip the user type check if USE_GITEA_API is set
return;
actorType = "Bot"
console.log("Gitea does not provide an API to determine whether a user is a bot. Assuming the user is a bot and verify whether it is listed in allowedBots.")
}else{
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
actorType = userData.type;
}
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
const actorType = userData.type;
console.log(`Actor type: ${actorType}`);
// Check bot permissions if actor is not a User