This commit is contained in:
Mark Wylde
2025-05-30 20:02:39 +01:00
parent 180a1b6680
commit fb6df649ed
33 changed files with 4709 additions and 901 deletions
+40 -14
View File
@@ -5,27 +5,53 @@
* Prevents automated tools or bots from triggering Claude
*/
import type { Octokit } from "@octokit/rest";
import type { GiteaApiClient } from "../api/gitea-client";
import type { ParsedGitHubContext } from "../context";
export async function checkHumanActor(
octokit: Octokit,
api: GiteaApiClient,
githubContext: ParsedGitHubContext,
) {
// Fetch user information from GitHub API
const { data: userData } = await octokit.users.getByUsername({
username: githubContext.actor,
});
// Check if we're in a Gitea environment
const isGitea =
process.env.GITEA_API_URL &&
!process.env.GITEA_API_URL.includes("api.github.com");
const actorType = userData.type;
console.log(`Actor type: ${actorType}`);
if (actorType !== "User") {
throw new Error(
`Workflow initiated by non-human actor: ${githubContext.actor} (type: ${actorType}).`,
if (isGitea) {
console.log(
`Detected Gitea environment, skipping actor type validation for: ${githubContext.actor}`,
);
return;
}
console.log(`Verified human actor: ${githubContext.actor}`);
try {
// Fetch user information from GitHub API
const response = await api.customRequest(
"GET",
`/api/v1/users/${githubContext.actor}`,
);
const userData = response.data;
const actorType = userData.type;
console.log(`Actor type: ${actorType}`);
if (actorType !== "User") {
throw new Error(
`Workflow initiated by non-human actor: ${githubContext.actor} (type: ${actorType}).`,
);
}
console.log(`Verified human actor: ${githubContext.actor}`);
} catch (error) {
console.warn(
`Failed to check actor type for ${githubContext.actor}:`,
error,
);
// For compatibility, assume human actor if API call fails
console.log(
`Assuming human actor due to API failure: ${githubContext.actor}`,
);
}
}