|
2 | 2 | import * as core from "@actions/core"; |
3 | 3 | import { Octokit } from "@octokit/rest"; |
4 | 4 | import { runAuggie } from "./auggie"; |
5 | | -import { getInput, parseRepository, reactToComment } from "./utils"; |
| 5 | +import { |
| 6 | + getCommentIdFromEvent, |
| 7 | + getInput, |
| 8 | + parseRepository, |
| 9 | + reactToComment, |
| 10 | +} from "./utils"; |
6 | 11 |
|
7 | 12 | /** |
8 | 13 | * Main function |
9 | 14 | */ |
10 | 15 | 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"); |
19 | 22 |
|
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(); |
25 | 24 |
|
26 | | - const { owner, repo } = parseRepository(); |
| 25 | + // Create Octokit instance |
| 26 | + const octokit = new Octokit({ auth: githubToken }); |
27 | 27 |
|
28 | | - // Create Octokit instance |
29 | | - const octokit = new Octokit({ auth: githubToken }); |
| 28 | + // Extract comment_id from GitHub event payload |
| 29 | + const commentId = getCommentIdFromEvent(); |
30 | 30 |
|
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 | + } |
33 | 40 |
|
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 | + } |
41 | 48 |
|
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 | + }); |
51 | 58 |
|
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"); |
59 | 61 | } |
60 | 62 |
|
61 | 63 | // Run the action |
62 | 64 | 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}`); |
65 | 67 | }); |
0 commit comments