@@ -50,11 +50,11 @@ async function postToSkillsIssue({github, context}, activity) {
5050 }
5151 }
5252
53-
5453 // Get eventActor's Skills Issue number, nodeId, current statusId (all null if no Skills Issue found)
5554 const skillsIssueNum = skillsInfo . issueNum ;
5655 const skillsIssueNodeId = skillsInfo . issueId ;
5756 const skillsStatusId = skillsInfo . statusId ;
57+ const commentIdCached = skillsInfo . commentId ;
5858 const isArchived = skillsInfo . isArchived ;
5959
6060 // Return immediately if Skills Issue not found
@@ -64,48 +64,97 @@ async function postToSkillsIssue({github, context}, activity) {
6464 }
6565 console . log ( ` ⮡ Found Skills Issue for ${ eventActor } : #${ skillsIssueNum } ` ) ;
6666
67- // Get all comments from the Skills Issue
68- let commentData ;
69- try {
70- // https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
71- commentData = await github . request ( 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments' , {
72- owner,
73- repo,
74- per_page : 100 ,
75- issue_number : skillsIssueNum ,
76- } ) ;
77- } catch ( err ) {
78- console . error ( ` ⮡ GET comments failed for issue #${ skillsIssueNum } :` , err ) ;
79- return ;
80- }
67+ let commentIdToUse = commentIdCached ;
68+ let commentFound = null ;
8169
82- // Find the comment that includes the MARKER text and append message
83- const commentFound = commentData . data . find ( comment => comment . body . includes ( MARKER ) ) ;
70+ // Try cached comment ID first
71+ if ( commentIdCached ) {
72+ console . log ( ` ⮡ Found cached comment ID for ${ eventActor } : ${ commentIdCached } ` ) ;
73+ try {
74+ const { data : cachedComment } = await github . request (
75+ 'GET /repos/{owner}/{repo}/issues/comments/{comment_id}' ,
76+ {
77+ owner,
78+ repo,
79+ comment_id : commentIdCached ,
80+ }
81+ ) ;
8482
85- if ( commentFound ) {
86- console . log ( ` ⮡ Found comment with MARKER...` ) ;
87- const comment_id = commentFound . id ;
88- const originalBody = commentFound . body ;
89- const updatedBody = `${ originalBody } \n${ message } ` ;
83+ if ( cachedComment && cachedComment . body . includes ( MARKER ) ) {
84+ const updatedBody = `${ cachedComment . body } \n${ message } ` ;
85+ await github . request ( 'PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}' , {
86+ owner,
87+ repo,
88+ comment_id : commentIdCached ,
89+ body : updatedBody ,
90+ } ) ;
91+ console . log ( ` ⮡ Updated cached comment #${ commentIdCached } ` ) ;
92+ return ; // Done
93+ }
94+ } catch ( err ) {
95+ console . warn ( ` ⮡ Cached comment invalid or not found. Falling back to search.` , err ) ;
96+ commentIdToUse = null ; // Force fallback path
97+ }
98+ }
99+
100+ // Fallback — search for MARKER or create new comment
101+ if ( ! commentIdToUse ) {
102+ console . log ( ` ⮡ Searching for activity comment marker...` ) ;
103+ let commentData ;
90104 try {
91- // https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#update-an-issue-comment
92- await github . request ( 'PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}' , {
93- owner,
94- repo,
95- comment_id,
96- body : updatedBody
97- } ) ;
98- console . log ( ` ⮡ Entry posted to Skills Issue #${ skillsIssueNum } ` ) ;
105+ commentData = await github . request (
106+ 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments' ,
107+ {
108+ owner,
109+ repo,
110+ per_page : 100 ,
111+ issue_number : skillsIssueNum ,
112+ }
113+ ) ;
99114 } catch ( err ) {
100- console . error ( ` ⮡ Something went wrong posting entry to #${ skillsIssueNum } :` , err ) ;
115+ console . error ( ` ⮡ GET comments failed for issue #${ skillsIssueNum } :` , err ) ;
116+ return ;
101117 }
102-
103- } else {
104- console . log ( ` ⮡ MARKER not found, creating new comment entry with MARKER...` ) ;
105- const body = `${ MARKER } \n## Activity Log: ${ eventActor } \n### Repo: https://github.com/hackforla/website\n\n##### ⚠ Important note: The bot updates this comment automatically - do not edit\n\n${ message } ` ;
106- const commentPosted = await postComment ( skillsIssueNum , body , github , context ) ;
107- if ( commentPosted ) {
108- console . log ( ` ⮡ Entry posted to Skills Issue #${ skillsIssueNum } ` ) ;
118+
119+ commentFound = commentData . data . find ( ( comment ) => comment . body . includes ( MARKER ) ) ;
120+
121+ if ( commentFound ) {
122+ console . log ( ` ⮡ Found comment with MARKER...` ) ;
123+ const comment_id = commentFound . id ;
124+ const originalBody = commentFound . body ;
125+ const updatedBody = `${ originalBody } \n${ message } ` ;
126+ try {
127+ await github . request ( 'PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}' , {
128+ owner,
129+ repo,
130+ comment_id,
131+ body : updatedBody ,
132+ } ) ;
133+ console . log ( ` ⮡ Entry posted to Skills Issue #${ skillsIssueNum } ` ) ;
134+ // Cache this comment ID
135+ updateSkillsDirectory ( eventActor , { commentId : comment_id } ) ;
136+ } catch ( err ) {
137+ console . error ( ` ⮡ Something went wrong posting entry to #${ skillsIssueNum } :` , err ) ;
138+ }
139+ } else {
140+ console . log ( ` ⮡ MARKER not found, creating new comment entry with MARKER...` ) ;
141+ const body = `${ MARKER } \n## Activity Log: ${ eventActor } \n### Repo: https://github.com/hackforla/website\n\n##### ⚠ Important note: The bot updates this comment automatically - do not edit\n\n${ message } ` ;
142+ try {
143+ const { data : newComment } = await github . request (
144+ 'POST /repos/{owner}/{repo}/issues/{issue_number}/comments' ,
145+ {
146+ owner,
147+ repo,
148+ issue_number : skillsIssueNum ,
149+ body,
150+ }
151+ ) ;
152+ console . log ( ` ⮡ Entry posted to Skills Issue #${ skillsIssueNum } ` ) ;
153+ // Cache new comment ID
154+ updateSkillsDirectory ( eventActor , { commentId : newComment . id } ) ;
155+ } catch ( err ) {
156+ console . error ( ` ⮡ Failed to create new comment for issue #${ skillsIssueNum } :` , err ) ;
157+ }
109158 }
110159 }
111160
0 commit comments