mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-02-21 11:32:49 +08:00
feat: add mode-aware gitea prepare flow
This commit is contained in:
@@ -29,3 +29,7 @@ export const GITEA_SERVER_URL = getServerUrl();
|
||||
|
||||
export const GITEA_API_URL =
|
||||
process.env.GITEA_API_URL || deriveApiUrl(GITEA_SERVER_URL);
|
||||
|
||||
// Backwards-compatible aliases for legacy GitHub-specific naming
|
||||
export const GITHUB_SERVER_URL = GITEA_SERVER_URL;
|
||||
export const GITHUB_API_URL = GITEA_API_URL;
|
||||
|
||||
@@ -141,14 +141,16 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
|
||||
if (branchLink) {
|
||||
// Extract the branch URL from the link
|
||||
const urlMatch = branchLink.match(/\((https:\/\/.*)\)/);
|
||||
const urlMatch = branchLink.match(/\((https?:\/\/[^\)]+)\)/);
|
||||
if (urlMatch && urlMatch[1]) {
|
||||
branchUrl = urlMatch[1];
|
||||
}
|
||||
|
||||
// Extract branch name from link if not provided
|
||||
if (!finalBranchName) {
|
||||
const branchNameMatch = branchLink.match(/tree\/([^"'\)]+)/);
|
||||
const branchNameMatch = branchLink.match(
|
||||
/(?:tree|src\/branch)\/([^"'\)\s]+)/,
|
||||
);
|
||||
if (branchNameMatch) {
|
||||
finalBranchName = branchNameMatch[1];
|
||||
}
|
||||
@@ -157,10 +159,17 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
|
||||
// If we don't have a URL yet but have a branch name, construct it
|
||||
if (!branchUrl && finalBranchName) {
|
||||
// Extract owner/repo from jobUrl
|
||||
const repoMatch = jobUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\//);
|
||||
if (repoMatch) {
|
||||
branchUrl = `${GITEA_SERVER_URL}/${repoMatch[1]}/${repoMatch[2]}/src/branch/${finalBranchName}`;
|
||||
try {
|
||||
const parsedJobUrl = new URL(jobUrl);
|
||||
const segments = parsedJobUrl.pathname
|
||||
.split("/")
|
||||
.filter((segment) => segment);
|
||||
const [owner, repo] = segments;
|
||||
if (owner && repo) {
|
||||
branchUrl = `${GITEA_SERVER_URL}/${owner}/${repo}/src/branch/${finalBranchName}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to derive branch URL from job URL: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { GITEA_SERVER_URL } from "../../api/config";
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
function getSpinnerHtml(): string {
|
||||
return `<img src="https://raw.githubusercontent.com/markwylde/claude-code-gitea-action/refs/heads/gitea/assets/spinner.gif" width="14px" height="14px" style="vertical-align: middle; margin-left: 4px;" />`;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import { $ } from "bun";
|
||||
import type { ParsedGitHubContext } from "../context";
|
||||
import { GITHUB_SERVER_URL } from "../api/config";
|
||||
import { GITEA_SERVER_URL } from "../api/config";
|
||||
|
||||
type GitUser = {
|
||||
login: string;
|
||||
@@ -22,7 +22,7 @@ export async function configureGitAuth(
|
||||
console.log("Configuring git authentication for non-signing mode");
|
||||
|
||||
// Determine the noreply email domain based on GITHUB_SERVER_URL
|
||||
const serverUrl = new URL(GITHUB_SERVER_URL);
|
||||
const serverUrl = new URL(GITEA_SERVER_URL);
|
||||
const noreplyDomain =
|
||||
serverUrl.hostname === "github.com"
|
||||
? "users.noreply.github.com"
|
||||
@@ -46,7 +46,7 @@ export async function configureGitAuth(
|
||||
// Remove the authorization header that actions/checkout sets
|
||||
console.log("Removing existing git authentication headers...");
|
||||
try {
|
||||
await $`git config --unset-all http.${GITHUB_SERVER_URL}/.extraheader`;
|
||||
await $`git config --unset-all http.${GITEA_SERVER_URL}/.extraheader`;
|
||||
console.log("✓ Removed existing authentication headers");
|
||||
} catch (e) {
|
||||
console.log("No existing authentication headers to remove");
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
isPullRequestReviewEvent,
|
||||
isPullRequestReviewCommentEvent,
|
||||
} from "../context";
|
||||
import type { IssuesLabeledEvent } from "@octokit/webhooks-types";
|
||||
import type { ParsedGitHubContext } from "../context";
|
||||
|
||||
export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
@@ -41,6 +42,26 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for issue label trigger
|
||||
if (isIssuesEvent(context) && context.eventAction === "labeled") {
|
||||
const triggerLabel = context.inputs.labelTrigger?.trim();
|
||||
const appliedLabel = (context.payload as IssuesLabeledEvent).label?.name
|
||||
?.trim();
|
||||
|
||||
console.log(
|
||||
`Checking label trigger: expected='${triggerLabel}', applied='${appliedLabel}'`,
|
||||
);
|
||||
|
||||
if (
|
||||
triggerLabel &&
|
||||
appliedLabel &&
|
||||
triggerLabel.localeCompare(appliedLabel, undefined, { sensitivity: "accent" }) === 0
|
||||
) {
|
||||
console.log(`Issue labeled with trigger label '${triggerLabel}'`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for issue body and title trigger on issue creation
|
||||
if (isIssuesEvent(context) && context.eventAction === "opened") {
|
||||
const issueBody = context.payload.issue.body || "";
|
||||
|
||||
Reference in New Issue
Block a user