diff --git a/github-actions/trigger-issue/add-missing-labels-to-issues/check-labels.js b/github-actions/trigger-issue/add-missing-labels-to-issues/check-labels.js index 5aa85adbfa..8d593c564e 100644 --- a/github-actions/trigger-issue/add-missing-labels-to-issues/check-labels.js +++ b/github-actions/trigger-issue/add-missing-labels-to-issues/check-labels.js @@ -2,14 +2,42 @@ const statusFieldIds = require('../../utils/_data/status-field-ids'); const queryIssueInfo = require('../../utils/query-issue-info'); const mutateIssueStatus = require('../../utils/mutate-issue-status'); +const retrieveLabelDirectory = require('../../utils/retrieve-label-directory'); + +// Use labelKeys to retrieve current labelNames from directory +const [ + sizeMissing, + featureMissing, + complexityMissing, + roleMissing, + complexity1, + complexity2, + readyForDevLead, + featureAdministrative, + size025pt, + roleDevLeads +] = [ + "sizeMissing", + "featureMissing", + "complexityMissing", + "roleMissing", + "complexity1", + "complexity2", + "readyForDevLead", + "featureAdministrative", + "size025pt", + "roleDevLeads" +].map(retrieveLabelDirectory); // Constant variables -const REQUIRED_LABELS = ['Complexity', 'role', 'Feature', 'size']; -const LABEL_MISSING = ['Complexity: Missing', 'role missing', 'Feature Missing', 'size: missing']; -const COMPLEXITY_EXCEPTIONS = ['good first issue']; +const REQUIRED_LABELS = ['complexity', 'role', 'feature', 'size']; +const LABEL_MISSING = [complexityMissing, roleMissing, featureMissing, sizeMissing]; +// Exception for the `good first issue` label +const COMPLEXITY_EXCEPTIONS = [complexity1]; -// SPECIAL_CASE is for issue created by reference with issue title "Hack for LA website bot" (from "Review Inactive Team Members") -const SPECIAL_CASE = ['ready for dev lead','Feature: Administrative','size: 0.25pt','Complexity: Small','role: dev leads']; +// SPECIAL_CASE is for issue created by reference with issue title "Hack for LA website bot" +// ("Review Inactive Team Members" from the "Schedule Monthly" workflow) +const SPECIAL_CASE = [readyForDevLead, featureAdministrative, size025pt, complexity2, roleDevLeads]; // Global variables var github; @@ -86,7 +114,7 @@ function checkLabels(labels) { const regExp = new RegExp(`\\b${requiredLabel}\\b`, 'gi'); const isLabelPresent = labels.some(label => { // If the label is in the complexity exceptions array, it also fulfills the complexity requirements - if (COMPLEXITY_EXCEPTIONS.includes(label) && requiredLabel === 'Complexity') { + if (COMPLEXITY_EXCEPTIONS.includes(label) && requiredLabel === 'complexity') { return true; } @@ -97,7 +125,7 @@ function checkLabels(labels) { labelsToAdd.push(LABEL_MISSING[i]); } }) - + return labelsToAdd; } diff --git a/github-actions/utils/_data/status-field-ids.js b/github-actions/utils/_data/status-field-ids.js index 101532db3a..e72d3e6495 100644 --- a/github-actions/utils/_data/status-field-ids.js +++ b/github-actions/utils/_data/status-field-ids.js @@ -1,7 +1,7 @@ /** * The purpose of this utility is to list the (non-changing) GraphQL ids of the 'Status' fields - * for the Website Project so that functions will not need to run a GraphQL query when needed - * SEE BELOW for GraphQL query used to generate this list + * for the Website Project so that functions will not need to run a GraphQL query each time + * SEE BELOW for GraphQL query used to generate the values from this list * * @params {String} statusField - Standardized name of status field (see lines 10-27) * @returns {String} statusId - the field id of the selected status @@ -10,6 +10,12 @@ function statusFieldIds(statusField) { const statusValues = new Map([ + + // Default values for HfLA Website Project 86 + ["PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"], + ["FIELD_ID", "PVTSSF_lADOALGKNs4AjuckzgcCutQ"], + + // Individual Status field values ["Agendas", "864392c1"], ["Ice_Box", "2b49cbab"], ["Emergent_Requests", "d468e876"], @@ -40,15 +46,13 @@ query findStatusSubfieldIds ($login: String!, $projNum: Int!, $fieldName: String organization(login: $login) { projectV2(number: $projNum) { id - field(name:$fieldName) { - ... on ProjectV2SingleSelectField { - id options{ + field(name: $fieldName) { + ... on ProjectV2SingleSelectField { + id + options { id name - ... on ProjectV2SingleSelectFieldOption { - id - } - } + } } } } @@ -56,9 +60,9 @@ query findStatusSubfieldIds ($login: String!, $projNum: Int!, $fieldName: String } { - "login":"hackforla", + "login": "hackforla", "projNum": 86, - "fieldName": "Status" + "fieldName": "Status" } */ diff --git a/github-actions/utils/mutate-issue-status.js b/github-actions/utils/mutate-issue-status.js index 5e4f335ff3..fea00e687e 100644 --- a/github-actions/utils/mutate-issue-status.js +++ b/github-actions/utils/mutate-issue-status.js @@ -1,3 +1,6 @@ +// Import modules +const statusFieldIds = require('./_data/status-field-ids'); + /** * Changes the 'Status' of an issue (with the corresponding itemId) to a newStatusValue * @param {String} itemId - GraphQL item Id for the issue @@ -11,8 +14,8 @@ async function mutateIssueStatus( newStatusValue ) { // Defaults for HfLA Website Project 86 - const WEBSITE_PROJECT_ID = 'PVT_kwDOALGKNs4Ajuck'; - const STATUS_FIELD_ID = 'PVTSSF_lADOALGKNs4AjuckzgcCutQ'; + const PROJECT_ID = statusFieldIds("PROJECT_ID"); + const FIELD_ID = statusFieldIds("FIELD_ID"); const mutation = `mutation($projectId: ID!, $fieldId: ID!, $itemId: ID!, $value: String!) { updateProjectV2ItemFieldValue(input: { @@ -30,8 +33,8 @@ async function mutateIssueStatus( }`; const variables = { - projectId: WEBSITE_PROJECT_ID, - fieldId: STATUS_FIELD_ID, + projectId: PROJECT_ID, + fieldId: FIELD_ID, itemId: itemId, value: newStatusValue, }; @@ -39,7 +42,7 @@ async function mutateIssueStatus( try { await github.graphql(mutation, variables); } catch (error) { - throw new Error('Error in mutateItemStatus() function: ' + error); + throw new Error('Error in mutateIssueStatus() function: ' + error); } }