Forgejo-patched claude-code-gitea-action (View-job URL uses per-repo run index)
Some checks failed
Test Custom Executables / test-custom-executables (push) Has been cancelled
CI / test (push) Has been cancelled
CI / prettier (push) Has been cancelled
CI / typecheck (push) Has been cancelled
Sync Base Action to claude-code-base-action / Sync base-action to claude-code-base-action repository (push) Has been cancelled
Test Claude Code Action / test-inline-prompt (push) Has been cancelled
Test Claude Code Action / test-prompt-file (push) Has been cancelled
Test Claude Env Feature / test-claude-env-with-comments (push) Has been cancelled
Test MCP Servers / test-mcp-integration (push) Has been cancelled
Test MCP Servers / test-mcp-config-flag (push) Has been cancelled
Test Settings Feature / test-settings-inline-allow (push) Has been cancelled
Test Settings Feature / test-settings-inline-deny (push) Has been cancelled
Test Settings Feature / test-settings-file-allow (push) Has been cancelled
Test Settings Feature / test-settings-file-deny (push) Has been cancelled
Some checks failed
Test Custom Executables / test-custom-executables (push) Has been cancelled
CI / test (push) Has been cancelled
CI / prettier (push) Has been cancelled
CI / typecheck (push) Has been cancelled
Sync Base Action to claude-code-base-action / Sync base-action to claude-code-base-action repository (push) Has been cancelled
Test Claude Code Action / test-inline-prompt (push) Has been cancelled
Test Claude Code Action / test-prompt-file (push) Has been cancelled
Test Claude Env Feature / test-claude-env-with-comments (push) Has been cancelled
Test MCP Servers / test-mcp-integration (push) Has been cancelled
Test MCP Servers / test-mcp-config-flag (push) Has been cancelled
Test Settings Feature / test-settings-inline-allow (push) Has been cancelled
Test Settings Feature / test-settings-inline-deny (push) Has been cancelled
Test Settings Feature / test-settings-file-allow (push) Has been cancelled
Test Settings Feature / test-settings-file-deny (push) Has been cancelled
Fork of markwylde/claude-code-gitea-action@b744372 (v1.0.21) with the 'View job' link fixed to use GITHUB_RUN_NUMBER (per-repo index) instead of GITHUB_RUN_ID (global id), because Forgejo routes run pages by per-repo index. See VENDOR.txt.
This commit is contained in:
commit
32685a740f
151 changed files with 23555 additions and 0 deletions
121
test/branch-cleanup.test.ts
Normal file
121
test/branch-cleanup.test.ts
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import { describe, test, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||
import { checkAndDeleteEmptyBranch } from "../src/github/operations/branch-cleanup";
|
||||
import type { GitHubClient } from "../src/github/api/client";
|
||||
import { GITEA_SERVER_URL } from "../src/github/api/config";
|
||||
|
||||
describe("checkAndDeleteEmptyBranch", () => {
|
||||
let consoleLogSpy: any;
|
||||
let consoleErrorSpy: any;
|
||||
const originalEnv = { ...process.env };
|
||||
|
||||
beforeEach(() => {
|
||||
consoleLogSpy = spyOn(console, "log").mockImplementation(() => {});
|
||||
consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {});
|
||||
delete process.env.GITEA_API_URL; // ensure GitHub mode for predictable behaviour
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
consoleLogSpy.mockRestore();
|
||||
consoleErrorSpy.mockRestore();
|
||||
process.env = { ...originalEnv };
|
||||
});
|
||||
|
||||
const createMockClient = (
|
||||
options: { branchSha?: string; baseSha?: string; error?: Error } = {},
|
||||
): GitHubClient => {
|
||||
const { branchSha = "branch-sha", baseSha = "base-sha", error } = options;
|
||||
return {
|
||||
api: {
|
||||
getBranch: async (_owner: string, _repo: string, branch: string) => {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return {
|
||||
data: {
|
||||
commit: {
|
||||
sha: branch.includes("claude/") ? branchSha : baseSha,
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
} as unknown as GitHubClient;
|
||||
};
|
||||
|
||||
test("returns defaults when no claude branch provided", async () => {
|
||||
const client = createMockClient();
|
||||
const result = await checkAndDeleteEmptyBranch(
|
||||
client,
|
||||
"owner",
|
||||
"repo",
|
||||
undefined,
|
||||
"main",
|
||||
);
|
||||
|
||||
expect(result.shouldDeleteBranch).toBe(false);
|
||||
expect(result.branchLink).toBe("");
|
||||
expect(consoleLogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("marks branch for deletion when SHAs match", async () => {
|
||||
const client = createMockClient({ branchSha: "same", baseSha: "same" });
|
||||
const result = await checkAndDeleteEmptyBranch(
|
||||
client,
|
||||
"owner",
|
||||
"repo",
|
||||
"claude/issue-123",
|
||||
"main",
|
||||
);
|
||||
|
||||
expect(result.shouldDeleteBranch).toBe(true);
|
||||
expect(result.branchLink).toBe("");
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
"Branch claude/issue-123 has same SHA as base, marking for deletion",
|
||||
);
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
"Skipping branch deletion - not reliably supported across all Git platforms: claude/issue-123",
|
||||
);
|
||||
});
|
||||
|
||||
test("returns branch link when branch has commits", async () => {
|
||||
const client = createMockClient({ branchSha: "feature", baseSha: "main" });
|
||||
const result = await checkAndDeleteEmptyBranch(
|
||||
client,
|
||||
"owner",
|
||||
"repo",
|
||||
"claude/issue-123",
|
||||
"main",
|
||||
);
|
||||
|
||||
expect(result.shouldDeleteBranch).toBe(false);
|
||||
expect(result.branchLink).toBe(
|
||||
`\n[View branch](${GITEA_SERVER_URL}/owner/repo/src/branch/claude/issue-123)`,
|
||||
);
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
"Branch claude/issue-123 appears to have commits (different SHA from base)",
|
||||
);
|
||||
});
|
||||
|
||||
test("falls back to branch link when API call fails", async () => {
|
||||
const client = createMockClient({ error: Object.assign(new Error("boom"), { status: 500 }) });
|
||||
const result = await checkAndDeleteEmptyBranch(
|
||||
client,
|
||||
"owner",
|
||||
"repo",
|
||||
"claude/issue-123",
|
||||
"main",
|
||||
);
|
||||
|
||||
expect(result.shouldDeleteBranch).toBe(false);
|
||||
expect(result.branchLink).toBe(
|
||||
`\n[View branch](${GITEA_SERVER_URL}/owner/repo/src/branch/claude/issue-123)`,
|
||||
);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
||||
"Error checking branch:",
|
||||
expect.any(Error),
|
||||
);
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||
"Assuming branch exists due to non-404 error",
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue