Skip to content

Commit

Permalink
Only add changed file to markdown summary if only changed files is true
Browse files Browse the repository at this point in the history
  • Loading branch information
ataylorme committed Mar 1, 2024
1 parent 391edc7 commit 14956b4
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/getPullRequestChangedAnalyzedReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}

0 comments on commit 14956b4

Please sign in to comment.