Skip to content

Commit 00b4e58

Browse files
committed
Fix missing revision git diff error
1 parent ab071e5 commit 00b4e58

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

__tests__/main.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
writeFile
1414
} from 'node:fs/promises'
1515
import { join } from 'node:path'
16-
import { simpleGit, type SimpleGit } from 'simple-git'
16+
import { simpleGit, type DiffResult, type SimpleGit } from 'simple-git'
1717
import type { ActionInputs } from '../src/inputs'
1818
import { run } from '../src/main'
1919

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

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

131134
await git.init()
132135
await git.addConfig('user.name', 'John Doe')

dist/index.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diff.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { DiffNameStatus, simpleGit } from 'simple-git'
22

33
export async function listChangedFiles(
44
refs: {
5-
base: { ref: string; sha: string }
6-
head: { ref: string; sha: string }
5+
base: string
6+
head: string
77
},
88
git = simpleGit()
99
): Promise<string[]> {
@@ -13,8 +13,8 @@ export async function listChangedFiles(
1313
]
1414
const { files } = await git.diffSummary([
1515
`--diff-filter=${statuses.join('')}`,
16-
refs.base.ref,
17-
refs.head.ref
16+
refs.base,
17+
refs.head
1818
])
1919
return files.filter(({ binary }) => !binary).map(({ file }) => file)
2020
}

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function run(
4545
}
4646

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

5151
let prevReport: string
@@ -94,7 +94,10 @@ export async function run(
9494
if (inputs.annotations) {
9595
await git.fetch('origin', base.ref, ['--depth=1'])
9696
const reportsDiff = await fs.readFile(diffJsonPath, 'utf8')
97-
const changedFiles = await listChangedFiles({ base, head }, git)
97+
const changedFiles = await listChangedFiles(
98+
{ base: 'FETCH_HEAD', head: 'HEAD' },
99+
git
100+
)
98101
const issues = filterRelevantIssues({
99102
currReport: JSON.parse(currReport),
100103
prevReport: JSON.parse(prevReport),

0 commit comments

Comments
 (0)