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.
96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { $ } from "bun";
|
|
|
|
/**
|
|
* Check if a branch exists locally using git commands
|
|
*/
|
|
export async function branchExists(branchName: string): Promise<boolean> {
|
|
try {
|
|
await $`git show-ref --verify --quiet refs/heads/${branchName}`;
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a remote branch exists using git commands
|
|
*/
|
|
export async function remoteBranchExists(branchName: string): Promise<boolean> {
|
|
try {
|
|
await $`git show-ref --verify --quiet refs/remotes/origin/${branchName}`;
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the SHA of a branch using git commands
|
|
*/
|
|
export async function getBranchSha(branchName: string): Promise<string | null> {
|
|
try {
|
|
// Try local branch first
|
|
if (await branchExists(branchName)) {
|
|
const result = await $`git rev-parse refs/heads/${branchName}`;
|
|
return result.text().trim();
|
|
}
|
|
|
|
// Try remote branch if local doesn't exist
|
|
if (await remoteBranchExists(branchName)) {
|
|
const result = await $`git rev-parse refs/remotes/origin/${branchName}`;
|
|
return result.text().trim();
|
|
}
|
|
|
|
return null;
|
|
} catch (error) {
|
|
console.error(`Error getting SHA for branch ${branchName}:`, error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if a branch has commits different from base branch
|
|
*/
|
|
export async function branchHasChanges(
|
|
branchName: string,
|
|
baseBranch: string,
|
|
): Promise<{
|
|
hasChanges: boolean;
|
|
branchSha: string | null;
|
|
baseSha: string | null;
|
|
}> {
|
|
try {
|
|
const branchSha = await getBranchSha(branchName);
|
|
const baseSha = await getBranchSha(baseBranch);
|
|
|
|
if (!branchSha || !baseSha) {
|
|
return { hasChanges: false, branchSha, baseSha };
|
|
}
|
|
|
|
const hasChanges = branchSha !== baseSha;
|
|
return { hasChanges, branchSha, baseSha };
|
|
} catch (error) {
|
|
console.error(
|
|
`Error comparing branches ${branchName} and ${baseBranch}:`,
|
|
error,
|
|
);
|
|
return { hasChanges: false, branchSha: null, baseSha: null };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fetch latest changes from remote to ensure we have up-to-date branch info
|
|
*/
|
|
export async function fetchBranch(branchName: string): Promise<boolean> {
|
|
try {
|
|
await $`git fetch origin --depth=1 ${branchName}`;
|
|
return true;
|
|
} catch (error) {
|
|
console.log(
|
|
`Could not fetch branch ${branchName} from remote (may not exist yet)`,
|
|
);
|
|
return false;
|
|
}
|
|
}
|