From 67fe06ffa24742028f2d4fc4ad5b216d1cfc5eeb Mon Sep 17 00:00:00 2001 From: Francois G Date: Tue, 7 Mar 2023 15:03:58 +0100 Subject: [PATCH] Fixed linting --- cli/src/commands/versions.ts | 38 ++++++------- cli/src/utils/jira/fetchVersions.ts | 20 ++++--- cli/src/utils/versions/getIssues.ts | 26 +++++---- cli/src/utils/versions/getVersions.ts | 16 ++---- cli/src/utils/versions/groupVersions.ts | 72 ++++++++++--------------- cli/src/utils/versions/trimIssues.ts | 15 +----- 6 files changed, 76 insertions(+), 111 deletions(-) diff --git a/cli/src/commands/versions.ts b/cli/src/commands/versions.ts index 74b420e..a5f3645 100644 --- a/cli/src/commands/versions.ts +++ b/cli/src/commands/versions.ts @@ -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'); @@ -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, }, }), ); diff --git a/cli/src/utils/jira/fetchVersions.ts b/cli/src/utils/jira/fetchVersions.ts index d22c062..4df8890 100644 --- a/cli/src/utils/jira/fetchVersions.ts +++ b/cli/src/utils/jira/fetchVersions.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import { values } from 'lodash'; import { UserConfigJira } from '../../global'; @@ -9,8 +8,8 @@ const paginateVersion = async ( versions: Array, 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`, @@ -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; diff --git a/cli/src/utils/versions/getIssues.ts b/cli/src/utils/versions/getIssues.ts index cbf40dc..c1d7dca 100644 --- a/cli/src/utils/versions/getIssues.ts +++ b/cli/src/utils/versions/getIssues.ts @@ -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'; @@ -25,7 +23,7 @@ const getIssues = async ( ) => { cli.action.start(`${version.name}: Begin fetching issues for this version`); - let issues: Array = []; + const issues: Array = []; const versionsFolder = path.join(cacheDir, 'versions'); // Create folder to be used to store the versions cache @@ -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) { diff --git a/cli/src/utils/versions/getVersions.ts b/cli/src/utils/versions/getVersions.ts index 7df55ef..2a3cf24 100644 --- a/cli/src/utils/versions/getVersions.ts +++ b/cli/src/utils/versions/getVersions.ts @@ -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 @@ -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, }; }); diff --git a/cli/src/utils/versions/groupVersions.ts b/cli/src/utils/versions/groupVersions.ts index f645405..8ccdc23 100644 --- a/cli/src/utils/versions/groupVersions.ts +++ b/cli/src/utils/versions/groupVersions.ts @@ -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 */ @@ -38,37 +25,36 @@ const groupVersions = (versions: Array) => { ], }); 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; + }); }, []); }; diff --git a/cli/src/utils/versions/trimIssues.ts b/cli/src/utils/versions/trimIssues.ts index 5d75728..b3d7fc9 100644 --- a/cli/src/utils/versions/trimIssues.ts +++ b/cli/src/utils/versions/trimIssues.ts @@ -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) => { return issues.map(issue => { - let trimmedIssue: any = {}; + const trimmedIssue: any = {}; if (issue.key !== undefined) { trimmedIssue.key = issue.key; }