diff --git a/src/getPullRequestChangedAnalyzedReport.ts b/src/getPullRequestChangedAnalyzedReport.ts index 37a790f..b791e10 100644 --- a/src/getPullRequestChangedAnalyzedReport.ts +++ b/src/getPullRequestChangedAnalyzedReport.ts @@ -2,7 +2,7 @@ import getPullRequestFiles from './getPullRequestFiles' import getAnalyzedReport from './getAnalyzedReport' import type {ESLintReport, AnalyzedESLintReport} from './types' import constants from './constants' -const {GITHUB_WORKSPACE, OWNER, REPO, pullRequest} = constants +const {GITHUB_WORKSPACE, OWNER, REPO, pullRequest, onlyChangedFiles} = constants /** * Analyzes an ESLint report, separating pull request changed files @@ -16,35 +16,35 @@ export default async function getPullRequestChangedAnalyzedReport( repo: REPO, pull_number: pullRequest.number, }) + // Separate lint reports for PR and non-PR files const pullRequestFilesReportJS: ESLintReport = reportJS.filter((file) => { file.filePath = file.filePath.replace(GITHUB_WORKSPACE + '/', '') return changedFiles.indexOf(file.filePath) !== -1 }) - const nonPullRequestFilesReportJS: ESLintReport = reportJS.filter((file) => { - file.filePath = file.filePath.replace(GITHUB_WORKSPACE + '/', '') - return changedFiles.indexOf(file.filePath) === -1 - }) + const analyzedPullRequestReport = getAnalyzedReport(pullRequestFilesReportJS) - const analyzedNonPullRequestReport = getAnalyzedReport(nonPullRequestFilesReportJS) - const combinedSummary = ` -${analyzedPullRequestReport.summary} in pull request changed files. -${analyzedNonPullRequestReport.summary} in files outside of the pull request. -` - const combinedMarkdown = ` -# Pull Request Changed Files ESLint Results: -**${analyzedPullRequestReport.summary}** -${analyzedPullRequestReport.markdown} -# Non-Pull Request Changed Files ESLint Results: -**${analyzedNonPullRequestReport.summary}** -${analyzedNonPullRequestReport.markdown} -` + let summary = `${analyzedPullRequestReport.summary} in pull request changed files.` + let markdown = `# Pull Request Changed Files ESLint Results:\n**${analyzedPullRequestReport.summary}**\n${analyzedPullRequestReport.markdown}` + + if (!onlyChangedFiles) { + const nonPullRequestFilesReportJS: ESLintReport = reportJS.filter((file) => { + file.filePath = file.filePath.replace(GITHUB_WORKSPACE + '/', '') + return changedFiles.indexOf(file.filePath) === -1 + }) + + const analyzedNonPullRequestReport = getAnalyzedReport(nonPullRequestFilesReportJS) + + summary += `${analyzedNonPullRequestReport.summary} in files outside of the pull request.` + markdown += `\n\n# Non-Pull Request Changed Files ESLint Results:\n**${analyzedNonPullRequestReport.summary}**\n${analyzedNonPullRequestReport.markdown}` + } + return { errorCount: analyzedPullRequestReport.errorCount, warningCount: analyzedPullRequestReport.warningCount, - markdown: combinedMarkdown, + markdown, success: analyzedPullRequestReport.success, - summary: combinedSummary, + summary, annotations: analyzedPullRequestReport.annotations, } }