Skip to content

Commit

Permalink
Filter issues by changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Mar 28, 2024
1 parent 15f1037 commit 35bb22c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 35 additions & 14 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.

8 changes: 4 additions & 4 deletions src/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export type SourceFileIssue = Required<Issue> & { audit: AuditReport }
export function filterRelevantIssues({
currReport,
prevReport,
reportsDiff
// changedFiles
reportsDiff,
changedFiles
}: {
currReport: Report
prevReport: Report
reportsDiff: ReportsDiff
// changedFiles: string[]
changedFiles: string[]
}): SourceFileIssue[] {
const audits = [...reportsDiff.audits.changed, ...reportsDiff.audits.added]
.map(auditLink =>
Expand All @@ -28,7 +28,7 @@ export function filterRelevantIssues({

return issues.filter(
issue =>
// changedFiles.includes(issue.source?.file) &&
changedFiles.includes(issue.source?.file) &&
!prevIssues.some(prevIssue => issuesAreEqual(prevIssue, issue))
)
}
Expand Down
14 changes: 7 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { collect } from './collect'
import { commentOnPR } from './comment'
import { compare } from './compare'
import { listChangedFiles } from './diff'
import { parseInputs } from './inputs'
import { filterRelevantIssues } from './issues'
import type { PersistedCliFiles } from './persist'
Expand Down Expand Up @@ -44,8 +45,7 @@ export async function run(
}

if (isPullRequest(github.context.payload.pull_request)) {
const { base } = github.context.payload.pull_request
// const { base, head } = github.context.payload.pull_request
const { base, head } = github.context.payload.pull_request
core.debug(`PR detected, preparing to compare base branch ${base.ref}`)

let prevReport: string
Expand Down Expand Up @@ -92,18 +92,18 @@ export async function run(
core.debug(`Commented on PR #${github.context.issue.number}`)

if (inputs.annotations) {
await git.fetch('origin', base.ref, ['--depth=1'])
const reportsDiff = await fs.readFile(diffJsonPath, 'utf8')
// const changedFiles = await listChangedFiles({ base, head }, git)
const changedFiles = await listChangedFiles({ base, head }, git)
const issues = filterRelevantIssues({
currReport: JSON.parse(currReport),
prevReport: JSON.parse(prevReport),
reportsDiff: JSON.parse(reportsDiff)
// changedFiles
reportsDiff: JSON.parse(reportsDiff),
changedFiles
})
createAnnotationsFromIssues(issues)
core.debug(
// `Found ${issues.length} relevant issues for ${changedFiles.length} changed files and created GitHub annotations`
`Found ${issues.length} relevant issues and created GitHub annotations`
`Found ${issues.length} relevant issues for ${changedFiles.length} changed files and created GitHub annotations`
)
}

Expand Down

0 comments on commit 35bb22c

Please sign in to comment.