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

@ -2,5 +2,4 @@ export const GITHUB_API_URL =
process.env.GITHUB_API_URL || "https://api.github.com"; process.env.GITHUB_API_URL || "https://api.github.com";
export const GITHUB_SERVER_URL = export const GITHUB_SERVER_URL =
process.env.GITHUB_SERVER_URL || "https://github.com"; 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 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 { Octokit } from "@octokit/rest";
import type { GitHubContext } from "../context"; 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( export async function checkHumanActor(
octokit: Octokit, octokit: Octokit,
githubContext: GitHubContext, githubContext: GitHubContext,
) { ) {
let actorType: string
if (USE_GITEA_API) { if (USE_GITEA_API) {
if (!GITEA_BOT_USERNAMES.includes(githubContext.actor)) { actorType = "Bot"
throw new Error( 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.")
`Workflow initiated by non-human actor: ${githubContext.actor}. Please add bot to GITEA_BOT_USERNAMES`, }else{
); // Fetch user information from GitHub API
} const { data: userData } = await octokit.users.getByUsername({
// For Gitea environments, skip the user type check if USE_GITEA_API is set username: githubContext.actor,
return; });
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}`); console.log(`Actor type: ${actorType}`);
// Check bot permissions if actor is not a User // Check bot permissions if actor is not a User