Skip to content

Commit e990f9b

Browse files
committed
Coderabbit comments from upstream
1 parent e936a38 commit e990f9b

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/gitGraph.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execSync } from 'child_process';
1+
import { spawnSync } from 'child_process';
22
import * as core from '@actions/core';
33
import { Benchmark } from './extract';
44

@@ -7,7 +7,7 @@ export class GitGraphAnalyzer {
77

88
constructor() {
99
try {
10-
execSync('git --version', { stdio: 'ignore' });
10+
spawnSync('git', ['--version'], { stdio: 'ignore' });
1111
this.gitCliAvailable = true;
1212
} catch (e) {
1313
this.gitCliAvailable = false;
@@ -31,12 +31,16 @@ export class GitGraphAnalyzer {
3131
}
3232

3333
try {
34-
const output = execSync(`git log --oneline --topo-order ${ref}`, {
34+
const result = spawnSync('git', ['log', '--oneline', '--topo-order', ref], {
3535
encoding: 'utf8',
3636
cwd: process.env.GITHUB_WORKSPACE ?? process.cwd(),
3737
});
3838

39-
return output
39+
if (result.error) {
40+
throw result.error;
41+
}
42+
43+
return result.stdout
4044
.split('\n')
4145
.filter((line) => line.trim())
4246
.map((line) => line.split(' ')[0]); // Extract SHA from "sha message"
@@ -97,7 +101,9 @@ export class GitGraphAnalyzer {
97101
}
98102

99103
// Create a set of ancestor SHAs for quick lookup (excluding the commit itself)
100-
const ancestorSet = new Set(ancestry.slice(1)); // Skip first element (the commit itself)
104+
// Skip first element only if it matches the commit (it should)
105+
const startIndex = ancestry[0] === newCommitSha ? 1 : 0;
106+
const ancestorSet = new Set(ancestry.slice(startIndex));
101107

102108
// Find the most recent ancestor in the existing suites
103109
// Iterate through suites from end to beginning to find the most recent one

test/write.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ jest.mock('../src/git', () => ({
118118

119119
jest.mock('../src/gitGraph', () => ({
120120
GitGraphAnalyzer: jest.fn().mockImplementation(() => ({
121-
getCurrentBranch: () => 'main',
122-
findPreviousBenchmark: (suites: any[]) => {
121+
isGitAvailable: () => true,
122+
getAncestry: (ref: string) => [],
123+
findPreviousBenchmark: (suites: any[], currentSha: string) => {
123124
if (suites.length > 0) {
124125
return suites[suites.length - 1];
125126
}
126127
return null;
127128
},
128-
findInsertionIndex: (suites: any[]) => suites.length,
129-
sortByGitOrder: (suites: any[]) => suites,
129+
findInsertionIndex: (suites: any[], newCommitSha: string) => suites.length,
130130
})),
131131
}));
132132

0 commit comments

Comments
 (0)