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

Remove default for max-warnings & max-errors #10

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,4 @@ jobs:
with:
filepath: './__tests__/testapi-oas.json'
apikey: ${{ secrets.RMOA_API_KEY }}
max-warnings: '57'
max-errors: '0'
minimum-score: '60'
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ See [action.yml](action.yml)
# The RMOA API Key issued when creating a user on https://api.ratemyopenapi.com/docs
apikey: ''

# The maximum number of warnings allowed before labeling the run as failed. Default is 5.
# The maximum number of warnings allowed before labeling the run as failed.
max-warnings: ''

# The maximum number of errors allowed before labeling the run as failed. Default is 0.
# The maximum number of errors allowed before labeling the run as failed.
max-errors: ''

# The minimum score (0 - 100) to label a lint run as successful/passing. Default is 80.
Expand Down
8 changes: 2 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ inputs:
required: true
max-warnings:
description:
'The maximum number of warnings allowed before labeling the run as failed.
Default is 5.'
default: '5'
'The maximum number of warnings allowed before labeling the run as failed.'
max-errors:
description:
'The maximum number of errors allowed before labeling the run as failed.
Default is 0.'
default: '0'
'The maximum number of errors allowed before labeling the run as failed.'
minimum-score:
description:
'The minimum score (0 - 100) to label a lint run as successful/passing.
Expand Down
54 changes: 18 additions & 36 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

80 changes: 42 additions & 38 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ import { APIResponse } from './interfaces'
import { ApiError } from '@zuplo/errors'

const failMark = '\x1b[31m✖\x1b[0m'

function generateScoreTableRow(
categoryName: string,
score: number,
numIssues: number
): string {
return `<tr style="border:none">
<td style="border:none">
<img src="https://api.ratemyopenapi.com/svg-generator?score=${score}" width="100px" style="width:100px;"/>
</td>
<td style="border:none">
<p><h3>${categoryName}</h3><span>${numIssues} issues</span></p>
</td>
</tr>`
}

/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
Expand All @@ -14,12 +30,12 @@ export async function run(): Promise<void> {
try {
const openApiFilePath: string = core.getInput('filepath')
const apikey: string = core.getInput('apikey')
const maxWarnings: number = core.getInput('max-warnings')
const maxWarnings: number | undefined = core.getInput('max-warnings')
? parseInt(core.getInput('max-warnings'), 10)
: 5
const maxErrors: number = core.getInput('max-errors')
: undefined
const maxErrors: number | undefined = core.getInput('max-errors')
? parseInt(core.getInput('max-errors'), 10)
: 0
: undefined
const minimumScore: number = core.getInput('minimum-score')
? parseInt(core.getInput('minimum-score'), 10)
: 80
Expand Down Expand Up @@ -125,44 +141,32 @@ export async function run(): Promise<void> {
'<table align="center" style="border-collapse: collapse; border: none;">'
)
.addRaw(
`<tr style="border:none">
<td style="border:none">
<img src="https://api.ratemyopenapi.com/svg-generator?score=${report.results.simpleReport.docsScore}" width="100px" style="width:100px;"/>
</td>
<td style="border:none">
<p><h3>Docs</h3><span>${report.results.fullReport.docsIssues.length} issues</span></p>
</td>
</tr>`
generateScoreTableRow(
'Docs',
report.results.simpleReport.docsScore,
report.results.fullReport.docsIssues.length
)
)
.addRaw(
`<tr style="border:none">
<td style="border:none">
<img src="https://api.ratemyopenapi.com/svg-generator?score=${report.results.simpleReport.completenessScore}" width="100px" style="width:100px;"/>
</td>
<td style="border:none">
<p><h3>Completeness</h3><span>${report.results.fullReport.completenessIssues.length} issues</span></p>
</td>
</tr>`
generateScoreTableRow(
'Completeness',
report.results.simpleReport.completenessScore,
report.results.fullReport.completenessIssues.length
)
)
.addRaw(
`<tr style="border:none">
<td style="border:none">
<img src="https://api.ratemyopenapi.com/svg-generator?score=${report.results.simpleReport.sdkGenerationScore}" width="100px" style="width:100px;"/>
</td>
<td style="border:none">
<p><h3>SDK Generation</h3><span>${report.results.fullReport.sdkGenerationIssues.length} issues</span></p>
</td>
</tr>`
generateScoreTableRow(
'SDK Generation',
report.results.simpleReport.sdkGenerationScore,
report.results.fullReport.sdkGenerationIssues.length
)
)
.addRaw(
`<tr style="border:none">
<td style="border:none">
<img src="https://api.ratemyopenapi.com/svg-generator?score=${report.results.simpleReport.securityScore}" width="100px" style="width:100px;"/>
</td>
<td style="border:none">
<p><h3>Security</h3><span>${report.results.fullReport.securityIssues.length} issues</span></p>
</td>
</tr>`
generateScoreTableRow(
'Security',
report.results.simpleReport.securityScore,
report.results.fullReport.securityIssues.length
)
)
.addRaw('</table>')

Expand All @@ -179,13 +183,13 @@ export async function run(): Promise<void> {

await summary.write()

if (totalWarnings > maxWarnings) {
if (maxWarnings && totalWarnings > maxWarnings) {
core.setFailed(
`The total number of warnings (${totalWarnings}) exceeds the maximum amout of warnings allowed (${maxWarnings})`
)
}

if (totalErrors > maxErrors) {
if (maxErrors && totalErrors > maxErrors) {
core.setFailed(
`The total number of errors (${totalErrors}) exceeds the maximum amout of errors allowed (${maxErrors})`
)
Expand Down
Loading