Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring check-labels.js to use label-directory.json #7777

Open
wants to merge 5 commits into
base: gh-pages
Choose a base branch
from
Open
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -97,7 +125,7 @@ function checkLabels(labels) {
labelsToAdd.push(LABEL_MISSING[i]);
}
})

return labelsToAdd;
}

Expand Down
26 changes: 15 additions & 11 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
["PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"],
["FIELD_ID", "PVTSSF_lADOALGKNs4AjuckzgcCutQ"],

// Individual Status field values
["Agendas", "864392c1"],
["Ice_Box", "2b49cbab"],
["Emergent_Requests", "d468e876"],
Expand Down Expand Up @@ -40,25 +46,23 @@ 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"
"fieldName": "Status"
}
*/

Expand Down
13 changes: 8 additions & 5 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('./_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 PROJECT_ID = statusFieldIds("PROJECT_ID");
const FIELD_ID = statusFieldIds("FIELD_ID");

const mutation = `mutation($projectId: ID!, $fieldId: ID!, $itemId: ID!, $value: String!) {
updateProjectV2ItemFieldValue(input: {
Expand All @@ -30,16 +33,16 @@ async function mutateIssueStatus(
}`;

const variables = {
projectId: WEBSITE_PROJECT_ID,
fieldId: STATUS_FIELD_ID,
projectId: PROJECT_ID,
fieldId: FIELD_ID,
itemId: itemId,
value: newStatusValue,
};

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