Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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
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
Expand All @@ -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()
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);
}
}
}
Expand All @@ -40,28 +40,65 @@ 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){
if(eventdescriptions[i].event == 'assigned'){
issueAssignee = eventdescriptions[i].assignee.login
break
for(let i = eventDescriptions.length - 1; i >= 0; i -= 1){
if(eventDescriptions[i].event == 'assigned'){
issueAssignee = eventDescriptions[i].assignee.login;
break;
}
}

const isDraft = context.payload.issue.labels.find((label) => label.name == 'Draft') ? true : false;

const queryColumn = `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 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 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
}
};

// 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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- Template for a notification to the assignee that they will be unassigned because the issue is in the "New Issue Approval" column -->

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.