Skip to content

Commit

Permalink
Fix missing revision git diff error
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Mar 28, 2024
1 parent f209310 commit 51accdd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
5 changes: 4 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
writeFile
} from 'node:fs/promises'
import { join } from 'node:path'
import { simpleGit, type SimpleGit } from 'simple-git'
import { simpleGit, type DiffResult, type SimpleGit } from 'simple-git'
import type { ActionInputs } from '../src/inputs'
import { run } from '../src/main'

Expand Down Expand Up @@ -127,6 +127,9 @@ describe('code-pushup action', () => {
git = simpleGit(workDir)

jest.spyOn(git, 'fetch').mockImplementation()
jest.spyOn(git, 'diffSummary').mockResolvedValue({
files: [{ file: 'index.ts', binary: false }]
} as DiffResult)

await git.init()
await git.addConfig('user.name', 'John Doe')
Expand Down
8 changes: 4 additions & 4 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/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DiffNameStatus, simpleGit } from 'simple-git'

export async function listChangedFiles(
refs: {
base: { ref: string; sha: string }
head: { ref: string; sha: string }
base: string
head: string
},
git = simpleGit()

Check failure on line 8 in src/diff.ts

View workflow job for this annotation

GitHub Actions / GitHub Actions Test

Branch coverage

1st branch is not taken in any test case.
): Promise<string[]> {
Expand All @@ -13,8 +13,8 @@ export async function listChangedFiles(
]
const { files } = await git.diffSummary([
`--diff-filter=${statuses.join('')}`,
refs.base.ref,
refs.head.ref
refs.base,
refs.head
])
return files.filter(({ binary }) => !binary).map(({ file }) => file)
}
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function run(
}

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

let prevReport: string
Expand Down Expand Up @@ -94,7 +94,10 @@ export async function run(
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: 'FETCH_HEAD', head: 'HEAD' },
git
)
const issues = filterRelevantIssues({
currReport: JSON.parse(currReport),
prevReport: JSON.parse(prevReport),
Expand Down

0 comments on commit 51accdd

Please sign in to comment.