Skip to content

Commit 4df380c

Browse files
author
Tulga Tsogtgerel
committed
comment_id is no longer necessary
1 parent ee29987 commit 4df380c

File tree

3 files changed

+74
-49
lines changed

3 files changed

+74
-49
lines changed

action.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ inputs:
99
github_token:
1010
description: 'GitHub token for API access'
1111
required: true
12-
comment_id:
13-
description: 'The ID of the comment to react to'
14-
required: true
1512
event_name:
16-
description: 'The GitHub event name (pull_request_review_comment or issue_comment)'
13+
description: 'The GitHub event name (pull_request, pull_request_review_comment, or issue_comment)'
1714
required: true
1815
prompt:
1916
description: 'The prompt to send to Auggie agent'
@@ -57,7 +54,6 @@ runs:
5754
shell: bash
5855
env:
5956
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
60-
INPUT_COMMENT_ID: ${{ inputs.comment_id }}
6157
INPUT_EVENT_NAME: ${{ inputs.event_name }}
6258
INPUT_PROMPT: ${{ inputs.prompt }}
6359
INPUT_AUGMENT_API_KEY: ${{ inputs.augment_api_key }}

src/index.ts

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,66 @@
22
import * as core from "@actions/core";
33
import { Octokit } from "@octokit/rest";
44
import { runAuggie } from "./auggie";
5-
import { getInput, parseRepository, reactToComment } from "./utils";
5+
import {
6+
getCommentIdFromEvent,
7+
getInput,
8+
parseRepository,
9+
reactToComment,
10+
} from "./utils";
611

712
/**
813
* Main function
914
*/
1015
async function main(): Promise<void> {
11-
try {
12-
const githubToken = getInput("github_token", true);
13-
const commentIdStr = getInput("comment_id", true);
14-
const eventName = getInput("event_name", true);
15-
const prompt = getInput("prompt", true);
16-
const augmentApiKey = getInput("augment_api_key");
17-
const augmentApiUrl = getInput("augment_api_url");
18-
const workspaceRoot = getInput("workspace_root");
16+
const githubToken = getInput("github_token", true);
17+
const eventName = getInput("event_name", true);
18+
const prompt = getInput("prompt", true);
19+
const augmentApiKey = getInput("augment_api_key");
20+
const augmentApiUrl = getInput("augment_api_url");
21+
const workspaceRoot = getInput("workspace_root");
1922

20-
// Validate comment ID
21-
const commentId = Number.parseInt(commentIdStr, 10);
22-
if (Number.isNaN(commentId)) {
23-
throw new Error(`Invalid comment_id: ${commentIdStr}. Must be a number.`);
24-
}
23+
const { owner, repo } = parseRepository();
2524

26-
const { owner, repo } = parseRepository();
25+
// Create Octokit instance
26+
const octokit = new Octokit({ auth: githubToken });
2727

28-
// Create Octokit instance
29-
const octokit = new Octokit({ auth: githubToken });
28+
// Extract comment_id from GitHub event payload
29+
const commentId = getCommentIdFromEvent();
3030

31-
// React to the comment to acknowledge receipt
32-
await reactToComment({ octokit, owner, repo, commentId, eventName });
31+
// React to the comment to acknowledge receipt (only for comment events)
32+
if (commentId) {
33+
core.info(`📝 Found comment ID ${commentId} from event payload`);
34+
await reactToComment({ octokit, owner, repo, commentId, eventName });
35+
} else {
36+
core.info(
37+
`ℹ️ No comment found in event payload, skipping comment reaction (event: ${eventName})`,
38+
);
39+
}
3340

34-
// Log GITHUB_STEP_SUMMARY availability
35-
const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;
36-
if (stepSummaryPath) {
37-
core.info(`📊 GITHUB_STEP_SUMMARY available at: ${stepSummaryPath}`);
38-
} else {
39-
core.warning("⚠️ GITHUB_STEP_SUMMARY not available");
40-
}
41+
// Log GITHUB_STEP_SUMMARY availability
42+
const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;
43+
if (stepSummaryPath) {
44+
core.info(`📊 GITHUB_STEP_SUMMARY available at: ${stepSummaryPath}`);
45+
} else {
46+
core.warning("⚠️ GITHUB_STEP_SUMMARY not available");
47+
}
4148

42-
// Run Auggie agent with the prompt
43-
core.info("🚀 Running Auggie agent...");
44-
await runAuggie({
45-
userPrompt: prompt,
46-
apiKey: augmentApiKey,
47-
apiUrl: augmentApiUrl,
48-
workspaceRoot: workspaceRoot || undefined,
49-
githubToken,
50-
});
49+
// Run Auggie agent with the prompt
50+
core.info("🚀 Running Auggie agent...");
51+
await runAuggie({
52+
userPrompt: prompt,
53+
apiKey: augmentApiKey,
54+
apiUrl: augmentApiUrl,
55+
workspaceRoot: workspaceRoot || undefined,
56+
githubToken,
57+
});
5158

52-
core.info("✅ Auggie agent completed successfully");
53-
core.setOutput("success", "true");
54-
} catch (error) {
55-
const errorMessage = error instanceof Error ? error.message : String(error);
56-
core.setFailed(errorMessage);
57-
core.setOutput("success", "false");
58-
}
59+
core.info("✅ Auggie agent completed successfully");
60+
core.setOutput("success", "true");
5961
}
6062

6163
// Run the action
6264
main().catch((error) => {
63-
const errorMessage = error instanceof Error ? error.message : String(error);
64-
core.setFailed(`Unexpected error: ${errorMessage}`);
65+
const errorMessage = error instanceof Error ? error.message : String(error);
66+
core.setFailed(`Unexpected error: ${errorMessage}`);
6567
});

src/utils/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from "@actions/core";
2+
import { readFileSync } from "node:fs";
23
import type { Octokit } from "@octokit/rest";
34

45
/**
@@ -15,6 +16,32 @@ export function getInput(name: string, required = false): string {
1516
return value.trim();
1617
}
1718

19+
/**
20+
* Extract comment ID from GitHub event payload
21+
* Returns undefined if the event doesn't have a comment
22+
*/
23+
export function getCommentIdFromEvent(): number | undefined {
24+
const eventPath = process.env.GITHUB_EVENT_PATH;
25+
if (!eventPath) {
26+
core.warning("GITHUB_EVENT_PATH not found");
27+
return undefined;
28+
}
29+
30+
try {
31+
const eventData = JSON.parse(readFileSync(eventPath, "utf8"));
32+
33+
// Check if event has a comment object
34+
if (eventData.comment?.id) {
35+
return eventData.comment.id;
36+
}
37+
38+
return undefined;
39+
} catch (error) {
40+
core.warning(`Failed to read event payload: ${error}`);
41+
return undefined;
42+
}
43+
}
44+
1845
/**
1946
* Parse repository owner and name from GITHUB_REPOSITORY
2047
*/

0 commit comments

Comments
 (0)