From 5dfa5ab923283409017b5f360212584bd5fb7719 Mon Sep 17 00:00:00 2001 From: Mario Antonini Date: Thu, 21 Mar 2024 15:00:29 -0700 Subject: [PATCH 1/4] Updated text to add to comment --- .../preliminary-update-comment.js | 27 ++++++++++++++++++- .../unassign-from-NIA.md | 5 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md diff --git a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js index 66731647c4..a45c3ed7d4 100644 --- a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js +++ b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js @@ -51,11 +51,36 @@ async function makeComment(){ } } + const isDraft = context.payload.issue.labels.find((label) => label.name == 'Draft') ? true : false; + + const query = `query($owner:String!, $name:String!, $number:Int!) { + repository(owner:$owner, name:$name) { + issue(number:$number) { + projectCards { + nodes { + column { + name + } + } + } + } + } + }`; + const variables = { + owner: context.repo.owner, + name: context.repo.repo, + number: context.payload.issue.number + } + const res = await github.graphql(query, variables); + const columnName = res.repository.issue.projectCards.nodes[0].column.name; + + const filename = !isDraft && columnName == 'New Issue Approval' ? 'unassign-from-NIA.md' : 'preliminary-update.md'; + const filePathToFormat = './github-actions/trigger-issue/add-preliminary-comment/' + filename; const commentObject = { replacementString: issueAssignee, placeholderString: '${issueAssignee}', - filePathToFormat: './github-actions/trigger-issue/add-preliminary-comment/preliminary-update.md', + filePathToFormat: filePathToFormat, textToFormat: null } diff --git a/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md b/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md new file mode 100644 index 0000000000..87c560d6fb --- /dev/null +++ b/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md @@ -0,0 +1,5 @@ + +``` +Hi @${issueAssignee}, HfLA appreciates your interest in this issue, but please note that it is in the `New Issue Approval` column of the Project Board because it has not been finalized, approved or prioritized, and so it is not ready for assignment. For this reason, you have been unassigned from this issue. Please remember to assign issues only from the `Prioritized Backlog` column. The one exception to this rule is if you are writing an issue and the `Draft` label is applied. + +``` \ No newline at end of file From 81f0c8138304131db695ba49a533909906f0a0ff Mon Sep 17 00:00:00 2001 From: Mario Antonini Date: Thu, 21 Mar 2024 15:39:06 -0700 Subject: [PATCH 2/4] Minor fix on markdown file and unassign contributor on js file --- .../preliminary-update-comment.js | 21 +++++++++++++++---- .../unassign-from-NIA.md | 4 +--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js index a45c3ed7d4..a37a28b5e8 100644 --- a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js +++ b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js @@ -53,7 +53,7 @@ async function makeComment(){ const isDraft = context.payload.issue.labels.find((label) => label.name == 'Draft') ? true : false; - const query = `query($owner:String!, $name:String!, $number:Int!) { + const queryColumn = `query($owner:String!, $name:String!, $number:Int!) { repository(owner:$owner, name:$name) { issue(number:$number) { projectCards { @@ -70,11 +70,24 @@ async function makeComment(){ owner: context.repo.owner, name: context.repo.repo, number: context.payload.issue.number + }; + const resColumn = await github.graphql(queryColumn, variables); + const columnName = resColumn.repository.issue.projectCards.nodes[0].column.name; + + let filename = 'preliminary-update.md'; + + // Unassign if issue is in New Issue Approval column of Project Board and is not labeled 'Draft' + if (!isDraft && columnName == 'New Issue Approval') { + filename = 'unassign-from-NIA.md'; + + await github.rest.issues.removeAssignees({ + owner: variables.owner, + repo: variables.name, + issue_number: variables.number, + assignees: [issueAssignee], + }); } - const res = await github.graphql(query, variables); - const columnName = res.repository.issue.projectCards.nodes[0].column.name; - const filename = !isDraft && columnName == 'New Issue Approval' ? 'unassign-from-NIA.md' : 'preliminary-update.md'; const filePathToFormat = './github-actions/trigger-issue/add-preliminary-comment/' + filename; const commentObject = { diff --git a/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md b/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md index 87c560d6fb..bfc8ca4e83 100644 --- a/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md +++ b/github-actions/trigger-issue/add-preliminary-comment/unassign-from-NIA.md @@ -1,5 +1,3 @@ -``` -Hi @${issueAssignee}, HfLA appreciates your interest in this issue, but please note that it is in the `New Issue Approval` column of the Project Board because it has not been finalized, approved or prioritized, and so it is not ready for assignment. For this reason, you have been unassigned from this issue. Please remember to assign issues only from the `Prioritized Backlog` column. The one exception to this rule is if you are writing an issue and the `Draft` label is applied. -``` \ No newline at end of file +Hi @${issueAssignee}, HfLA appreciates your interest in this issue, but please note that it is in the `New Issue Approval` column of the Project Board because it has not been finalized, approved or prioritized, and so it is not ready for assignment. For this reason, you have been unassigned from this issue. Please remember to assign issues only from the `Prioritized Backlog` column. The one exception to this rule is if you are writing an issue and the `Draft` label is applied. From 97fdae1cde1621d55ef66a1123ceb3550dc3b581 Mon Sep 17 00:00:00 2001 From: Mario Antonini Date: Sun, 24 Mar 2024 11:53:41 -0700 Subject: [PATCH 3/4] Cleaned up a little bit --- .../preliminary-update-comment.js | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js index a37a28b5e8..4522723326 100644 --- a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js +++ b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js @@ -1,6 +1,6 @@ -var fs = require("fs") -const postComment = require('../../utils/post-issue-comment') -const formatComment = require('../../utils/format-comment') +const fs = require("fs"); +const postComment = require('../../utils/post-issue-comment'); +const formatComment = require('../../utils/format-comment'); const getTimeline = require('../../utils/get-timeline'); // Global variables @@ -16,19 +16,19 @@ var context */ async function main({ g, c }, { shouldPost, issueNum }){ - github = g - context = c + github = g; + context = c; // If the previous action returns a false, stop here if(shouldPost === false){ - console.log('No need to post comment.') - return + console.log('No need to post comment.'); + return; } //Else we make the comment with the issuecreator's github handle instead of the placeholder. else{ const instructions = await makeComment() if(instructions !== null){ // the actual creation of the comment in github - await postComment(issueNum, instructions, github, context) + await postComment(issueNum, instructions, github, context); } } } @@ -40,14 +40,13 @@ async function main({ g, c }, { shouldPost, issueNum }){ async function makeComment(){ // Setting all the variables which formatComment is to be called with - var issueAssignee = context.payload.issue.assignee.login - const eventdescriptions = await getTimeline(context.payload.issue.number, github, context) - console.log(eventdescriptions.length) + let issueAssignee = context.payload.issue.assignee.login; + const eventdescriptions = await getTimeline(context.payload.issue.number, github, context); //adding the code to find out the latest person assigned the issue - for(var i = eventdescriptions.length - 1 ; i>=0; i-=1){ + for(let i = eventdescriptions.length - 1; i >= 0; i -= 1){ if(eventdescriptions[i].event == 'assigned'){ - issueAssignee = eventdescriptions[i].assignee.login - break + issueAssignee = eventdescriptions[i].assignee.login; + break; } } @@ -98,8 +97,8 @@ async function makeComment(){ } // creating the comment with issue assignee's name and returning it! - const commentWithIssueAssignee = formatComment(commentObject, fs) - return commentWithIssueAssignee + const commentWithIssueAssignee = formatComment(commentObject, fs); + return commentWithIssueAssignee; } -module.exports = main +module.exports = main; From 266350caa6ceae1db48e48ad26bd754240a4e74f Mon Sep 17 00:00:00 2001 From: Mario Antonini Date: Sun, 24 Mar 2024 15:30:10 -0700 Subject: [PATCH 4/4] A bit more cleanup --- .../preliminary-update-comment.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js index 4522723326..7ec26b6f79 100644 --- a/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js +++ b/github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js @@ -4,8 +4,8 @@ const formatComment = require('../../utils/format-comment'); const getTimeline = require('../../utils/get-timeline'); // Global variables -var github -var context +var github; +var context; /** * @description - This function is the entry point into the javascript file, it formats the md file based on the result of the previous step and then posts it to the issue @@ -25,7 +25,7 @@ async function main({ g, c }, { shouldPost, issueNum }){ } //Else we make the comment with the issuecreator's github handle instead of the placeholder. else{ - const instructions = await makeComment() + const instructions = await makeComment(); if(instructions !== null){ // the actual creation of the comment in github await postComment(issueNum, instructions, github, context); @@ -41,11 +41,11 @@ async function main({ g, c }, { shouldPost, issueNum }){ async function makeComment(){ // Setting all the variables which formatComment is to be called with let issueAssignee = context.payload.issue.assignee.login; - const eventdescriptions = await getTimeline(context.payload.issue.number, github, context); + const eventDescriptions = await getTimeline(context.payload.issue.number, github, context); //adding the code to find out the latest person assigned the issue - for(let i = eventdescriptions.length - 1; i >= 0; i -= 1){ - if(eventdescriptions[i].event == 'assigned'){ - issueAssignee = eventdescriptions[i].assignee.login; + for(let i = eventDescriptions.length - 1; i >= 0; i -= 1){ + if(eventDescriptions[i].event == 'assigned'){ + issueAssignee = eventDescriptions[i].assignee.login; break; } } @@ -94,7 +94,7 @@ async function makeComment(){ placeholderString: '${issueAssignee}', filePathToFormat: filePathToFormat, textToFormat: null - } + }; // creating the comment with issue assignee's name and returning it! const commentWithIssueAssignee = formatComment(commentObject, fs);