cleanup GITEA_BOT_USERNAMES
This commit is contained in:
parent
f70d7d5217
commit
011bea4cdc
@ -3,4 +3,3 @@ export const GITHUB_API_URL =
|
|||||||
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(",")
|
|
||||||
@ -7,30 +7,25 @@
|
|||||||
|
|
||||||
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{
|
||||||
);
|
|
||||||
}
|
|
||||||
// For Gitea environments, skip the user type check if USE_GITEA_API is set
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch user information from GitHub API
|
// Fetch user information from GitHub API
|
||||||
const { data: userData } = await octokit.users.getByUsername({
|
const { data: userData } = await octokit.users.getByUsername({
|
||||||
username: githubContext.actor,
|
username: githubContext.actor,
|
||||||
});
|
});
|
||||||
|
|
||||||
const actorType = userData.type;
|
actorType = userData.type;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Actor type: ${actorType}`);
|
console.log(`Actor type: ${actorType}`);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user