chore: format gitea branch

This commit is contained in:
Mark Wylde
2026-07-26 21:26:22 +01:00
parent c30a6c8c23
commit 40b8061da5
11 changed files with 455 additions and 442 deletions

View File

@@ -55,7 +55,7 @@ jobs:
## Inputs ## Inputs
| Input | Description | Required | Default | | Input | Description | Required | Default |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------- | | ------------------------- | ------------------------------------------------------------------------------------------------------------------- | -------- | ---------------------- |
| `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex) | No\* | - | | `anthropic_api_key` | Anthropic API key (required for direct API, not needed for Bedrock/Vertex) | No\* | - |
| `claude_code_oauth_token` | Claude Code OAuth token (alternative to anthropic_api_key) | No | - | | `claude_code_oauth_token` | Claude Code OAuth token (alternative to anthropic_api_key) | No | - |
| `direct_prompt` | Direct prompt for Claude to execute automatically without needing a trigger (for automated workflows) | No | - | | `direct_prompt` | Direct prompt for Claude to execute automatically without needing a trigger (for automated workflows) | No | - |
@@ -102,6 +102,7 @@ When running Gitea in containers, the action may generate links using internal c
``` ```
**How it works:** **How it works:**
- The action first checks for `GITEA_SERVER_URL` (user-configurable) - The action first checks for `GITEA_SERVER_URL` (user-configurable)
- Falls back to `GITHUB_SERVER_URL` (automatically set by Gitea Actions) - Falls back to `GITHUB_SERVER_URL` (automatically set by Gitea Actions)
- Uses `https://github.com` as final fallback - Uses `https://github.com` as final fallback
@@ -570,9 +571,11 @@ You can authenticate with Claude using any of these methods:
If you have access to [Claude Code](https://claude.ai/code), you can use OAuth authentication instead of an API key: If you have access to [Claude Code](https://claude.ai/code), you can use OAuth authentication instead of an API key:
1. **Generate OAuth Token**: run the following command and follow instructions: 1. **Generate OAuth Token**: run the following command and follow instructions:
``` ```
claude setup-token claude setup-token
``` ```
This will generate an OAuth token that you can use for authentication. This will generate an OAuth token that you can use for authentication.
2. **Add Token to Repository**: Add the generated token as a repository secret named `CLAUDE_CODE_OAUTH_TOKEN`. 2. **Add Token to Repository**: Add the generated token as a repository secret named `CLAUDE_CODE_OAUTH_TOKEN`.

View File

@@ -189,7 +189,6 @@ runs:
echo "$CLAUDE_DIR" >> "$GITHUB_PATH" echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
fi fi
# TODO pass claude_code_executable as input and use it here # TODO pass claude_code_executable as input and use it here
- name: Run Claude Code - name: Run Claude Code
id: claude-code id: claude-code
if: steps.prepare.outputs.contains_trigger == 'true' if: steps.prepare.outputs.contains_trigger == 'true'

View File

@@ -27,7 +27,10 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
} }
// Check for assignee trigger // Check for assignee trigger
if (isIssuesEvent(context) && (context.eventAction === "assigned" || context.eventAction === "opened")) { if (
isIssuesEvent(context) &&
(context.eventAction === "assigned" || context.eventAction === "opened")
) {
// Remove @ symbol from assignee_trigger if present // Remove @ symbol from assignee_trigger if present
let triggerUser = assigneeTrigger?.replace(/^@/, "") || ""; let triggerUser = assigneeTrigger?.replace(/^@/, "") || "";
const assigneeUsername = context.payload.issue.assignee?.login || ""; const assigneeUsername = context.payload.issue.assignee?.login || "";

View File

@@ -97,7 +97,9 @@ describe("checkAndDeleteEmptyBranch", () => {
}); });
test("falls back to branch link when API call fails", async () => { test("falls back to branch link when API call fails", async () => {
const client = createMockClient({ error: Object.assign(new Error("boom"), { status: 500 }) }); const client = createMockClient({
error: Object.assign(new Error("boom"), { status: 500 }),
});
const result = await checkAndDeleteEmptyBranch( const result = await checkAndDeleteEmptyBranch(
client, client,
"owner", "owner",

View File

@@ -140,8 +140,7 @@ describe("updateCommentBody", () => {
it("removes old branch links from body", () => { it("removes old branch links from body", () => {
const input = { const input = {
...baseInput, ...baseInput,
currentBody: currentBody: `Some comment with [View branch](${BRANCH_BASE_URL}/branch-name)`,
`Some comment with [View branch](${BRANCH_BASE_URL}/branch-name)` ,
branchName: "new-branch-name", branchName: "new-branch-name",
}; };

View File

@@ -63,21 +63,33 @@ describe("GITEA_SERVER_URL configuration", () => {
process.env.GITEA_SERVER_URL = "https://gitea.example.com"; process.env.GITEA_SERVER_URL = "https://gitea.example.com";
// Clear module cache and re-import // Clear module cache and re-import
delete require.cache[require.resolve("../src/github/operations/comments/common")]; delete require.cache[
const { createJobRunLink } = await import("../src/github/operations/comments/common"); require.resolve("../src/github/operations/comments/common")
];
const { createJobRunLink } = await import(
"../src/github/operations/comments/common"
);
const link = createJobRunLink("owner", "repo", "123"); const link = createJobRunLink("owner", "repo", "123");
expect(link).toBe("[View job run](https://gitea.example.com/owner/repo/actions/runs/123)"); expect(link).toBe(
"[View job run](https://gitea.example.com/owner/repo/actions/runs/123)",
);
}); });
it("should create correct branch links with custom GITEA_SERVER_URL", async () => { it("should create correct branch links with custom GITEA_SERVER_URL", async () => {
process.env.GITEA_SERVER_URL = "https://gitea.example.com"; process.env.GITEA_SERVER_URL = "https://gitea.example.com";
// Clear module cache and re-import // Clear module cache and re-import
delete require.cache[require.resolve("../src/github/operations/comments/common")]; delete require.cache[
const { createBranchLink } = await import("../src/github/operations/comments/common"); require.resolve("../src/github/operations/comments/common")
];
const { createBranchLink } = await import(
"../src/github/operations/comments/common"
);
const link = createBranchLink("owner", "repo", "feature-branch"); const link = createBranchLink("owner", "repo", "feature-branch");
expect(link).toBe("\n[View branch](https://gitea.example.com/owner/repo/src/branch/feature-branch/)"); expect(link).toBe(
"\n[View branch](https://gitea.example.com/owner/repo/src/branch/feature-branch/)",
);
}); });
}); });

View File

@@ -40,7 +40,12 @@ describe("downloadCommentImages", () => {
}, },
]; ];
const result = await downloadCommentImages(noopClient, "owner", "repo", comments); const result = await downloadCommentImages(
noopClient,
"owner",
"repo",
comments,
);
expect(result.size).toBe(0); expect(result.size).toBe(0);
expect(consoleLogSpy).toHaveBeenCalled(); expect(consoleLogSpy).toHaveBeenCalled();

View File

@@ -52,7 +52,9 @@ describe("checkWritePermissions", () => {
}); });
test("returns true immediately in Gitea environments", async () => { test("returns true immediately in Gitea environments", async () => {
const client = { api: { getBaseUrl: () => "https://gitea.example.com/api/v1" } } as any; const client = {
api: { getBaseUrl: () => "https://gitea.example.com/api/v1" },
} as any;
const result = await checkWritePermissions(client, baseContext); const result = await checkWritePermissions(client, baseContext);
expect(result).toBe(true); expect(result).toBe(true);

View File

@@ -70,11 +70,7 @@ describe("parseEnvVarsWithContext", () => {
}); });
test("should allow missing CLAUDE_BRANCH and omit it from event data", () => { test("should allow missing CLAUDE_BRANCH and omit it from event data", () => {
const result = prepareContext( const result = prepareContext(mockIssueCommentContext, "12345", "main");
mockIssueCommentContext,
"12345",
"main",
);
if ( if (
result.eventData.eventName === "issue_comment" && result.eventData.eventName === "issue_comment" &&

View File

@@ -417,9 +417,7 @@ describe("checkContainsTrigger", () => {
body: "This PR fixes a bug", body: "This PR fixes a bug",
created_at: "2023-01-01T00:00:00Z", created_at: "2023-01-01T00:00:00Z",
user: { login: "testuser" }, user: { login: "testuser" },
requested_reviewers: [ requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
{ login: "claude", id: 1, type: "User" },
],
}, },
} as unknown as PullRequestEvent, } as unknown as PullRequestEvent,
inputs: { inputs: {
@@ -491,9 +489,7 @@ describe("checkContainsTrigger", () => {
body: "This PR fixes a bug", body: "This PR fixes a bug",
created_at: "2023-01-01T00:00:00Z", created_at: "2023-01-01T00:00:00Z",
user: { login: "testuser" }, user: { login: "testuser" },
requested_reviewers: [ requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
{ login: "claude", id: 1, type: "User" },
],
}, },
} as unknown as PullRequestEvent, } as unknown as PullRequestEvent,
inputs: { inputs: {
@@ -529,9 +525,7 @@ describe("checkContainsTrigger", () => {
body: "This PR fixes a bug", body: "This PR fixes a bug",
created_at: "2023-01-01T00:00:00Z", created_at: "2023-01-01T00:00:00Z",
user: { login: "testuser" }, user: { login: "testuser" },
requested_reviewers: [ requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
{ login: "claude", id: 1, type: "User" },
],
requested_teams: [], requested_teams: [],
}, },
} as unknown as PullRequestEvent, } as unknown as PullRequestEvent,
@@ -605,9 +599,7 @@ describe("checkContainsTrigger", () => {
body: "This PR fixes a bug", body: "This PR fixes a bug",
created_at: "2023-01-01T00:00:00Z", created_at: "2023-01-01T00:00:00Z",
user: { login: "testuser" }, user: { login: "testuser" },
requested_reviewers: [ requested_reviewers: [{ login: "claude", id: 1, type: "User" }],
{ login: "claude", id: 1, type: "User" },
],
requested_teams: [], requested_teams: [],
}, },
} as unknown as PullRequestEvent, } as unknown as PullRequestEvent,