Skip to content

Commit

Permalink
fix: only use approved builds as baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Oct 8, 2024
1 parent 4784b35 commit 030d3b5
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions apps/backend/src/build/strategy/strategies/ci/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Build, ScreenshotBucket } from "@/database/models/index.js";
import {
Build,
ScreenshotBucket,
ScreenshotDiff,
} from "@/database/models/index.js";

/**
* Get the base bucket for a build and a commit.
Expand Down Expand Up @@ -30,11 +34,31 @@ export async function getBaseBucketForBuildAndCommit(
* Query the base bucket from a build.
*/
export function queryBaseBucket(build: Build) {
return ScreenshotBucket.query().where({
projectId: build.projectId,
name: build.name,
complete: true,
valid: true,
mode: build.mode,
});
const approvedBuilds = Build.query()
.where("projectId", build.projectId)
.where("name", build.name)
.where("mode", build.mode)
.where("jobStatus", "complete")
.whereNot("id", build.id)
.where((qb) => {
// Reference build or check build with accepted diffs
qb.where("type", "reference").orWhere((qb) => {
qb.where("type", "check").whereExists(
ScreenshotDiff.query()
.select(1)
.whereRaw('"buildId" = builds.id')
.where("validationStatus", "accepted"),
);
});
});

return ScreenshotBucket.query()
.where({
projectId: build.projectId,
name: build.name,
complete: true,
valid: true,
mode: build.mode,
})
.whereIn("id", approvedBuilds);
}

0 comments on commit 030d3b5

Please sign in to comment.