From c133ebb4eccedcc121155df15421903f26c47d3e Mon Sep 17 00:00:00 2001 From: t-will-gillis <40799239+t-will-gillis@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:11:16 -0800 Subject: [PATCH 1/5] added labelKeys, moved hard coded vales to status-field-ids.js --- .../check-labels.js | 40 ++++++++++++++----- .../utils/_data/status-field-ids.js | 24 ++++++----- github-actions/utils/mutate-issue-status.js | 9 +++-- 3 files changed, 50 insertions(+), 23 deletions(-) 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..89544ff993 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,39 @@ 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, + complexity2, + readyForDevLead, + featureAdministrative, + size025pt, + roleDevLeads +] = [ + "sizeMissing", + "featureMissing", + "complexityMissing", + "roleMissing", + "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]; -// 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" +// (from "Review Inactive Team Members", "Schedule Monthly" workflow) +const SPECIAL_CASE = [readyForDevLead, featureAdministrative, size025pt, complexity2, roleDevLeads]; // Global variables var github; @@ -85,11 +110,6 @@ function checkLabels(labels) { REQUIRED_LABELS.forEach((requiredLabel, i) => { 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') { - return true; - } - return regExp.test(label); }) diff --git a/github-actions/utils/_data/status-field-ids.js b/github-actions/utils/_data/status-field-ids.js index 101532db3a..48d78b7521 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 + ["WEBSITE_PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"], + ["STATUS_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,7 +60,7 @@ query findStatusSubfieldIds ($login: String!, $projNum: Int!, $fieldName: String } { - "login":"hackforla", + "login": "hackforla", "projNum": 86, "fieldName": "Status" } diff --git a/github-actions/utils/mutate-issue-status.js b/github-actions/utils/mutate-issue-status.js index 5e4f335ff3..6f1961c045 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('../../utils/_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 WEBSITE_PROJECT_ID = statusFieldIds("WEBSITE_PROJECT_ID"); + const STATUS_FIELD_ID = statusFieldIds("STATUS_FIELD_ID"); const mutation = `mutation($projectId: ID!, $fieldId: ID!, $itemId: ID!, $value: String!) { updateProjectV2ItemFieldValue(input: { @@ -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); } } From b94894651faed105192c7d164f0f6fb6cb70b101 Mon Sep 17 00:00:00 2001 From: t-will-gillis <40799239+t-will-gillis@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:04:08 -0800 Subject: [PATCH 2/5] hard-code status-field-ids only --- github-actions/utils/_data/status-field-ids.js | 4 ++-- github-actions/utils/mutate-issue-status.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/github-actions/utils/_data/status-field-ids.js b/github-actions/utils/_data/status-field-ids.js index 48d78b7521..5e1651bfce 100644 --- a/github-actions/utils/_data/status-field-ids.js +++ b/github-actions/utils/_data/status-field-ids.js @@ -12,8 +12,8 @@ function statusFieldIds(statusField) { const statusValues = new Map([ // Default values for HfLA Website Project 86 - ["WEBSITE_PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"], - ["STATUS_FIELD_ID", "PVTSSF_lADOALGKNs4AjuckzgcCutQ"], + ["PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"], + ["FIELD_ID", "PVTSSF_lADOALGKNs4AjuckzgcCutQ"], // Individual Status field values ["Agendas", "864392c1"], diff --git a/github-actions/utils/mutate-issue-status.js b/github-actions/utils/mutate-issue-status.js index 6f1961c045..fea00e687e 100644 --- a/github-actions/utils/mutate-issue-status.js +++ b/github-actions/utils/mutate-issue-status.js @@ -1,5 +1,5 @@ // Import modules -const statusFieldIds = require('../../utils/_data/status-field-ids'); +const statusFieldIds = require('./_data/status-field-ids'); /** * Changes the 'Status' of an issue (with the corresponding itemId) to a newStatusValue @@ -14,8 +14,8 @@ async function mutateIssueStatus( newStatusValue ) { // Defaults for HfLA Website Project 86 - const WEBSITE_PROJECT_ID = statusFieldIds("WEBSITE_PROJECT_ID"); - const STATUS_FIELD_ID = statusFieldIds("STATUS_FIELD_ID"); + 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: { @@ -33,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, }; From aea587cfb7f9af10b4d7ada781f1dac4e49cf849 Mon Sep 17 00:00:00 2001 From: t-will-gillis <40799239+t-will-gillis@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:42:28 -0800 Subject: [PATCH 3/5] add back 'COMPLEXITY_EXCEPTIONS' - still needed --- .../add-missing-labels-to-issues/check-labels.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 89544ff993..76669d19da 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 @@ -10,6 +10,7 @@ const [ featureMissing, complexityMissing, roleMissing, + complexity1, complexity2, readyForDevLead, featureAdministrative, @@ -20,6 +21,7 @@ const [ "featureMissing", "complexityMissing", "roleMissing", + "complexity1", "complexity2", "readyForDevLead", "featureAdministrative", @@ -30,10 +32,11 @@ const [ // Constant variables 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", "Schedule Monthly" workflow) +// ("Review Inactive Team Members" from the "Schedule Monthly" workflow) const SPECIAL_CASE = [readyForDevLead, featureAdministrative, size025pt, complexity2, roleDevLeads]; // Global variables @@ -110,6 +113,11 @@ function checkLabels(labels) { REQUIRED_LABELS.forEach((requiredLabel, i) => { 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') { + return true; + } + return regExp.test(label); }) @@ -117,7 +125,7 @@ function checkLabels(labels) { labelsToAdd.push(LABEL_MISSING[i]); } }) - + return labelsToAdd; } From c398444df40b6bc89b4cc4f820f4cd720b0071db Mon Sep 17 00:00:00 2001 From: t-will-gillis <40799239+t-will-gillis@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:53:59 -0800 Subject: [PATCH 4/5] fix 'Complexity' --> 'complexity' --- .../trigger-issue/add-missing-labels-to-issues/check-labels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 76669d19da..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 @@ -114,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; } From 00899d0f2caf01f7c65f79b3e2723af3b6a6131c Mon Sep 17 00:00:00 2001 From: Will Gillis <40799239+t-will-gillis@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:51:15 -0800 Subject: [PATCH 5/5] Update status-field-ids.js Fix indent in comments section --- github-actions/utils/_data/status-field-ids.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-actions/utils/_data/status-field-ids.js b/github-actions/utils/_data/status-field-ids.js index 5e1651bfce..e72d3e6495 100644 --- a/github-actions/utils/_data/status-field-ids.js +++ b/github-actions/utils/_data/status-field-ids.js @@ -62,7 +62,7 @@ query findStatusSubfieldIds ($login: String!, $projNum: Int!, $fieldName: String { "login": "hackforla", "projNum": 86, - "fieldName": "Status" + "fieldName": "Status" } */