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

Case insensitive status names #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 23 additions & 5 deletions src/components/staging-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ const addResolutionDateToClosedStage = (issue: JiraApiIssue, stageMap, stageBins
return stageBins;
};

const caseInsensetiveGet = (map: Map<string, any>, keyToGet: string) => {
const lowerCaseKeyToGet = keyToGet.toLowerCase()
const entries = [...map.entries()]
const found = entries.find(entry => entry[0].toLowerCase() === lowerCaseKeyToGet)
return found !== undefined ? found[1] : undefined
}

const caseInsensetiveHas = (map: Map<string, any>, keyToCheck: string) => {
return caseInsensetiveGet(map, keyToCheck) !== undefined
}


const populateStages = (issue: JiraApiIssue, stageMap, stageBins, unusedStages = new Map<string, number>()) => {
// sort status changes into stage bins
issue.changelog.histories.forEach(history => {
history.items.forEach(historyItem => {
const stageName: string = historyItem.toString;
const stageDate: string = history['created'];

if (historyItem['field'] === 'status') {
const stageName: string = historyItem.toString;
if (stageMap.has(stageName)) {
const stageIndex: number = stageMap.get(stageName);
const stageDate: string = history['created'];
stageBins[stageIndex].push(stageDate);
} else if (caseInsensetiveHas(stageMap, stageName)) {
const stageIndex: number = caseInsensetiveGet(stageMap, stageName);
stageBins[stageIndex].push(stageDate);
} else {
const count: number = unusedStages.has(stageName) ? unusedStages.get(stageName) : 0;
unusedStages.set(stageName, count + 1);
Expand All @@ -41,9 +57,11 @@ const populateStages = (issue: JiraApiIssue, stageMap, stageBins, unusedStages =
const stageName: string = historyItem.toString;
if (stageMap.has(stageName)) {
const stageIndex: number = stageMap.get(stageName);
const stageDate: string = history['created'];
stageBins[stageIndex].push(stageDate);
} else {
} else if (caseInsensetiveHas(stageMap, stageName)) {
const stageIndex: number = caseInsensetiveGet(stageMap, stageName);
stageBins[stageIndex].push(stageDate);
} else {
const count: number = unusedStages.has(stageName) ? unusedStages.get(stageName) : 0;
unusedStages.set(stageName, count + 1);
}
Expand All @@ -64,7 +82,7 @@ const filterAndFlattenStagingDates = (stageBins: string[][]) => {
validStageDates.sort();
latestValidIssueDateSoFar = validStageDates[validStageDates.length - 1];
const earliestStageDate = validStageDates[0];
return earliestStageDate.split('T')[0];
return earliestStageDate.split('T')[0];
} else {
return '';
}
Expand Down