This commit is contained in:
ollie-anthropic
2025-08-27 14:57:36 -07:00
committed by Ashwin Bhat
parent 7bd5b28434
commit 2ef669b4c0
3 changed files with 19 additions and 17 deletions

View File

@@ -122,7 +122,6 @@ runs:
# Install Claude Code # Install Claude Code
bun install -g @anthropic-ai/claude-code bun install -g @anthropic-ai/claude-code
- name: Run Claude Code Action - name: Run Claude Code Action
shell: bash shell: bash
id: run_claude id: run_claude

View File

@@ -7,7 +7,10 @@ import * as core from "@actions/core";
import type { GitHubContext } from "../../github/context"; import type { GitHubContext } from "../../github/context";
import type { Octokits } from "../../github/api/client"; import type { Octokits } from "../../github/api/client";
import type { ResumeResponse, ResumeResult } from "../../types/resume"; import type { ResumeResponse, ResumeResult } from "../../types/resume";
import { setupBranch as setupBaseBranch, type BranchInfo } from "../../github/operations/branch"; import {
setupBranch as setupBaseBranch,
type BranchInfo,
} from "../../github/operations/branch";
export type RemoteBranchInfo = BranchInfo & { export type RemoteBranchInfo = BranchInfo & {
resumeMessages?: ResumeResult["messages"]; resumeMessages?: ResumeResult["messages"];
@@ -25,7 +28,7 @@ async function fetchResumeData(
): Promise<ResumeResult | null> { ): Promise<ResumeResult | null> {
try { try {
console.log(`Attempting to resume from: ${resumeEndpoint}`); console.log(`Attempting to resume from: ${resumeEndpoint}`);
const response = await fetch(resumeEndpoint, { const response = await fetch(resumeEndpoint, {
method: "GET", method: "GET",
headers: headers || {}, headers: headers || {},
@@ -39,7 +42,7 @@ async function fetchResumeData(
} }
const data = (await response.json()) as ResumeResponse; const data = (await response.json()) as ResumeResponse;
if (!data.log || !Array.isArray(data.log)) { if (!data.log || !Array.isArray(data.log)) {
console.log("Resume endpoint returned invalid data structure"); console.log("Resume endpoint returned invalid data structure");
return null; return null;
@@ -48,11 +51,11 @@ async function fetchResumeData(
console.log( console.log(
`Successfully fetched resume data with ${data.log.length} messages`, `Successfully fetched resume data with ${data.log.length} messages`,
); );
// If a branch is specified in the response, we'll use it // If a branch is specified in the response, we'll use it
// Otherwise, we'll determine the branch from the current git state // Otherwise, we'll determine the branch from the current git state
const branchName = data.branch || ""; const branchName = data.branch || "";
return { return {
messages: data.log, messages: data.log,
branchName, branchName,
@@ -81,31 +84,31 @@ export async function setupBranchWithResume(
// Check if we have a resume endpoint // Check if we have a resume endpoint
if (context.progressTracking?.resumeEndpoint) { if (context.progressTracking?.resumeEndpoint) {
console.log("Resume endpoint detected, attempting to resume session..."); console.log("Resume endpoint detected, attempting to resume session...");
// Prepare headers with OIDC token // Prepare headers with OIDC token
const headers: Record<string, string> = { const headers: Record<string, string> = {
...(context.progressTracking.headers || {}), ...(context.progressTracking.headers || {}),
Authorization: `Bearer ${oidcToken}`, Authorization: `Bearer ${oidcToken}`,
}; };
const resumeData = await fetchResumeData( const resumeData = await fetchResumeData(
context.progressTracking.resumeEndpoint, context.progressTracking.resumeEndpoint,
headers, headers,
); );
if (resumeData && resumeData.branchName) { if (resumeData && resumeData.branchName) {
// Try to checkout the resumed branch // Try to checkout the resumed branch
try { try {
console.log(`Resuming on branch: ${resumeData.branchName}`); console.log(`Resuming on branch: ${resumeData.branchName}`);
// Fetch the branch from origin // Fetch the branch from origin
await $`git fetch origin ${resumeData.branchName}`; await $`git fetch origin ${resumeData.branchName}`;
// Checkout the branch // Checkout the branch
await $`git checkout ${resumeData.branchName}`; await $`git checkout ${resumeData.branchName}`;
console.log(`Successfully resumed on branch: ${resumeData.branchName}`); console.log(`Successfully resumed on branch: ${resumeData.branchName}`);
// Get the base branch for this branch (we'll use the default branch as fallback) // Get the base branch for this branch (we'll use the default branch as fallback)
let resumeBaseBranch = baseBranch; let resumeBaseBranch = baseBranch;
if (!resumeBaseBranch) { if (!resumeBaseBranch) {
@@ -115,11 +118,11 @@ export async function setupBranchWithResume(
}); });
resumeBaseBranch = repoResponse.data.default_branch; resumeBaseBranch = repoResponse.data.default_branch;
} }
// Set outputs for GitHub Actions // Set outputs for GitHub Actions
core.setOutput("CLAUDE_BRANCH", resumeData.branchName); core.setOutput("CLAUDE_BRANCH", resumeData.branchName);
core.setOutput("BASE_BRANCH", resumeBaseBranch); core.setOutput("BASE_BRANCH", resumeBaseBranch);
return { return {
baseBranch: resumeBaseBranch, baseBranch: resumeBaseBranch,
claudeBranch: resumeData.branchName, claudeBranch: resumeData.branchName,
@@ -151,4 +154,4 @@ export async function setupBranchWithResume(
// No resume endpoint or resume failed, use normal branch setup // No resume endpoint or resume failed, use normal branch setup
console.log("No resume endpoint or resume failed, creating new branch..."); console.log("No resume endpoint or resume failed, creating new branch...");
return setupBaseBranch(octokits, null, context); return setupBaseBranch(octokits, null, context);
} }

View File

@@ -26,4 +26,4 @@ export type ResumeResponse = {
export type ResumeResult = { export type ResumeResult = {
messages: ResumeMessage[]; messages: ResumeMessage[];
branchName: string; branchName: string;
}; };