-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version filter on project revision/revisions and add version and …
…check-reviewed flags on CLI
- Loading branch information
Showing
7 changed files
with
127 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,65 @@ | ||
// Vendor | ||
import * as chalk from 'chalk'; | ||
|
||
// Command | ||
import {flags} from '@oclif/command'; | ||
import Command, {configFlag} from '../base'; | ||
import {CLIError} from '@oclif/errors'; | ||
|
||
// Services | ||
import Formatter from '../services/formatters/project-stats'; | ||
import ProjectFetcher from '../services/project-fetcher'; | ||
import {Revision} from '../types/project'; | ||
|
||
export default class Stats extends Command { | ||
static description = 'Fetch stats from the API and display it beautifully'; | ||
static description = 'Fetch stats from the API and display them beautifully'; | ||
|
||
static examples = [`$ accent stats`]; | ||
static flags = {config: configFlag}; | ||
static flags = { | ||
version: flags.string({ | ||
default: undefined, | ||
description: 'View stats for a specific version', | ||
}), | ||
'check-reviewed': flags.boolean({ | ||
description: 'Exit 1 when reviewed percentage is not 100%', | ||
}), | ||
config: configFlag, | ||
}; | ||
|
||
/* eslint-disable @typescript-eslint/require-await */ | ||
async run() { | ||
const formatter = new Formatter(this.project!, this.projectConfig.config); | ||
const {flags} = this.parse(Stats); | ||
|
||
if (flags.version) { | ||
const config = this.projectConfig.config; | ||
const fetcher = new ProjectFetcher(); | ||
const response = await fetcher.fetch(config, {versionId: flags.version}); | ||
|
||
this.project = response.project; | ||
} | ||
|
||
const formatter = new Formatter( | ||
this.project!, | ||
this.projectConfig.config, | ||
flags.version | ||
); | ||
|
||
formatter.log(); | ||
|
||
if (flags['check-reviewed']) { | ||
const conflictsCount = this.project!.revisions.reduce( | ||
(memo, revision: Revision) => memo + revision.conflictsCount, | ||
0 | ||
); | ||
|
||
if (conflictsCount !== 0) { | ||
const versionFormat = flags.version ? ` ${flags.version}` : ''; | ||
throw new CLIError( | ||
chalk.red( | ||
`Project${versionFormat} has ${conflictsCount} strings to be reviewed` | ||
), | ||
{exit: 1} | ||
); | ||
} | ||
} | ||
} | ||
/* eslint-enable @typescript-eslint/require-await */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters