-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support multiple output file formats #160
Open
Vedmax
wants to merge
1
commit into
codeleague:main
Choose a base branch
from
Vedmax:multiple-output-format-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 +0,0 @@ | ||
export enum OutputFormat { | ||
default = 'default', | ||
gitlab = 'gitlab', | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const DEFAULT_OUTPUT_FILE = 'build.json'; | ||
export const DEFAULT_OUTPUT_FILE = 'output.json'; | ||
|
||
export const USER_AGENT = 'CodeCoach'; | ||
export const TIME_ZONE = 'Asia/Bangkok'; |
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 |
---|---|---|
|
@@ -5,16 +5,16 @@ import { File } from './File'; | |
import { Log } from './Logger'; | ||
import { | ||
AndroidLintStyleParser, | ||
DartLintParser, | ||
DotnetBuildParser, | ||
ESLintParser, | ||
JscpdParser, | ||
LintItem, | ||
MSBuildParser, | ||
Parser, | ||
ScalaStyleParser, | ||
TSLintParser, | ||
DartLintParser, | ||
SwiftLintParser, | ||
JscpdParser, | ||
TSLintParser, | ||
} from './Parser'; | ||
import { GitHubPRService, VCS } from './Provider'; | ||
import { GitLabMRService } from './Provider/GitLab/GitLabMRService'; | ||
|
@@ -23,15 +23,16 @@ import { VCSEngine } from './Provider/CommonVCS/VCSEngine'; | |
import { GitLabAdapter } from './Provider/GitLab/GitLabAdapter'; | ||
import { VCSAdapter } from './Provider/@interfaces/VCSAdapter'; | ||
import { AnalyzerBot } from './AnalyzerBot/AnalyzerBot'; | ||
import { | ||
defaultFormatter, | ||
gitLabFormatter, | ||
OutputFormatter, | ||
} from './OutputFormatter/OutputFormatter'; | ||
import { defaultFormatter, gitLabFormatter } from './OutputFormatter/OutputFormatter'; | ||
|
||
type OutputFileMeta = { | ||
formatter: (items: LintItem[]) => string; | ||
filename: string; | ||
}; | ||
|
||
class App { | ||
private vcs: VCS | null = null; | ||
private outputFormatter: OutputFormatter; | ||
private outputFileMeta: OutputFileMeta[]; | ||
|
||
async start(): Promise<void> { | ||
if (!configs.dryRun) { | ||
|
@@ -44,14 +45,14 @@ class App { | |
this.vcs = new VCSEngine(configs, analyzer, adapter); | ||
} | ||
|
||
this.outputFormatter = App.getOutputFormatter(); | ||
this.outputFileMeta = App.getOutputFileMetas(); | ||
|
||
const logs = await this.parseBuildData(configs.buildLogFile); | ||
Log.info('Build data parsing completed'); | ||
|
||
const reportToVcs = this.reportToVcs(logs); | ||
const writeOutputFile = this.writeOutputFile(logs); | ||
const [passed] = await Promise.all([reportToVcs, writeOutputFile]); | ||
const writeOutputFiles = this.writeOutputFiles(logs); | ||
const [passed] = await Promise.all([reportToVcs, writeOutputFiles]); | ||
if (!passed) { | ||
Log.error('There are some linting error and exit code reporting is enabled'); | ||
process.exit(1); | ||
|
@@ -94,13 +95,19 @@ class App { | |
} | ||
} | ||
|
||
private static getOutputFormatter(): OutputFormatter { | ||
switch (configs.outputFormat) { | ||
case 'default': | ||
return defaultFormatter; | ||
case 'gitlab': | ||
return gitLabFormatter; | ||
private static getOutputFileMetas(): OutputFileMeta[] { | ||
const outputFileMetas: OutputFileMeta[] = []; | ||
if (configs.outputFormat.includes('default')) { | ||
outputFileMetas.push({ formatter: defaultFormatter, filename: configs.output }); | ||
} | ||
if (configs.outputFormat.includes('gitlab')) { | ||
outputFileMetas.push({ | ||
formatter: gitLabFormatter, | ||
filename: 'gl-code-quality-report.json', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should let users set the filename for gitlab or any other format if we have in the future as well. |
||
}); | ||
} | ||
|
||
return outputFileMetas; | ||
} | ||
|
||
private async parseBuildData(files: BuildLogFile[]): Promise<LintItem[]> { | ||
|
@@ -130,9 +137,15 @@ class App { | |
} | ||
} | ||
|
||
private async writeOutputFile(items: LintItem[]): Promise<void> { | ||
private async writeOutputFiles(items: LintItem[]): Promise<void> { | ||
try { | ||
await File.writeFileHelper(configs.output, this.outputFormatter(items)); | ||
await Promise.all( | ||
this.outputFileMeta.map((meta) => { | ||
Log.info('Write output to ' + meta.filename, { meta }); | ||
return File.writeFileHelper(meta.filename, meta.formatter(items)); | ||
}), | ||
); | ||
|
||
Log.info('Write output completed'); | ||
} catch (error) { | ||
Log.error('Write output failed', { error }); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this is going to be a breaking change