-
-
Notifications
You must be signed in to change notification settings - Fork 844
Enhanced Skills Activity GHA to use Skills Directory #8370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
b2830e2
e458fc4
7217292
1ac174c
7dbcad2
0c0a75f
02cbaf3
b1b2957
397308f
0e57320
23c0730
37aa0fe
ba56356
ba6a687
459b847
38f2c6a
e4174a7
104fb5c
77ed1a1
2716d2b
d16a0a8
5e1f55f
9e6524d
33924db
7383d6c
a57eac9
0814cd4
d5450d5
9e5a8be
fcfdafc
58074a5
4ba5279
b74bae2
fa4e10b
0b632cd
d094b96
c3d296d
0780650
ee0d837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| const checkTeamMembership = require('../utils/check-team-membership'); | ||
| const statusFieldIds = require('../utils/_data/status-field-ids'); | ||
| const mutateIssueStatus = require('../utils/mutate-issue-status'); | ||
| const { lookupSkillsDirectory, updateSkillsDirectory } = require('../utils/skills-directory'); | ||
|
|
||
| // `complexity0` refers `Complexity: Prework` label | ||
| const SKILLS_LABEL = retrieveLabelDirectory("complexity0"); | ||
|
|
@@ -33,72 +34,149 @@ | |
| console.log(`eventActor is undefined (likely a bot). Cannot post message...`); | ||
| return; | ||
| } | ||
|
|
||
| // Get eventActor's Skills Issue number, nodeId, current statusId (all null if no Skills Issue found) | ||
| const skillsInfo = await querySkillsIssue(github, context, eventActor, SKILLS_LABEL); | ||
| const skillsIssueNum = skillsInfo.issueNum; | ||
| const skillsIssueNodeId = skillsInfo.issueId; | ||
| const skillsStatusId = skillsInfo.statusId; | ||
| const isArchived = skillsInfo.isArchived; | ||
|
|
||
| // Step 1: Try local directory lookup first | ||
| let needsUpdate = false; | ||
| let skillsInfo = lookupSkillsDirectory(eventActor); | ||
|
|
||
| if (!skillsInfo) { | ||
| console.log(`No cached Skills Issue found for ${eventActor}, querying GitHub...`); | ||
|
|
||
| // Step 2: Fallback to GitHub API | ||
| skillsInfo = await querySkillsIssue(github, context, eventActor, SKILLS_LABEL); | ||
|
||
|
|
||
| // Step 3: Save result to local directory if found | ||
| if (skillsInfo && skillsInfo.issueNum) { | ||
| needsUpdate = true | ||
Check noticeCode scanning / CodeQL Semicolon insertion Note
Avoid automated semicolon insertion (98% of all statements in
the enclosing function Error loading related location Loading |
||
| } else { | ||
| console.log(` ⮡ No Skills Issue found for ${eventActor}. Cannot post message.`); | ||
| return; | ||
| } | ||
| } | ||
| // Get eventActor's Skills Issue number, nodeId, current statusId (all null if no Skills Issue found) | ||
| //const skillsIssueNum = skillsInfo.issueNum; | ||
| const skillsIssueNum = 17; | ||
| const skillsIssueNodeId = skillsInfo.issueId; | ||
| const skillsStatusId = skillsInfo?.statusId || 'unknown'; | ||
| const isArchived = skillsInfo?.isArchived || false; | ||
| const commentIdCached = skillsInfo?.commentId || null; // not used currently | ||
|
|
||
| console.log(`skillsIssueNum: ${skillsIssueNum}, skillsIssueNodeId: ${skillsIssueNodeId}, skillsStatusId: ${skillsStatusId}, isArchived: ${isArchived}`); // only for debugging | ||
|
|
||
| // Return immediately if Skills Issue not found | ||
| if (!skillsIssueNum) { | ||
| console.log(` ⮡ Did not find Skills Issue for ${eventActor}. Cannot post message.`); | ||
| return; | ||
| } | ||
| console.log(` ⮡ Found Skills Issue for ${eventActor}: #${skillsIssueNum}`); | ||
|
|
||
| // Get all comments from the Skills Issue | ||
| let commentData; | ||
| try { | ||
| // https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments | ||
| commentData = await github.request('GET /repos/{owner}/{repo}/issues/{issue_number}/comments', { | ||
| owner, | ||
| repo, | ||
| per_page: 100, | ||
| issue_number: skillsIssueNum, | ||
| }); | ||
| } catch (err) { | ||
| console.error(` ⮡ GET comments failed for issue #${skillsIssueNum}:`, err); | ||
| return; | ||
| } | ||
| let commentIdToUse = commentIdCached; | ||
| let commentFound = null; | ||
|
|
||
| // Find the comment that includes the MARKER text and append message | ||
| const commentFound = commentData.data.find(comment => comment.body.includes(MARKER)); | ||
| // Try cached comment ID first | ||
| if (commentIdCached) { | ||
| console.log(` ⮡ Found cached comment ID for ${eventActor}: ${commentIdCached}`); | ||
| try { | ||
| const { data: cachedComment } = await github.request( | ||
| 'GET /repos/{owner}/{repo}/issues/comments/{comment_id}', | ||
| { | ||
| owner, | ||
| repo, | ||
| comment_id: commentIdCached, | ||
| } | ||
| ); | ||
|
|
||
| if (commentFound) { | ||
| console.log(` ⮡ Found comment with MARKER...`); | ||
| const comment_id = commentFound.id; | ||
| const originalBody = commentFound.body; | ||
| const updatedBody = `${originalBody}\n${message}`; | ||
| if (cachedComment && cachedComment.body.includes(MARKER)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't satisfy this if statement, I think we accidentally skip the fallback (because commendIdToUse is set to commendIdCached, which is non-null if we get here)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this comment still applies. You could potentially resolve this by adding an |
||
| const updatedBody = `${cachedComment.body}\n${message}`; | ||
| await github.request('PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}', { | ||
| owner, | ||
| repo, | ||
| comment_id: commentIdCached, | ||
| body: updatedBody, | ||
| }); | ||
| console.log(` ⮡ Updated cached comment #${commentIdCached}`); | ||
|
|
||
| } else { | ||
| commentIdToUse = null; | ||
| } | ||
| } catch (err) { | ||
| console.warn(` ⮡ Cached comment invalid or not found. Falling back to search.`, err); | ||
| commentIdToUse = null; // Force fallback path | ||
| } | ||
| } | ||
|
|
||
| // Fallback — search for MARKER or create new comment | ||
| if (!commentIdToUse) { | ||
| console.log(` ⮡ Searching for activity comment marker...`); | ||
| let commentData; | ||
| try { | ||
| // https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#update-an-issue-comment | ||
| await github.request('PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}', { | ||
| owner, | ||
| repo, | ||
| comment_id, | ||
| body: updatedBody | ||
| }); | ||
| console.log(` ⮡ Entry posted to Skills Issue #${skillsIssueNum}`); | ||
| commentData = await github.request( | ||
| 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments', | ||
| { | ||
| owner, | ||
| repo, | ||
| per_page: 100, | ||
| issue_number: skillsIssueNum, | ||
| } | ||
| ); | ||
| } catch (err) { | ||
| console.error(` ⮡ Something went wrong posting entry to #${skillsIssueNum}:`, err); | ||
| console.error(` ⮡ GET comments failed for issue #${skillsIssueNum}:`, err); | ||
| return; | ||
| } | ||
|
|
||
| } else { | ||
| console.log(` ⮡ MARKER not found, creating new comment entry with MARKER...`); | ||
| 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}`; | ||
| const commentPosted = await postComment(skillsIssueNum, body, github, context); | ||
| if (commentPosted) { | ||
| console.log(` ⮡ Entry posted to Skills Issue #${skillsIssueNum}`); | ||
|
|
||
| commentFound = commentData.data.find((comment) => comment.body.includes(MARKER)); | ||
|
|
||
| if (commentFound) { | ||
| console.log(` ⮡ Found comment with MARKER...`); | ||
| const comment_id = commentFound.id; | ||
| const originalBody = commentFound.body; | ||
| const updatedBody = `${originalBody}\n${message}`; | ||
| try { | ||
| await github.request('PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}', { | ||
| owner, | ||
| repo, | ||
| comment_id, | ||
| body: updatedBody, | ||
| }); | ||
| console.log(` ⮡ Entry posted to Skills Issue #${skillsIssueNum}`); | ||
| // Cache this comment ID | ||
| updateSkillsDirectory(eventActor, { commentId: comment_id }); | ||
| } catch (err) { | ||
| console.error(` ⮡ Something went wrong posting entry to #${skillsIssueNum}:`, err); | ||
| } | ||
| } else { | ||
| console.log(` ⮡ MARKER not found, creating new comment entry with MARKER...`); | ||
| 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}`; | ||
| try { | ||
| const { data: newComment } = await github.request( | ||
Check noticeCode scanning / CodeQL Unused variable, import, function or class Note
Unused variable newComment.
|
||
| 'POST /repos/{owner}/{repo}/issues/{issue_number}/comments', | ||
| { | ||
| owner, | ||
| repo, | ||
| issue_number: skillsIssueNum, | ||
| body, | ||
| } | ||
| ); | ||
| console.log(` ⮡ Entry posted to Skills Issue #${skillsIssueNum}`); | ||
| // Cache new comment ID | ||
| // updateSkillsDirectory(eventActor, { commentId: newComment.id }); | ||
| } catch (err) { | ||
| console.error(` ⮡ Failed to create new comment for issue #${skillsIssueNum}:`, err); | ||
| } | ||
| } | ||
| } | ||
| if (needsUpdate) { | ||
| console.log(` ⮡ Updating Skills Directory for ${eventActor}...`); | ||
| updateSkillsDirectory(eventActor, skillsIssueNum, skillsIssueNodeId, commentIdFound); | ||
| }; | ||
|
|
||
|
|
||
| // Only proceed if Skills Issue message does not include: 'closed', 'assigned', or isArchived | ||
| if (!(message.includes('closed') || message.includes('assigned') || isArchived)) { | ||
|
|
||
| // If eventActor is team member, open issue and move to "In progress" | ||
| const isActiveMember = await checkTeamMembership(github, context, eventActor, TEAM); | ||
|
|
||
| //const isActiveMember = await checkTeamMembership(github, context, eventActor, TEAM); | ||
| const isActiveMember = true; | ||
| if (isActiveMember) { | ||
| try { | ||
| await github.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { | ||
|
|
@@ -121,4 +199,4 @@ | |
|
|
||
| } | ||
|
|
||
| module.exports = postToSkillsIssue; | ||
| module.exports = postToSkillsIssue; | ||
Uh oh!
There was an error while loading. Please reload this page.