Skip to content

Commit

Permalink
Fixed linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgerthoffert committed Mar 7, 2023
1 parent 1cbe59c commit 67fe06f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 111 deletions.
38 changes: 16 additions & 22 deletions cli/src/commands/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ const sortByNameDesc = (a: any, b: any) => {
return comparison;
};

export default class Streams extends Command {
export default class Versions extends Command {
static description = 'Fetches details about completed versions';

static flags = {
...Command.flags,
help: flags.help({ char: 'h' }),
useCache: flags.boolean({
char: 'c',
default: false,
description: 'Use local cache instead of fetching the data from Jira',
}),
};

async run() {
const { flags } = this.parse(Streams);
const userConfig = this.userConfig;
const cacheDir = path.join(this.config.configDir, 'cache');

Expand Down Expand Up @@ -119,25 +113,25 @@ export default class Streams extends Command {
monthsToChart: userConfig.versions.monthsToChart,
defaultFilters: {
name:
userConfig.versions.defaultFilters.name !== undefined
? userConfig.versions.defaultFilters.name
: '',
userConfig.versions.defaultFilters.name === undefined
? ''
: userConfig.versions.defaultFilters.name,
projectKey:
userConfig.versions.defaultFilters.projectKey !== undefined
? userConfig.versions.defaultFilters.projectKey
: '',
userConfig.versions.defaultFilters.projectKey === undefined
? ''
: userConfig.versions.defaultFilters.projectKey,
label:
userConfig.versions.defaultFilters.label !== undefined
? userConfig.versions.defaultFilters.label
: '',
userConfig.versions.defaultFilters.label === undefined
? ''
: userConfig.versions.defaultFilters.label,
issueType:
userConfig.versions.defaultFilters.issueType !== undefined
? userConfig.versions.defaultFilters.issueType
: '',
userConfig.versions.defaultFilters.issueType === undefined
? ''
: userConfig.versions.defaultFilters.issueType,
priority:
userConfig.versions.defaultFilters.priority !== undefined
? userConfig.versions.defaultFilters.priority
: '',
userConfig.versions.defaultFilters.priority === undefined
? ''
: userConfig.versions.defaultFilters.priority,
},
}),
);
Expand Down
20 changes: 13 additions & 7 deletions cli/src/utils/jira/fetchVersions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
import { values } from 'lodash';

import { UserConfigJira } from '../../global';

Expand All @@ -9,8 +8,8 @@ const paginateVersion = async (
versions: Array<any>,
startAt: number,
) => {
const resultsCount = 100
console.log(`Fetching ${resultsCount} records from position: ${startAt}`)
const resultsCount = 100;
console.log(`Fetching ${resultsCount} records from position: ${startAt}`);
const response = await axios({
method: 'get',
url: `${jiraConfig.host}/rest/api/2/project/${projectKey}/version`,
Expand All @@ -24,19 +23,26 @@ const paginateVersion = async (
},
});
if (response.data.values.length > 0) {
versions = [...versions, ...response.data.values]
versions = [...versions, ...response.data.values];
}
if (response.data.isLast === false) {
return await paginateVersion(jiraConfig, projectKey, versions, startAt + resultsCount)
const recVersions: any = await paginateVersion(
jiraConfig,
projectKey,
versions,
startAt + resultsCount,
);
return recVersions;
}
return versions;
};
};

const jiraFetchVersions = async (
jiraConfig: UserConfigJira,
projectKey: string,
) => {
return await paginateVersion(jiraConfig, projectKey, [], 0)
const versions = await paginateVersion(jiraConfig, projectKey, [], 0);
return versions;
};

export default jiraFetchVersions;
26 changes: 12 additions & 14 deletions cli/src/utils/versions/getIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import * as fs from 'fs';
import * as path from 'path';
import * as fsNdjson from 'fs-ndjson';

import { IJiraIssue, UserConfigTeam, UserConfigJira } from '../../global';
import { IJiraIssue, UserConfigJira } from '../../global';
import jiraSearchIssues from '../jira/searchIssues';
import { formatDate, getDaysBetweenDates } from '../misc/dateUtils';
import { differenceInBusinessDays, startOfDay, parse } from 'date-fns';
import { getTeamId } from '../misc/teamUtils';
import { differenceInBusinessDays } from 'date-fns';
import { getId } from '../misc/id';
import { returnTicketsPoints } from '../misc/jiraUtils';

