Skip to content

Commit

Permalink
added labelKeys, moved hard coded vales to status-field-ids.js
Browse files Browse the repository at this point in the history
  • Loading branch information
t-will-gillis committed Nov 28, 2024
1 parent 11a5f3d commit c133ebb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
})

Expand Down
24 changes: 14 additions & 10 deletions github-actions/utils/_data/status-field-ids.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"],
Expand Down Expand Up @@ -40,23 +46,21 @@ 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
}
}
}
}
}
}
}
}
{
"login":"hackforla",
"login": "hackforla",
"projNum": 86,
"fieldName": "Status"
}
Expand Down
9 changes: 6 additions & 3 deletions github-actions/utils/mutate-issue-status.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: {
Expand All @@ -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);
}
}

Expand Down

0 comments on commit c133ebb

Please sign in to comment.