Skip to content

Commit

Permalink
PBB migration "Issue Trigger" (#7053)
Browse files Browse the repository at this point in the history
* Update issue-trigger.yml

Changes in prep for Projects Beta migration

* Update issue-trigger.yml

space added to comment

* Update issue-trigger.yml

edits to comment at Team Members

* Update preliminary-update-comment.js

refactoring for PBB migration
  • Loading branch information
t-will-gillis authored Jun 23, 2024
1 parent f557f73 commit 3fcd415
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 67 deletions.
42 changes: 12 additions & 30 deletions .github/workflows/issue-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,10 @@ on:
types: [opened, transferred, assigned, labeled, unlabeled]

jobs:
# Adds newly created issues onto project board in the default column 'New Issue Approval'
# unless overridden when issue has "LA website bot" in title, then 'Questions / In Review'
Add-Issue-To-Project-Board:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'issues' && github.event.action == 'opened' }}
env:
COLUMN_NAME: ${{ contains(github.event.issue.title, 'Hack for LA website bot') && 'Questions / In Review' || 'New Issue Approval' }}
steps:
- name: Add issue to project board
id: add-issue-project-board
uses: alex-page/github-project-automation-plus@v0.9.0
with:
project: Project Board
column: ${{ env.COLUMN_NAME }}
repo-token: ${{ secrets.HACKFORLA_BOT_PA_TOKEN }}

# Adds missing labels to newly-created or transferred issues
Add-Missing-Labels-To-Issues:
runs-on: ubuntu-latest
# Only trigger this action when an issue is newly created
if: ${{ github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'transferred')}}
if: ${{ github.event.action == 'opened' || github.event.action == 'transferred' }}
steps:
- uses: actions/checkout@v4
# Check if the issue has required labels
Expand All @@ -36,7 +20,7 @@ jobs:
const checkLabels = script({g: github, c: context})
return checkLabels
#Checks which teams the user is on
# Checks if user is on the 'website-write' team
- uses: tspascoal/get-user-teams-membership@v3
id: checkUserMember
with:
Expand All @@ -45,9 +29,8 @@ jobs:
team: 'website-write'
GITHUB_TOKEN: ${{ secrets.TEAMS }}

# Checks if user is on the website-write-team
# Posts comment only if user is team member (based on the previous action's result)
- if: ${{ steps.checkUserMember.outputs.isTeamMember == 'true' }}
# Post comment based on the previous action's results
name: Post Comment
uses: actions/github-script@v7
id: post-comment
Expand All @@ -58,15 +41,13 @@ jobs:
script({g: github, c:context}, results)
#Asking for preliminary update when issue is assigned
# Asks for preliminary update when issue is assigned
Ask-For-Preliminary-update:
runs-on: ubuntu-latest
#Triggers when the issue is newly assigned
if: ${{ github.event_name == 'issues' && github.event.action == 'assigned'}}
if: ${{ github.event.action == 'assigned' }}
steps:
- uses: actions/checkout@v4

# Check if the issue has the required roles
# Checks if the issue has the required roles (front end, back end/devOps, design, or user research)
- name: Check Labels Prelim
uses: actions/github-script@v7
id: check-labels-prelim
Expand All @@ -76,22 +57,24 @@ jobs:
const checklabels = script({g: github, c: context})
return checklabels
# Post the comment based on the result of the previous step
# Posts the comment based on the result of the previous step
- name: Post assigning issue comment
id: assigned-comment
uses: actions/github-script@v7
with:
script: |
const results = ${{ steps.check-labels-prelim.outputs.result }}
const script = require('./github-actions/trigger-issue/add-preliminary-comment/preliminary-update-comment.js')
script({g: github, c:context},results)
script({g: github, c:context}, results)
# The following steps only apply to issues with `Feature: Feature Branch` label
# Note: These steps will be unnecessary and should be removed once Feature Branch goes live
Add-Feature-Branch-Comment:
runs-on: ubuntu-latest
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'Feature: Feature Branch' }}"
steps:
- uses: actions/checkout@v4

- name: Add feature branch comment
uses: actions/github-script@v7
with:
Expand All @@ -104,7 +87,6 @@ jobs:
if: "${{ github.event.action == 'unlabeled' && github.event.label.name == 'Feature: Feature Branch' }}"
steps:
- uses: actions/checkout@v4

- name: Hide feature branch comment
uses: actions/github-script@v7
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
var fs = require("fs")
const postComment = require('../../utils/post-issue-comment')
const formatComment = require('../../utils/format-comment')
// Import modules
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
* @param {Object} g - github object
* @param {Object} c - context object
* @param {Object} g - GitHub object
* @param {Object} c - context object
* @param {Boolean} actionResult - the previous gh-action's result
* @param {Number} issueNum - the number of the issue where the post will be made
* @param {Number} issueNum - the number of the issue where the post will be made
*/

async function main({ g, c }, { shouldPost, issueNum }){
github = g
context = c
// If the previous action returns a false, stop here
if(shouldPost === false){
console.log('No need to post comment.')
return
github = g;
context = c;
// If the previous action returned a false, stop here
if (shouldPost === false) {
console.log('Issue creator not a team member, 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)
// Else we make the comment with the issue creator'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);
}
}
}

/**
* @description - This function makes the comment with the issue assignee's github handle using the raw preliminary.md file
* @description - This function makes the comment with the issue assignee's GitHub handle using the raw preliminary.md file
* @returns {string} - Comment to be posted with the issue assignee's name in it!!!
*/

async function makeComment(){
async function makeComment() {
// Setting all the variables which formatComment is to be called with
let issueAssignee = context.payload.issue.assignee.login
let issueAssignee = context.payload.issue.assignee.login;
let filename = 'preliminary-update.md';
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(var i = eventdescriptions.length - 1 ; i>=0; i-=1){
if(eventdescriptions[i].event == 'assigned'){
issueAssignee = eventdescriptions[i].assignee.login
break
// 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;
}
}

// BELOW through line 89 +/-, disabling the 'column' checks becaues these are not compatible
// with Projects Beta. This code needs to be refactored using GraphQL, ProjectsV2, and 'status' field.
/*
// Getting the issue's Project Board column name
const queryColumn = `query($owner:String!, $name:String!, $number:Int!) {
repository(owner:$owner, name:$name) {
Expand All @@ -71,7 +73,7 @@ async function makeComment(){
const isDraft = context.payload.issue.labels.find((label) => label.name == 'Draft') ? true : false;
if (columnName == 'New Issue Approval' && !isDraft && !isPrework) {
// If author = assignee, remind them to add draft label, otherwise unnasign and comment
// If author == assignee, remind them to add `Draft` label, otherwise unnasign and comment
if (context.payload.issue.user.login == issueAssignee) {
filename = 'draft-label-reminder.md';
} else {
Expand All @@ -85,18 +87,19 @@ async function makeComment(){
});
}
}
*/

let filePathToFormat = './github-actions/trigger-issue/add-preliminary-comment/' + filename;
const commentObject = {
replacementString: issueAssignee,
placeholderString: '${issueAssignee}',
filePathToFormat: filePathToFormat,
textToFormat: null
}
};

// creating the comment with issue assignee's name and returning it!
const commentWithIssueAssignee = formatComment(commentObject, fs)
return commentWithIssueAssignee
// Creating the comment with issue assignee's name and returning it!
const commentWithIssueAssignee = formatComment(commentObject, fs);
return commentWithIssueAssignee;
}

module.exports = main
module.exports = main;

0 comments on commit 3fcd415

Please sign in to comment.