Expand All @@ -25,7 +23,7 @@ const getIssues = async (
) => {
cli.action.start(`${version.name}: Begin fetching issues for this version`);

let issues: Array<IJiraIssue> = [];
const issues: Array<IJiraIssue> = [];

const versionsFolder = path.join(cacheDir, 'versions');
// Create folder to be used to store the versions cache
Expand Down Expand Up @@ -63,15 +61,15 @@ const getIssues = async (
console.log(version.name, ' - No release date present');
}
for (const issue of issuesJira) {
let daysToRelease,
weeksToRelease,
monthsToRelease = undefined;
let daysToReleaseIfToday,
weeksToReleaseIfToday,
monthsToReleaseIfToday = undefined;
let daysToResolution,
weeksToResolution,
monthsToResolution = undefined;
let daysToRelease;
let weeksToRelease;
let monthsToRelease;
let daysToReleaseIfToday;
let weeksToReleaseIfToday;
let monthsToReleaseIfToday;
let daysToResolution;
let weeksToResolution;
let monthsToResolution;

// Verify the release date is present
if (version.releaseDate !== undefined) {
Expand Down
16 changes: 4 additions & 12 deletions cli/src/utils/versions/getVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
/* eslint-env es6 */

import cli from 'cli-ux';
import * as fs from 'fs';
import * as path from 'path';
import * as fsNdjson from 'fs-ndjson';
import { parse } from 'date-fns';

import { IJiraIssue, UserConfigTeam, UserConfigJira } from '../../global';
import { UserConfigJira } from '../../global';
import jiraFetchVersions from '../jira/fetchVersions';
import { formatDate, getDaysBetweenDates } from '../misc/dateUtils';
import { differenceInBusinessDays, startOfDay } from 'date-fns';
import { getTeamId } from '../misc/teamUtils';
import { getId } from '../misc/id';
import { returnTicketsPoints } from '../misc/jiraUtils';

/*
Fetches all completed issues, per day from a team
Expand All @@ -28,9 +20,9 @@ const getVersions = async (projectKey: string, jiraConfig: UserConfigJira) => {
return {
...v,
releaseDate:
v.releaseDate !== undefined
? parse(v.releaseDate, 'yyyy-MM-dd', new Date())
: undefined,
v.releaseDate === undefined
? undefined
: parse(v.releaseDate, 'yyyy-MM-dd', new Date()),
projectKey: projectKey,
};
});
Expand Down
72 changes: 29 additions & 43 deletions cli/src/utils/versions/groupVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
/* eslint max-params: ["error", 7] */
/* eslint-env es6 */

import cli from 'cli-ux';
import * as fs from 'fs';
import * as path from 'path';
import * as fsNdjson from 'fs-ndjson';

import { IJiraIssue, UserConfigTeam, UserConfigJira } from '../../global';
import jiraFetchVersions from '../jira/fetchVersions';
import { formatDate, getDaysBetweenDates } from '../misc/dateUtils';
import { differenceInBusinessDays, startOfDay } from 'date-fns';
import { getTeamId } from '../misc/teamUtils';
import { getId } from '../misc/id';
import { returnTicketsPoints } from '../misc/jiraUtils';

/*
Group all versions by name
*/
Expand All @@ -38,37 +25,36 @@ const groupVersions = (versions: Array<any>) => {
],
});
return acc;
} else {
return acc.map((a: any) => {
if (a.name === v.name) {
const projects = a.projects;
if (
a.projects.find((p: any) => p.projectKey === v.projectKey) ===
undefined
) {
projects.push({
projectId: v.projectId,
projectKey: v.projectKey,
versionId: v.id,
});
}
const releaseDate =
a.releaseDate === undefined ? v.releaseDate : a.releaseDate;
const userReleaseDate =
a.userReleaseDate === undefined
? v.userReleaseDate
: a.userReleaseDate;
if (a.release)
return {
...a,
releaseDate,
userReleaseDate,
projects,
};
}
return a;
});
}
return acc.map((a: any) => {
if (a.name === v.name) {
const projects = a.projects;
if (
a.projects.find((p: any) => p.projectKey === v.projectKey) ===
undefined
) {
projects.push({
projectId: v.projectId,
projectKey: v.projectKey,
versionId: v.id,
});
}
const releaseDate =
a.releaseDate === undefined ? v.releaseDate : a.releaseDate;
const userReleaseDate =
a.userReleaseDate === undefined
? v.userReleaseDate
: a.userReleaseDate;
if (a.release)
return {
...a,
releaseDate,
userReleaseDate,
projects,
};
}
return a;
});
}, []);
};

Expand Down
15 changes: 2 additions & 13 deletions cli/src/utils/versions/trimIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@
/* eslint max-params: ["error", 7] */
/* eslint-env es6 */

import cli from 'cli-ux';
import * as fs from 'fs';
import * as path from 'path';
import * as fsNdjson from 'fs-ndjson';

import { IJiraIssue, UserConfigTeam, UserConfigJira } from '../../global';
import jiraFetchVersions from '../jira/fetchVersions';
import { formatDate, getDaysBetweenDates } from '../misc/dateUtils';
import { differenceInBusinessDays, startOfDay } from 'date-fns';
import { getTeamId } from '../misc/teamUtils';
import { getId } from '../misc/id';
import { returnTicketsPoints } from '../misc/jiraUtils';
import { IJiraIssue } from '../../global';

/*
Trim issues to keep only the most important details
*/
const trimIssues = (issues: Array<IJiraIssue>) => {
return issues.map(issue => {
let trimmedIssue: any = {};
const trimmedIssue: any = {};
if (issue.key !== undefined) {
trimmedIssue.key = issue.key;
}
Expand Down

0 comments on commit 67fe06f

Please sign in to comment.