-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff90bd4
commit 2a4a683
Showing
8 changed files
with
353 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...canyon-collect/src/apps/collect/services/common/pull-change-code-and-insert-db.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// import { diffLine } from "../../../utils/diffline"; | ||
|
||
import { diffLine } from "../../../../utils/diffline"; | ||
|
||
export class PullChangeCodeAndInsertDbService { | ||
async invoke(projectID, commitSha, compareTarget, accessToken, prisma) { | ||
const codechanges = await prisma.codechange.findMany({ | ||
where: { | ||
projectID, | ||
sha: commitSha, | ||
compareTarget, | ||
}, | ||
}); | ||
const gitProvider = await prisma.gitProvider.findFirst({ | ||
where: { | ||
disabled: false, | ||
}, | ||
}); | ||
if (codechanges.length === 0) { | ||
const diffLineData = await diffLine({ | ||
repoID: projectID, | ||
baseCommitSha: compareTarget, | ||
compareCommitSha: commitSha, | ||
token: gitProvider?.privateToken, | ||
gitlabUrl: gitProvider?.url, | ||
}); | ||
const data = diffLineData.map(({ path, additions, deletions }) => { | ||
return { | ||
projectID, | ||
sha: commitSha, | ||
compareTarget, | ||
path, | ||
additions, | ||
deletions, | ||
}; | ||
}); | ||
|
||
await prisma.codechange.createMany({ | ||
data: data, | ||
}); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/canyon-collect/src/apps/collect/services/common/test-exclude.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
// import { PrismaService } from "../../../prisma/prisma.service"; | ||
import * as TestExclude from "test-exclude"; | ||
import { PrismaService } from "../../../../prisma/prisma.service"; | ||
@Injectable() | ||
export class TestExcludeService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async invoke(projectID, coverage) { | ||
const project = await this.prisma.project.findFirst({ | ||
where: { | ||
id: projectID, | ||
}, | ||
}); | ||
|
||
let matchRule: any = {}; // Default value | ||
|
||
try { | ||
// Attempt to parse project?.coverage | ||
matchRule = JSON.parse(project?.coverage || "{}"); | ||
} catch (error) { | ||
// console.error('Error parsing coverage:', error); | ||
// Log the error or handle it as needed | ||
// You can also return an empty object or any default value | ||
} | ||
const exclude = new TestExclude({ | ||
cwd: "", | ||
include: matchRule.include, | ||
exclude: matchRule.exclude || [], | ||
extension: matchRule.extensions || [ | ||
".js", | ||
".cjs", | ||
".mjs", | ||
".ts", | ||
".tsx", | ||
".jsx", | ||
".vue", | ||
], | ||
}); | ||
|
||
const filterCoverage = {}; | ||
|
||
for (const filterCoverageKey of Object.keys(coverage)) { | ||
// TODO 当过滤条件特别多的时候,性能会很差,大概能达到3s的计算时间,所以得在消费的时候就落库概览数据,summarys | ||
if (exclude.shouldInstrument(filterCoverageKey)) { | ||
filterCoverage[filterCoverageKey] = coverage[filterCoverageKey]; | ||
} | ||
} | ||
return Object.keys(filterCoverage).length > 0 | ||
? filterCoverage | ||
: coverage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.