chore: pull in latest

This commit is contained in:
Mark Wylde
2025-09-26 22:34:52 +01:00
12 changed files with 281 additions and 443 deletions
-63
View File
@@ -1,63 +0,0 @@
import { mkdir, writeFile } from "fs/promises";
import { join } from "path";
import { homedir } from "os";
interface OAuthCredentials {
accessToken: string;
refreshToken: string;
expiresAt: string;
}
interface ClaudeCredentialsInput {
claudeAiOauth: {
accessToken: string;
refreshToken: string;
expiresAt: number;
scopes: string[];
};
}
export async function setupOAuthCredentials(credentialsJson: string) {
try {
// Parse the credentials JSON
const parsedCredentials: ClaudeCredentialsInput =
JSON.parse(credentialsJson);
if (!parsedCredentials.claudeAiOauth) {
throw new Error("Invalid credentials format: missing claudeAiOauth");
}
const { accessToken, refreshToken, expiresAt } =
parsedCredentials.claudeAiOauth;
if (!accessToken || !refreshToken || !expiresAt) {
throw new Error(
"Invalid credentials format: missing required OAuth fields",
);
}
const claudeDir = join(homedir(), ".claude");
const credentialsPath = join(claudeDir, ".credentials.json");
// Create the .claude directory if it doesn't exist
await mkdir(claudeDir, { recursive: true });
// Create the credentials JSON structure
const credentialsData = {
claudeAiOauth: {
accessToken,
refreshToken,
expiresAt,
scopes: ["user:inference", "user:profile"],
},
};
// Write the credentials file
await writeFile(credentialsPath, JSON.stringify(credentialsData, null, 2));
console.log(`OAuth credentials written to ${credentialsPath}`);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to setup OAuth credentials: ${errorMessage}`);
}
}
+11 -23
View File
@@ -18,29 +18,17 @@ import { createPrompt } from "../create-prompt";
import { createClient } from "../github/api/client";
import { fetchGitHubData } from "../github/data/fetcher";
import { parseGitHubContext } from "../github/context";
import { setupOAuthCredentials } from "../claude/oauth-setup";
async function run() {
try {
// Step 1: Setup OAuth credentials if provided
const claudeCredentials = process.env.CLAUDE_CREDENTIALS;
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
if (claudeCredentials && anthropicApiKey === "use-oauth") {
await setupOAuthCredentials(claudeCredentials);
console.log(
"OAuth credentials configured for Claude AI Max subscription",
);
}
// Step 2: Setup GitHub token
// Step 1: Setup GitHub token
const githubToken = await setupGitHubToken();
const client = createClient(githubToken);
// Step 3: Parse GitHub context (once for all operations)
// Step 2: Parse GitHub context (once for all operations)
const context = parseGitHubContext();
// Step 4: Check write permissions
// Step 3: Check write permissions
const hasWritePermissions = await checkWritePermissions(
client.api,
context,
@@ -51,7 +39,7 @@ async function run() {
);
}
// Step 5: Check trigger conditions
// Step 4: Check trigger conditions
const containsTrigger = await checkTriggerAction(context);
// Set outputs that are always needed
@@ -63,14 +51,14 @@ async function run() {
return;
}
// Step 6: Check if actor is human
// Step 5: Check if actor is human
await checkHumanActor(client.api, context);
// Step 7: Create initial tracking comment
// Step 6: Create initial tracking comment
const commentId = await createInitialComment(client.api, context);
core.setOutput("claude_comment_id", commentId.toString());
// Step 8: Fetch GitHub data (once for both branch setup and prompt creation)
// Step 7: Fetch GitHub data (once for both branch setup and prompt creation)
const githubData = await fetchGitHubData({
client: client,
repository: `${context.repository.owner}/${context.repository.repo}`,
@@ -78,14 +66,14 @@ async function run() {
isPR: context.isPR,
});
// Step 9: Setup branch
// Step 8: Setup branch
const branchInfo = await setupBranch(client, githubData, context);
core.setOutput("BASE_BRANCH", branchInfo.baseBranch);
if (branchInfo.claudeBranch) {
core.setOutput("CLAUDE_BRANCH", branchInfo.claudeBranch);
}
// Step 10: Update initial comment with branch link (only if a claude branch was created)
// Step 9: Update initial comment with branch link (only if a claude branch was created)
if (branchInfo.claudeBranch) {
await updateTrackingComment(
client,
@@ -95,7 +83,7 @@ async function run() {
);
}
// Step 11: Create prompt file
// Step 10: Create prompt file
await createPrompt(
commentId,
branchInfo.baseBranch,
@@ -104,7 +92,7 @@ async function run() {
context,
);
// Step 12: Get MCP configuration
// Step 11: Get MCP configuration
const mcpConfig = await prepareMcpConfig(
githubToken,
context.repository.owner,
+19 -2
View File
@@ -7,8 +7,25 @@ function deriveApiUrl(serverUrl: string): string {
return `${serverUrl}/api/v1`;
}
export const GITEA_SERVER_URL =
process.env.GITHUB_SERVER_URL || "https://github.com";
// Get the appropriate server URL, prioritizing GITEA_SERVER_URL for custom Gitea instances
function getServerUrl(): string {
// First check for GITEA_SERVER_URL (can be set by user)
const giteaServerUrl = process.env.GITEA_SERVER_URL;
if (giteaServerUrl && giteaServerUrl !== "") {
return giteaServerUrl;
}
// Fall back to GITHUB_SERVER_URL (set by Gitea/GitHub Actions environment)
const githubServerUrl = process.env.GITHUB_SERVER_URL;
if (githubServerUrl && githubServerUrl !== "") {
return githubServerUrl;
}
// Default fallback
return "https://github.com";
}
export const GITEA_SERVER_URL = getServerUrl();
export const GITEA_API_URL =
process.env.GITEA_API_URL || deriveApiUrl(GITEA_SERVER_URL);
+2 -2
View File
@@ -52,7 +52,7 @@ export async function setupBranch(
);
// Check out the base branch and let Claude create branches as needed
await $`git fetch origin ${sourceBranch}`;
await $`git fetch origin --depth=1 ${sourceBranch}`;
await $`git checkout ${sourceBranch}`;
await $`git pull origin ${sourceBranch}`;
@@ -99,7 +99,7 @@ export async function setupBranch(
// Ensure we have the latest version of the source branch
console.log(`Fetching latest ${sourceBranch}...`);
await $`git fetch origin ${sourceBranch}`;
await $`git fetch origin --depth=1 ${sourceBranch}`;
// Checkout the source branch
console.log(`Checking out ${sourceBranch}...`);
+1 -1
View File
@@ -85,7 +85,7 @@ export async function branchHasChanges(
*/
export async function fetchBranch(branchName: string): Promise<boolean> {
try {
await $`git fetch origin ${branchName}`;
await $`git fetch origin --depth=1 ${branchName}`;
return true;
} catch (error) {
console.log(