From 6410e3359138b2dccffa21409f6ee747d3324db6 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Fri, 30 May 2025 20:17:34 +0100 Subject: [PATCH] Attempt to make this work --- MIGRATION.md | 4 ++++ src/github/data/fetcher.ts | 9 ++++--- src/github/validation/actor.ts | 43 +++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 3100d43..641e5a1 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -171,6 +171,10 @@ permissions: **Error**: "Failed to check permissions: HttpError: Bad credentials" **Solution**: This is normal in Gitea environments. The action automatically detects Gitea and bypasses GitHub-specific permission checks. +#### 1a. User Profile API Errors +**Error**: "Prepare step failed with error: Visit Project" or "GET /users/{username} - 404" +**Solution**: This occurs when Gitea's user profile API differs from GitHub's. The action automatically detects Gitea and skips user type validation. + #### 2. Limited Event Support Some GitHub Events may not be fully supported in Gitea. Use basic triggers: - `issue_comment` for comments diff --git a/src/github/data/fetcher.ts b/src/github/data/fetcher.ts index efeab47..a08470c 100644 --- a/src/github/data/fetcher.ts +++ b/src/github/data/fetcher.ts @@ -96,6 +96,7 @@ export async function fetchGitHubData({ })); } catch (error) { console.warn("Failed to fetch PR comments:", error); + comments = []; // Ensure we have an empty array } // Try to fetch files @@ -107,12 +108,13 @@ export async function fetchGitHubData({ }); changedFiles = filesResponse.data.map(file => ({ path: file.filename, - additions: file.additions, - deletions: file.deletions, - changeType: file.status, + additions: file.additions || 0, + deletions: file.deletions || 0, + changeType: file.status || "modified", })); } catch (error) { console.warn("Failed to fetch PR files:", error); + changedFiles = []; // Ensure we have an empty array } reviewData = { nodes: [] }; // Simplified for Gitea @@ -149,6 +151,7 @@ export async function fetchGitHubData({ })); } catch (error) { console.warn("Failed to fetch issue comments:", error); + comments = []; // Ensure we have an empty array } } } else { diff --git a/src/github/validation/actor.ts b/src/github/validation/actor.ts index c48764b..4d4c493 100644 --- a/src/github/validation/actor.ts +++ b/src/github/validation/actor.ts @@ -12,20 +12,35 @@ export async function checkHumanActor( octokit: Octokit, githubContext: ParsedGitHubContext, ) { - // 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}`); - - if (actorType !== "User") { - throw new Error( - `Workflow initiated by non-human actor: ${githubContext.actor} (type: ${actorType}).`, - ); + // Check if we're in a Gitea environment + const isGitea = process.env.GITHUB_API_URL && !process.env.GITHUB_API_URL.includes('api.github.com'); + + 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 { data: userData } = await octokit.users.getByUsername({ + username: githubContext.actor, + }); + + 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}`); + } }