From 5758a004ad8c6c2926f9261a439fdd71fc529765 Mon Sep 17 00:00:00 2001 From: Steven Kitterman Date: Thu, 18 Jul 2024 17:38:42 -0700 Subject: [PATCH 1/2] Only check for the hash if the build is local --- node-src/git/findAncestorBuildWithCommit.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node-src/git/findAncestorBuildWithCommit.ts b/node-src/git/findAncestorBuildWithCommit.ts index 8d2757ffc..c51670050 100644 --- a/node-src/git/findAncestorBuildWithCommit.ts +++ b/node-src/git/findAncestorBuildWithCommit.ts @@ -70,7 +70,9 @@ export async function findAncestorBuildWithCommit( return [build, exists] as const; }) ); - const result = results.find(([build, exists]) => !build.uncommittedHash && exists); + const result = results.find( + ([build, exists]) => !(build.isLocalBuild && build.uncommittedHash) && exists + ); if (result) return result[0]; From 1719c78fe1e5a3c1e6571f661e7a68edd4b4d289 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Fri, 19 Jul 2024 12:46:37 +1000 Subject: [PATCH 2/2] Add test for changes --- node-src/git/findAncestorBuildWithCommit.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/node-src/git/findAncestorBuildWithCommit.test.ts b/node-src/git/findAncestorBuildWithCommit.test.ts index cc5a6fa46..f75610a3a 100644 --- a/node-src/git/findAncestorBuildWithCommit.test.ts +++ b/node-src/git/findAncestorBuildWithCommit.test.ts @@ -15,6 +15,7 @@ const makeBuild = (build: Partial = {}): Build => ({ number: 1, commit: 'missing', uncommittedHash: '', + isLocalBuild: false, ...build, }); const makeResult = (ancestorBuilds: Build[]): AncestorBuildsQueryResult => ({ @@ -36,14 +37,24 @@ describe('findAncestorBuildWithCommit', () => { expect(client.runQuery.mock.calls[0][1]).toMatchObject({ buildNumber: 1 }); }); - it('does not return build with uncommitted changes', async () => { + it('does not return a local build with uncommitted changes', async () => { client.runQuery.mockReturnValue( - makeResult([makeBuild({ commit: 'exists', uncommittedHash: 'abc123' })]) + makeResult([makeBuild({ commit: 'exists', uncommittedHash: 'abc123', isLocalBuild: true })]) ); expect(await findAncestorBuildWithCommit({ client }, 1, { page: 1, limit: 1 })).toBeNull(); }); + it('DOES return a CI build with uncommitted changes', async () => { + client.runQuery.mockReturnValue( + makeResult([makeBuild({ commit: 'exists', uncommittedHash: 'abc123' })]) + ); + + expect(await findAncestorBuildWithCommit({ client }, 1, { page: 1, limit: 1 })).toMatchObject({ + commit: 'exists', + }); + }); + it('passes skip and limit and recurse', async () => { const toFind = makeBuild({ number: 3, commit: 'exists' }); client.runQuery