Skip to content

Commit 4c08437

Browse files
Refactoring check-labels.js to use label-directory.json (#7777)
* added labelKeys, moved hard coded vales to status-field-ids.js * hard-code status-field-ids only * add back 'COMPLEXITY_EXCEPTIONS' - still needed * fix 'Complexity' --> 'complexity' * Update status-field-ids.js Fix indent in comments section
1 parent ac60169 commit 4c08437

File tree

3 files changed

+58
-23
lines changed

3 files changed

+58
-23
lines changed

github-actions/trigger-issue/add-missing-labels-to-issues/check-labels.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,42 @@
22
const statusFieldIds = require('../../utils/_data/status-field-ids');
33
const queryIssueInfo = require('../../utils/query-issue-info');
44
const mutateIssueStatus = require('../../utils/mutate-issue-status');
5+
const retrieveLabelDirectory = require('../../utils/retrieve-label-directory');
6+
7+
// Use labelKeys to retrieve current labelNames from directory
8+
const [
9+
sizeMissing,
10+
featureMissing,
11+
complexityMissing,
12+
roleMissing,
13+
complexity1,
14+
complexity2,
15+
readyForDevLead,
16+
featureAdministrative,
17+
size025pt,
18+
roleDevLeads
19+
] = [
20+
"sizeMissing",
21+
"featureMissing",
22+
"complexityMissing",
23+
"roleMissing",
24+
"complexity1",
25+
"complexity2",
26+
"readyForDevLead",
27+
"featureAdministrative",
28+
"size025pt",
29+
"roleDevLeads"
30+
].map(retrieveLabelDirectory);
531

632
// Constant variables
7-
const REQUIRED_LABELS = ['Complexity', 'role', 'Feature', 'size'];
8-
const LABEL_MISSING = ['Complexity: Missing', 'role missing', 'Feature Missing', 'size: missing'];
9-
const COMPLEXITY_EXCEPTIONS = ['good first issue'];
33+
const REQUIRED_LABELS = ['complexity', 'role', 'feature', 'size'];
34+
const LABEL_MISSING = [complexityMissing, roleMissing, featureMissing, sizeMissing];
35+
// Exception for the `good first issue` label
36+
const COMPLEXITY_EXCEPTIONS = [complexity1];
1037

11-
// SPECIAL_CASE is for issue created by reference with issue title "Hack for LA website bot" (from "Review Inactive Team Members")
12-
const SPECIAL_CASE = ['ready for dev lead','Feature: Administrative','size: 0.25pt','Complexity: Small','role: dev leads'];
38+
// SPECIAL_CASE is for issue created by reference with issue title "Hack for LA website bot"
39+
// ("Review Inactive Team Members" from the "Schedule Monthly" workflow)
40+
const SPECIAL_CASE = [readyForDevLead, featureAdministrative, size025pt, complexity2, roleDevLeads];
1341

1442
// Global variables
1543
var github;
@@ -86,7 +114,7 @@ function checkLabels(labels) {
86114
const regExp = new RegExp(`\\b${requiredLabel}\\b`, 'gi');
87115
const isLabelPresent = labels.some(label => {
88116
// If the label is in the complexity exceptions array, it also fulfills the complexity requirements
89-
if (COMPLEXITY_EXCEPTIONS.includes(label) && requiredLabel === 'Complexity') {
117+
if (COMPLEXITY_EXCEPTIONS.includes(label) && requiredLabel === 'complexity') {
90118
return true;
91119
}
92120

@@ -97,7 +125,7 @@ function checkLabels(labels) {
97125
labelsToAdd.push(LABEL_MISSING[i]);
98126
}
99127
})
100-
128+
101129
return labelsToAdd;
102130
}
103131

github-actions/utils/_data/status-field-ids.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The purpose of this utility is to list the (non-changing) GraphQL ids of the 'Status' fields
3-
* for the Website Project so that functions will not need to run a GraphQL query when needed
4-
* SEE BELOW for GraphQL query used to generate this list
3+
* for the Website Project so that functions will not need to run a GraphQL query each time
4+
* SEE BELOW for GraphQL query used to generate the values from this list
55
*
66
* @params {String} statusField - Standardized name of status field (see lines 10-27)
77
* @returns {String} statusId - the field id of the selected status
@@ -10,6 +10,12 @@
1010
function statusFieldIds(statusField) {
1111

1212
const statusValues = new Map([
13+
14+
// Default values for HfLA Website Project 86
15+
["PROJECT_ID", "PVT_kwDOALGKNs4Ajuck"],
16+
["FIELD_ID", "PVTSSF_lADOALGKNs4AjuckzgcCutQ"],
17+
18+
// Individual Status field values
1319
["Agendas", "864392c1"],
1420
["Ice_Box", "2b49cbab"],
1521
["Emergent_Requests", "d468e876"],
@@ -40,25 +46,23 @@ query findStatusSubfieldIds ($login: String!, $projNum: Int!, $fieldName: String
4046
organization(login: $login) {
4147
projectV2(number: $projNum) {
4248
id
43-
field(name:$fieldName) {
44-
... on ProjectV2SingleSelectField {
45-
id options{
49+
field(name: $fieldName) {
50+
... on ProjectV2SingleSelectField {
51+
id
52+
options {
4653
id
4754
name
48-
... on ProjectV2SingleSelectFieldOption {
49-
id
50-
}
51-
}
55+
}
5256
}
5357
}
5458
}
5559
}
5660
}
5761
5862
{
59-
"login":"hackforla",
63+
"login": "hackforla",
6064
"projNum": 86,
61-
"fieldName": "Status"
65+
"fieldName": "Status"
6266
}
6367
*/
6468

github-actions/utils/mutate-issue-status.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Import modules
2+
const statusFieldIds = require('./_data/status-field-ids');
3+
14
/**
25
* Changes the 'Status' of an issue (with the corresponding itemId) to a newStatusValue
36
* @param {String} itemId - GraphQL item Id for the issue
@@ -11,8 +14,8 @@ async function mutateIssueStatus(
1114
newStatusValue
1215
) {
1316
// Defaults for HfLA Website Project 86
14-
const WEBSITE_PROJECT_ID = 'PVT_kwDOALGKNs4Ajuck';
15-
const STATUS_FIELD_ID = 'PVTSSF_lADOALGKNs4AjuckzgcCutQ';
17+
const PROJECT_ID = statusFieldIds("PROJECT_ID");
18+
const FIELD_ID = statusFieldIds("FIELD_ID");
1619

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

3235
const variables = {
33-
projectId: WEBSITE_PROJECT_ID,
34-
fieldId: STATUS_FIELD_ID,
36+
projectId: PROJECT_ID,
37+
fieldId: FIELD_ID,
3538
itemId: itemId,
3639
value: newStatusValue,
3740
};
3841

3942
try {
4043
await github.graphql(mutation, variables);
4144
} catch (error) {
42-
throw new Error('Error in mutateItemStatus() function: ' + error);
45+
throw new Error('Error in mutateIssueStatus() function: ' + error);
4346
}
4447
}
4548

0 commit comments

Comments
 (0)