mirror of
https://github.com/markwylde/claude-code-gitea-action.git
synced 2026-08-01 11:12:59 +08:00
chore: format gitea branch
This commit is contained in:
@@ -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`.
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|||||||
@@ -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 || "";
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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/)",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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" &&
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -700,9 +692,9 @@ describe("checkContainsTrigger", () => {
|
|||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(false);
|
expect(checkContainsTrigger(context)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("comment trigger", () => {
|
describe("comment trigger", () => {
|
||||||
it("should return true for issue_comment with trigger phrase", () => {
|
it("should return true for issue_comment with trigger phrase", () => {
|
||||||
const context = mockIssueCommentContext;
|
const context = mockIssueCommentContext;
|
||||||
expect(checkContainsTrigger(context)).toBe(true);
|
expect(checkContainsTrigger(context)).toBe(true);
|
||||||
@@ -810,9 +802,9 @@ describe("checkContainsTrigger", () => {
|
|||||||
expect(checkContainsTrigger(context)).toBe(expected);
|
expect(checkContainsTrigger(context)).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("pull request review_requested action", () => {
|
describe("pull request review_requested action", () => {
|
||||||
it("should return true when trigger user is requested as reviewer", () => {
|
it("should return true when trigger user is requested as reviewer", () => {
|
||||||
const context = createMockContext({
|
const context = createMockContext({
|
||||||
eventName: "pull_request",
|
eventName: "pull_request",
|
||||||
@@ -923,9 +915,9 @@ describe("checkContainsTrigger", () => {
|
|||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(true);
|
expect(checkContainsTrigger(context)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("non-matching events", () => {
|
describe("non-matching events", () => {
|
||||||
it("should return false for non-matching event type", () => {
|
it("should return false for non-matching event type", () => {
|
||||||
const context = createMockContext({
|
const context = createMockContext({
|
||||||
eventName: "push",
|
eventName: "push",
|
||||||
@@ -934,7 +926,7 @@ describe("checkContainsTrigger", () => {
|
|||||||
});
|
});
|
||||||
expect(checkContainsTrigger(context)).toBe(false);
|
expect(checkContainsTrigger(context)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("escapeRegExp", () => {
|
describe("escapeRegExp", () => {
|
||||||
it("should escape special regex characters", () => {
|
it("should escape special regex characters", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user