-
Notifications
You must be signed in to change notification settings - Fork 13
feat(#455): handle baselineBranchName #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
144ad70
195c506
65493c8
156dce4
31c3852
e6b29ab
2bfe11f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Project" ADD COLUMN "protectedBranch" TEXT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Injectable, Inject, forwardRef, Logger } from '@nestjs/common'; | ||
import { PrismaService } from '../prisma/prisma.service'; | ||
import { TestVariation, Baseline, Build, TestRun, User } from '@prisma/client'; | ||
import { TestVariation, Baseline, Build, TestRun, User, type Project } from '@prisma/client'; | ||
import { StaticService } from '../static/static.service'; | ||
import { BuildsService } from '../builds/builds.service'; | ||
import { TestRunsService } from '../test-runs/test-runs.service'; | ||
|
@@ -79,36 +79,34 @@ export class TestVariationsService { | |
* @param baselineData | ||
* @returns | ||
*/ | ||
async find( | ||
createTestRequestDto: BaselineDataDto & { projectId: string; sourceBranch?: string } | ||
): Promise<TestVariation | null> { | ||
async find(createTestRequestDto: Omit<CreateTestRequestDto, 'buildId'>): Promise<TestVariation | null> { | ||
const project = await this.prismaService.project.findUnique({ where: { id: createTestRequestDto.projectId } }); | ||
const mainBranch = createTestRequestDto.sourceBranch ?? project.mainBranchName; | ||
const baselineBranch = createTestRequestDto.baselineBranchName ?? project.mainBranchName; | ||
Comment on lines
-86
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it was used before to make manual test runs with comparison within branches not base on main branch |
||
|
||
const [mainBranchTestVariation, currentBranchTestVariation] = await Promise.all([ | ||
// search main branch variation | ||
// search baseline branch variation | ||
this.findUnique({ | ||
projectId: createTestRequestDto.projectId, | ||
branchName: mainBranch, | ||
branchName: baselineBranch, | ||
...getTestVariationUniqueData(createTestRequestDto), | ||
}), | ||
// search current branch variation | ||
createTestRequestDto.branchName !== mainBranch && | ||
createTestRequestDto.branchName !== baselineBranch && | ||
this.findUnique({ | ||
projectId: createTestRequestDto.projectId, | ||
branchName: createTestRequestDto.branchName, | ||
...getTestVariationUniqueData(createTestRequestDto), | ||
}), | ||
]); | ||
|
||
if (!!currentBranchTestVariation) { | ||
if (currentBranchTestVariation) { | ||
if (mainBranchTestVariation && mainBranchTestVariation.updatedAt > currentBranchTestVariation.updatedAt) { | ||
return mainBranchTestVariation; | ||
} | ||
return currentBranchTestVariation; | ||
} | ||
|
||
if (!!mainBranchTestVariation) { | ||
if (mainBranchTestVariation) { | ||
return mainBranchTestVariation; | ||
} | ||
} | ||
|
@@ -248,4 +246,14 @@ export class TestVariationsService { | |
where: { id: baseline.id }, | ||
}); | ||
} | ||
|
||
async findOldTestVariations(project: Project, dateRemoveAfter: Date) { | ||
return await this.prismaService.$queryRaw<Project[]>` | ||
SELECT * from public."TestVariation" | ||
WHERE "projectId" = ${project.id} | ||
AND "updatedAt" <= ${dateRemoveAfter} | ||
AND "branchName" NOT LIKE ${project.mainBranchName} | ||
AND "branchName" NOT SIMILAR TO ${project.protectedBranch} | ||
`; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I completely understand the purpose of this filtering
could we move this change to separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comment here Visual-Regression-Tracker/Visual-Regression-Tracker#455 (comment).