@@ -39,6 +39,23 @@ async function checkExistingPr(owner: string, repo: string, issueNumber: number)
3939 return pr ?. html_url ? { pr_url : pr . html_url } : null ;
4040}
4141
42+ type IssueComment = { body ?: string ; user ?: { login ?: string } ; created_at ?: string } ;
43+
44+ async function fetchIssueComments (
45+ owner : string ,
46+ repo : string ,
47+ issueNumber : number ,
48+ token : string
49+ ) : Promise < IssueComment [ ] > {
50+ const url = `https://api.github.com/repos/${ owner } /${ repo } /issues/${ issueNumber } /comments` ;
51+ const res = await fetch ( url , {
52+ headers : { Authorization : `Bearer ${ token } ` , Accept : 'application/vnd.github+json' } ,
53+ } ) ;
54+ if ( ! res . ok ) return [ ] ;
55+ const data = ( await res . json ( ) ) as IssueComment [ ] ;
56+ return Array . isArray ( data ) ? data : [ ] ;
57+ }
58+
4259function loadPayload ( ) : { eventName : string ; payload : unknown } {
4360 if ( ! EVENT_PATH ) {
4461 throw new Error ( 'GITHUB_EVENT_PATH is not set' ) ;
@@ -79,7 +96,8 @@ function buildAssessmentPrompt(
7996 payload : unknown ,
8097 eventName : string ,
8198 referenceIssue : string ,
82- contextBlock : string
99+ contextBlock : string ,
100+ issueComments : IssueComment [ ] = [ ]
83101) : string {
84102 const p = payload as Record < string , unknown > ;
85103 const issue = p . issue as { title ?: string ; body ?: string ; number ?: number } | undefined ;
@@ -99,12 +117,20 @@ function buildAssessmentPrompt(
99117 if ( contextBlock ) {
100118 parts . push ( '' , contextBlock ) ;
101119 }
102-
120+ if ( issueComments . length > 0 ) {
121+ parts . push (
122+ '' ,
123+ 'All issue comments (from API):' ,
124+ issueComments
125+ . map ( ( c ) => `[${ c . user ?. login ?? 'unknown' } @ ${ c . created_at ?? 'N/A' } ]: ${ c . body ?? '' } ` )
126+ . join ( '\n\n' )
127+ ) ;
128+ }
103129 const comment = p . comment as { body ?: string } | undefined ;
104- if ( comment ?. body ) {
105- parts . push ( '' , 'Latest comment:' , comment . body ) ;
130+ if ( comment ?. body && ! issueComments . some ( ( c ) => c . body === comment . body ) ) {
131+ parts . push ( '' , 'Latest event comment:' , comment . body ) ;
106132 }
107- if ( Array . isArray ( p . comments ) && p . comments . length ) {
133+ if ( Array . isArray ( p . comments ) && p . comments . length && issueComments . length === 0 ) {
108134 parts . push ( '' , 'Comments:' , JSON . stringify ( p . comments , null , 2 ) ) ;
109135 }
110136 if ( eventName === 'pull_request_review' || eventName === 'pull_request_review_comment' ) {
@@ -173,7 +199,14 @@ export async function assess(
173199
174200 const referenceIssue = opts . referenceIssue ?? '192' ;
175201 const contextBlock = opts . contextFilesContent ?? loadContextFiles ( ) ;
176- const prompt = buildAssessmentPrompt ( payload , eventName , referenceIssue , contextBlock ) ;
202+ let issueComments : IssueComment [ ] = [ ] ;
203+ if ( ( eventName === 'issues' || eventName === 'issue_comment' ) && opts . repo && opts . token ) {
204+ const [ owner , repo ] = opts . repo . split ( '/' ) ;
205+ if ( owner && repo ) {
206+ issueComments = await fetchIssueComments ( owner , repo , normalized . issueNumber , opts . token ) ;
207+ }
208+ }
209+ const prompt = buildAssessmentPrompt ( payload , eventName , referenceIssue , contextBlock , issueComments ) ;
177210 const result = await callClaude ( prompt , opts . anthropicClient ) ;
178211 result . issue_number = normalized . issueNumber ;
179212 return result ;
0 commit comments