Skip to content

Commit d78ddfd

Browse files
committed
formatting
1 parent 255d102 commit d78ddfd

File tree

7 files changed

+167
-88
lines changed

7 files changed

+167
-88
lines changed

src/entrypoints/prepare.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,27 @@ async function run() {
5151
await checkHumanActor(octokit.rest, context);
5252

5353
// Step 6: Setup output manager and create initial tracking
54-
const outputModes = OutputManager.parseOutputModes(process.env.OUTPUT_MODE || "pr_comment");
54+
const outputModes = OutputManager.parseOutputModes(
55+
process.env.OUTPUT_MODE || "pr_comment",
56+
);
5557
const commitSha = process.env.COMMIT_SHA;
56-
const outputManager = new OutputManager(outputModes, octokit.rest, context, commitSha);
58+
const outputManager = new OutputManager(
59+
outputModes,
60+
octokit.rest,
61+
context,
62+
commitSha,
63+
);
5764
const outputIdentifiers = await outputManager.createInitial(context);
58-
65+
5966
// Output the identifiers for downstream steps
60-
core.setOutput("output_identifiers", outputManager.serializeIdentifiers(outputIdentifiers));
61-
67+
core.setOutput(
68+
"output_identifiers",
69+
outputManager.serializeIdentifiers(outputIdentifiers),
70+
);
71+
6272
// Legacy support: output the primary identifier as claude_comment_id
63-
const primaryIdentifier = outputManager.getPrimaryIdentifier(outputIdentifiers);
73+
const primaryIdentifier =
74+
outputManager.getPrimaryIdentifier(outputIdentifiers);
6475
if (primaryIdentifier) {
6576
core.setOutput("claude_comment_id", primaryIdentifier);
6677
}

src/entrypoints/update-comment-link.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@
22

33
import { createOctokit } from "../github/api/client";
44
import * as fs from "fs/promises";
5-
import {
6-
type ExecutionDetails,
7-
} from "../github/operations/comment-logic";
8-
import {
9-
parseGitHubContext,
10-
} from "../github/context";
5+
import { type ExecutionDetails } from "../github/operations/comment-logic";
6+
import { parseGitHubContext } from "../github/context";
117
import { GITHUB_SERVER_URL } from "../github/api/config";
128
import { checkAndDeleteEmptyBranch } from "../github/operations/branch-cleanup";
139
import { OutputManager, type OutputIdentifiers } from "../output-manager";
1410
import type { ReviewContent } from "../output-strategies/base";
1511

1612
async function run() {
1713
try {
18-
// Legacy fallback for claude_comment_id
14+
// Legacy fallback for claude_comment_id
1915
const legacyCommentId = process.env.CLAUDE_COMMENT_ID;
2016
const outputIdentifiersJson = process.env.OUTPUT_IDENTIFIERS;
2117
const githubToken = process.env.GITHUB_TOKEN!;
2218
const claudeBranch = process.env.CLAUDE_BRANCH;
2319
const baseBranch = process.env.BASE_BRANCH || "main";
2420
const triggerUsername = process.env.TRIGGER_USERNAME;
25-
const outputModes = OutputManager.parseOutputModes(process.env.OUTPUT_MODE || "pr_comment");
21+
const outputModes = OutputManager.parseOutputModes(
22+
process.env.OUTPUT_MODE || "pr_comment",
23+
);
2624
const commitSha = process.env.COMMIT_SHA;
2725

2826
const context = parseGitHubContext();
@@ -32,7 +30,9 @@ async function run() {
3230
// Parse output identifiers from prepare step or fall back to legacy
3331
let outputIdentifiers: OutputIdentifiers;
3432
if (outputIdentifiersJson) {
35-
outputIdentifiers = OutputManager.deserializeIdentifiers(outputIdentifiersJson);
33+
outputIdentifiers = OutputManager.deserializeIdentifiers(
34+
outputIdentifiersJson,
35+
);
3636
} else if (legacyCommentId) {
3737
// Legacy fallback - assume pr_comment mode
3838
outputIdentifiers = { pr_comment: legacyCommentId };
@@ -41,7 +41,12 @@ async function run() {
4141
}
4242

4343
// Create output manager for final update
44-
const outputManager = new OutputManager(outputModes, octokit.rest, context, commitSha);
44+
const outputManager = new OutputManager(
45+
outputModes,
46+
octokit.rest,
47+
context,
48+
commitSha,
49+
);
4550

4651
const serverUrl = GITHUB_SERVER_URL;
4752
const jobUrl = `${serverUrl}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
@@ -61,15 +66,20 @@ async function run() {
6166
currentBody = issueComment.body ?? "";
6267
} catch {
6368
// If issue comment fails, try PR review comment
64-
const { data: prComment } = await octokit.rest.pulls.getReviewComment({
65-
owner,
66-
repo,
67-
comment_id: commentId,
68-
});
69+
const { data: prComment } = await octokit.rest.pulls.getReviewComment(
70+
{
71+
owner,
72+
repo,
73+
comment_id: commentId,
74+
},
75+
);
6976
currentBody = prComment.body ?? "";
7077
}
7178
} catch (error) {
72-
console.warn("Could not fetch current comment body, proceeding with empty body:", error);
79+
console.warn(
80+
"Could not fetch current comment body, proceeding with empty body:",
81+
error,
82+
);
7383
}
7484
}
7585

src/output-manager.ts

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class OutputManager {
1818
outputModes: string[],
1919
octokit: Octokit | null,
2020
context: ParsedGitHubContext,
21-
commitSha?: string
21+
commitSha?: string,
2222
) {
2323
// Create and validate strategies based on output modes
2424
for (const mode of outputModes) {
@@ -28,47 +28,61 @@ export class OutputManager {
2828
switch (trimmedMode) {
2929
case "pr_comment":
3030
if (!octokit) {
31-
throw new Error("'pr_comment' output mode requires GitHub authentication (octokit instance)");
31+
throw new Error(
32+
"'pr_comment' output mode requires GitHub authentication (octokit instance)",
33+
);
3234
}
3335
strategy = new PrCommentStrategy(octokit);
3436
break;
3537
case "commit_comment":
3638
if (!octokit) {
37-
throw new Error("'commit_comment' output mode requires GitHub authentication (octokit instance)");
39+
throw new Error(
40+
"'commit_comment' output mode requires GitHub authentication (octokit instance)",
41+
);
3842
}
3943
strategy = new CommitCommentStrategy(octokit, commitSha);
4044
break;
4145
case "stdout":
4246
strategy = new StdoutStrategy();
4347
break;
4448
default:
45-
throw new Error(`Unknown output mode: ${trimmedMode}. Valid options: pr_comment, commit_comment, stdout`);
49+
throw new Error(
50+
`Unknown output mode: ${trimmedMode}. Valid options: pr_comment, commit_comment, stdout`,
51+
);
4652
}
4753

4854
// Validate the strategy can work in this context
4955
try {
5056
strategy.validate(context);
5157
this.strategies.push(strategy);
5258
} catch (error) {
53-
const errorMessage = error instanceof Error ? error.message : String(error);
54-
throw new Error(`Output mode '${trimmedMode}' validation failed: ${errorMessage}`);
59+
const errorMessage =
60+
error instanceof Error ? error.message : String(error);
61+
throw new Error(
62+
`Output mode '${trimmedMode}' validation failed: ${errorMessage}`,
63+
);
5564
}
5665
}
5766

5867
if (this.strategies.length === 0) {
5968
throw new Error("No valid output strategies configured");
6069
}
6170

62-
console.log(`📤 Configured output strategies: ${this.strategies.map(s => s.name).join(", ")}`);
71+
console.log(
72+
`📤 Configured output strategies: ${this.strategies.map((s) => s.name).join(", ")}`,
73+
);
6374
}
6475

6576
static parseOutputModes(outputModeInput: string): string[] {
6677
if (!outputModeInput || outputModeInput.trim() === "") {
6778
return ["pr_comment"]; // Default
6879
}
6980

70-
const modes = outputModeInput.split(",").map(mode => mode.trim()).filter(mode => mode.length > 0);
71-
81+
const modes = outputModeInput
82+
.split(",")
83+
.map((mode) => mode.trim())
84+
.filter((mode) => mode.length > 0);
85+
7286
if (modes.length === 0) {
7387
return ["pr_comment"]; // Default
7488
}
@@ -77,7 +91,9 @@ export class OutputManager {
7791
return [...new Set(modes)];
7892
}
7993

80-
async createInitial(context: ParsedGitHubContext): Promise<OutputIdentifiers> {
94+
async createInitial(
95+
context: ParsedGitHubContext,
96+
): Promise<OutputIdentifiers> {
8197
const identifiers: OutputIdentifiers = {};
8298
const errors: Error[] = [];
8399

@@ -86,8 +102,12 @@ export class OutputManager {
86102
const identifier = await strategy.createInitial(context);
87103
identifiers[strategy.name] = identifier;
88104
} catch (error) {
89-
console.error(`❌ Output strategy ${strategy.name} failed during createInitial:`, error);
90-
const errorObj = error instanceof Error ? error : new Error(String(error));
105+
console.error(
106+
`❌ Output strategy ${strategy.name} failed during createInitial:`,
107+
error,
108+
);
109+
const errorObj =
110+
error instanceof Error ? error : new Error(String(error));
91111
errors.push(errorObj);
92112
identifiers[strategy.name] = null;
93113
}
@@ -96,7 +116,9 @@ export class OutputManager {
96116
// If all strategies failed during initial creation, that's a problem
97117
if (errors.length === this.strategies.length) {
98118
const lastError = errors[errors.length - 1];
99-
throw new Error(`All output strategies failed during initial creation. Last error: ${lastError?.message || 'Unknown error'}`);
119+
throw new Error(
120+
`All output strategies failed during initial creation. Last error: ${lastError?.message || "Unknown error"}`,
121+
);
100122
}
101123

102124
return identifiers;
@@ -105,7 +127,7 @@ export class OutputManager {
105127
async updateFinal(
106128
identifiers: OutputIdentifiers,
107129
context: ParsedGitHubContext,
108-
content: ReviewContent
130+
content: ReviewContent,
109131
): Promise<void> {
110132
const errors: Error[] = [];
111133

@@ -114,20 +136,28 @@ export class OutputManager {
114136
const identifier = identifiers[strategy.name] || null;
115137
await strategy.updateFinal(identifier, context, content);
116138
} catch (error) {
117-
console.error(`❌ Output strategy ${strategy.name} failed during updateFinal:`, error);
118-
const errorObj = error instanceof Error ? error : new Error(String(error));
139+
console.error(
140+
`❌ Output strategy ${strategy.name} failed during updateFinal:`,
141+
error,
142+
);
143+
const errorObj =
144+
error instanceof Error ? error : new Error(String(error));
119145
errors.push(errorObj);
120146
}
121147
}
122148

123149
// If all strategies failed, throw an error to mark the action as failed
124150
if (errors.length === this.strategies.length) {
125-
throw new Error(`All ${this.strategies.length} output strategies failed. See logs for details.`);
151+
throw new Error(
152+
`All ${this.strategies.length} output strategies failed. See logs for details.`,
153+
);
126154
}
127155

128156
// If some strategies failed but others succeeded, log a warning
129157
if (errors.length > 0) {
130-
console.warn(`⚠️ ${errors.length} of ${this.strategies.length} output strategies failed, but action completed partially.`);
158+
console.warn(
159+
`⚠️ ${errors.length} of ${this.strategies.length} output strategies failed, but action completed partially.`,
160+
);
131161
}
132162
}
133163

@@ -169,8 +199,11 @@ export class OutputManager {
169199
try {
170200
return JSON.parse(serialized);
171201
} catch (error) {
172-
console.warn("Failed to parse identifiers JSON, treating as empty:", error);
202+
console.warn(
203+
"Failed to parse identifiers JSON, treating as empty:",
204+
error,
205+
);
173206
return {};
174207
}
175208
}
176-
}
209+
}

src/output-strategies/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface ReviewContent {
1818

1919
export interface OutputStrategy {
2020
readonly name: string;
21-
21+
2222
/**
2323
* Creates an initial placeholder/tracking entity if needed.
2424
* Returns an identifier (like a comment ID) for future updates.
@@ -31,11 +31,11 @@ export interface OutputStrategy {
3131
updateFinal(
3232
identifier: string | null,
3333
context: ParsedGitHubContext,
34-
content: ReviewContent
34+
content: ReviewContent,
3535
): Promise<void>;
3636

3737
/**
3838
* Validates if this strategy can be used in the given context.
3939
*/
4040
validate(context: ParsedGitHubContext): void;
41-
}
41+
}

0 commit comments

Comments
 (0)