@@ -5,43 +5,76 @@ import type { Octokit } from "@octokit/rest";
55/**
66 * Get input from environment variables (GitHub Actions pattern)
77 */
8- export function getInput ( name : string , required = false ) : string {
8+ export function getInput ( name : string , required : true ) : string ;
9+ export function getInput ( name : string , required ?: false ) : string | undefined ;
10+ export function getInput ( name : string , required = false ) : string | undefined {
911 const envName = `INPUT_${ name . toUpperCase ( ) . replace ( / / g, "_" ) } ` ;
10- const value = process . env [ envName ] || "" ;
12+ const value = process . env [ envName ] ;
1113
1214 if ( required && ! value ) {
1315 throw new Error ( `Input required and not supplied: ${ name } ` ) ;
1416 }
1517
16- return value . trim ( ) ;
18+ return value ? .trim ( ) || undefined ;
1719}
1820
1921/**
20- * Extract comment ID from GitHub event payload
21- * Returns undefined if the event doesn't have a comment
22+ * Read and parse GitHub event payload
23+ * Returns undefined if the event payload cannot be read
2224 */
23- export function getCommentIdFromEvent ( ) : number | undefined {
25+ function getEventPayload ( ) : Record < string , unknown > | undefined {
2426 const eventPath = process . env . GITHUB_EVENT_PATH ;
2527 if ( ! eventPath ) {
2628 core . warning ( "GITHUB_EVENT_PATH not found" ) ;
2729 return undefined ;
2830 }
2931
3032 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 ;
33+ return JSON . parse ( readFileSync ( eventPath , "utf8" ) ) ;
3934 } catch ( error ) {
4035 core . warning ( `Failed to read event payload: ${ error } ` ) ;
4136 return undefined ;
4237 }
4338}
4439
40+ /**
41+ * Extract comment ID from GitHub event payload
42+ * Returns undefined if the event doesn't have a comment
43+ */
44+ export function getCommentIdFromEvent ( ) : number | undefined {
45+ const eventData = getEventPayload ( ) ;
46+ if ( ! eventData ) {
47+ return undefined ;
48+ }
49+
50+ // Check if event has a comment object
51+ const comment = eventData . comment as { id ?: number } | undefined ;
52+ if ( comment ?. id ) {
53+ return comment . id ;
54+ }
55+
56+ return undefined ;
57+ }
58+
59+ /**
60+ * Extract comment body from GitHub event payload
61+ * Returns undefined if the event doesn't have a comment
62+ */
63+ export function getCommentBodyFromEvent ( ) : string | undefined {
64+ const eventData = getEventPayload ( ) ;
65+ if ( ! eventData ) {
66+ return undefined ;
67+ }
68+
69+ // Check if event has a comment object with body
70+ const comment = eventData . comment as { body ?: string } | undefined ;
71+ if ( comment ?. body ) {
72+ return comment . body ;
73+ }
74+
75+ return undefined ;
76+ }
77+
4578/**
4679 * Parse repository owner and name from GITHUB_REPOSITORY
4780 */
@@ -62,23 +95,31 @@ type ReactToCommentParams = {
6295 octokit : Octokit ;
6396 owner : string ;
6497 repo : string ;
65- commentId : number ;
6698 eventName : string ;
6799} ;
68100
69101/**
70102 * React to a comment with an emoji
103+ * Extracts comment ID from event payload and reacts if present
71104 */
72105export async function reactToComment ( {
73106 octokit,
74107 owner,
75108 repo,
76- commentId,
77109 eventName,
78110} : ReactToCommentParams ) : Promise < void > {
79- core . info ( `🎯 Reacting to comment ${ commentId } with :eyes:` ) ;
80- core . info ( `📦 Repository: ${ owner } /${ repo } ` ) ;
81- core . info ( `📝 Event: ${ eventName } ` ) ;
111+ // Extract comment_id from GitHub event payload
112+ const commentId = getCommentIdFromEvent ( ) ;
113+
114+ // Only react if we have a comment ID
115+ if ( ! commentId ) {
116+ core . info (
117+ `ℹ️ No comment found in event payload, skipping comment reaction (event: ${ eventName } )` ,
118+ ) ;
119+ return ;
120+ }
121+
122+ core . info ( "👀 Reacting to comment" ) ;
82123
83124 // React based on event type
84125 if ( eventName === "pull_request_review_comment" ) {
@@ -102,48 +143,31 @@ export async function reactToComment({
102143 core . info ( `✅ Successfully added :eyes: reaction to comment ${ commentId } ` ) ;
103144}
104145
105- type PostCommentParams = {
106- octokit : Octokit ;
107- owner : string ;
108- repo : string ;
109- issueNumber : number ;
110- body : string ;
146+ type AuggieParams = {
147+ githubToken : string ;
111148 eventName : string ;
149+ prompt : string ;
150+ augmentApiKey : string ;
151+ augmentApiUrl : string ;
152+ workspaceRoot : string | undefined ;
153+ commentBody : string | undefined ;
112154} ;
113155
114- /**
115- * Post a reply comment
116- */
117- export async function postComment ( {
118- octokit,
119- owner,
120- repo,
121- issueNumber,
122- body,
123- eventName,
124- } : PostCommentParams ) : Promise < void > {
125- core . info ( "💬 Posting comment reply..." ) ;
126-
127- // Post comment based on event type
128- if ( eventName === "pull_request_review_comment" ) {
129- // For PR review comments, we need to post as a regular issue comment
130- // since we can't reply directly to review comments via API
131- await octokit . rest . issues . createComment ( {
132- owner,
133- repo,
134- issue_number : issueNumber ,
135- body,
136- } ) ;
137- } else if ( eventName === "issue_comment" ) {
138- await octokit . rest . issues . createComment ( {
139- owner,
140- repo,
141- issue_number : issueNumber ,
142- body,
143- } ) ;
144- } else {
145- throw new Error ( `Unsupported event type: ${ eventName } ` ) ;
156+ export function getAuggieParams ( ) : AuggieParams {
157+ const githubToken = getInput ( "github_token" , true ) ;
158+ const eventName = getInput ( "event_name" , true ) ;
159+ const prompt = getInput ( "prompt" , true ) ;
160+ const augmentApiKey = getInput ( "augment_api_key" , true ) ;
161+ const augmentApiUrl = getInput ( "augment_api_url" , true ) ;
162+ const workspaceRoot = getInput ( "workspace_root" ) ;
163+ const commentBody = getCommentBodyFromEvent ( ) ;
164+ return {
165+ githubToken,
166+ eventName,
167+ prompt,
168+ augmentApiKey,
169+ augmentApiUrl,
170+ workspaceRoot,
171+ commentBody,
146172 }
147-
148- core . info ( "✅ Successfully posted comment" ) ;
149173}
0 commit comments