diff --git a/.env.example b/.env.example index 3fcea34a..26bc4823 100755 --- a/.env.example +++ b/.env.example @@ -14,3 +14,6 @@ REDIRECT_URI=http://localhost:3000/login APP_URI=http://localhost:3000 UPLOAD_URL=http://localhost:3000 + + +PRIVATE_TOKEN=*** diff --git a/packages/canyon-backend/src/adapter/gitlab.adapter.ts b/packages/canyon-backend/src/adapter/gitlab.adapter.ts index b08690a8..ac2a50ae 100755 --- a/packages/canyon-backend/src/adapter/gitlab.adapter.ts +++ b/packages/canyon-backend/src/adapter/gitlab.adapter.ts @@ -143,7 +143,7 @@ export const getFileInfo = async ( }, headers: { // Authorization: `Bearer ${token}`, - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, }, ) @@ -162,7 +162,7 @@ export const getCommits = async ( { headers: { // Authorization: `Bearer ${token}`, - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, }, ) @@ -176,7 +176,7 @@ export async function getProjectByID(projectID: string, token: string) { .get(`${GITLAB_URL}/api/v4/projects/${projectID}`, { headers: { // Authorization: `Bearer ${token}`, - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, }) .then(({ data }) => data); diff --git a/packages/canyon-backend/src/coverage/coverage.controller.ts b/packages/canyon-backend/src/coverage/coverage.controller.ts index 4e93a40b..1a593984 100755 --- a/packages/canyon-backend/src/coverage/coverage.controller.ts +++ b/packages/canyon-backend/src/coverage/coverage.controller.ts @@ -32,6 +32,31 @@ export class CoverageController { private readonly prismaService: PrismaService, ) {} + @Get('/api/coverage') + async getcoverage(@Query() query: any): Promise { + const current = query.current || 1; + const pageSize = query.pageSize || 10; + return { + list: await this.prismaService.coverage.findMany({ + where: { + commitSha: query.commitSha, + reportID: query.reportID, + }, + orderBy: { + createdAt: 'desc', + }, + skip: (current - 1) * pageSize, + take: pageSize - 0, + }), + total: await this.prismaService.coverage.count({ + where: { + commitSha: query.commitSha, + reportID: query.reportID, + }, + }), + }; + } + @UseGuards(JwtAuthGuard) @Post('coverage/client') async save( diff --git a/packages/canyon-backend/src/utils/diffline.ts b/packages/canyon-backend/src/utils/diffline.ts index 52528ef7..c2535720 100755 --- a/packages/canyon-backend/src/utils/diffline.ts +++ b/packages/canyon-backend/src/utils/diffline.ts @@ -83,7 +83,7 @@ export async function diffLine({ const gitlabApiUrlCommitResponse = await fetch(gitlabApiUrlCommit, { headers: { // Authorization: 'Bearer ' + token, // 在请求头中使用 GitLab API token - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, }) .then((res) => res.json()) @@ -108,7 +108,7 @@ export async function diffLine({ { headers: { // Authorization: 'Bearer ' + token, // 在请求头中使用 GitLab API token - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, }, ) @@ -158,7 +158,7 @@ export async function diffLine({ { headers: { // Authorization: 'Bearer ' + token, // 在请求头中使用 GitLab API token - 'private-token': 'dpxTutmZv_wPogCkpCmc', + 'private-token': process.env.PRIVATE_TOKEN, }, method: 'GET', }, diff --git a/packages/canyon-platform/src/pages/coverage/index.tsx b/packages/canyon-platform/src/pages/coverage/index.tsx new file mode 100644 index 00000000..557c1912 --- /dev/null +++ b/packages/canyon-platform/src/pages/coverage/index.tsx @@ -0,0 +1,139 @@ +import { useRequest } from 'ahooks'; +import { Button, Input, Select, Space, Table } from 'antd'; +import axios from 'axios'; +import dayjs from 'dayjs'; +import { useState } from 'react'; + +// model Coverage { +// id Int @id @default(autoincrement()) +// key String? +// commitSha String @map("commit_sha") +// branch String +// compareTarget String @map("compare_target") +// projectID String @map("project_id") +// instrumentCwd String? @map("instrument_cwd") +// reporter Int +// reportID String @map("report_id") +// covType String @map("cov_type") +// relationID String @map("relation_id") +// createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3) +// +// @@map("coverage") +// } + +const CoveragePage = () => { + const [page, setPage] = useState({ + pageSize: 5, + current: 1, + }); + const { data, run, loading } = useRequest(({ pageSize, current } = { pageSize: 5, current: 1 }) => + axios + .get('/api/coverage', { + params: { + current: current || 1, + pageSize: pageSize || 5, + commitSha: searchData.commitSha || undefined, + projectID: searchData.projectID || undefined, + }, + }) + .then(({ data }) => data), + ); + const [searchData, setSearchData] = useState({ + commitSha: '', + projectID: '', + }); + const columns = [ + { + title: 'id', + dataIndex: 'id', + }, + { + title: 'reportID', + dataIndex: 'reportID', + }, + { + title: 'projectID', + dataIndex: 'projectID', + }, + { + title: 'branch', + dataIndex: 'branch', + }, + { + title: 'commitSha', + dataIndex: 'commitSha', + }, + { + title: 'compareTarget', + dataIndex: 'compareTarget', + }, + { + title: 'covType', + dataIndex: 'covType', + }, + { + title: 'createdAt', + dataIndex: 'createdAt', + render: (text: string) => dayjs(text).format('YYYY-MM-DD HH:mm:ss'), + }, + ]; + function handleKeyDown(event) { + if (event.keyCode === 13) { + run(); + } + } + + return ( +
+ + { + setSearchData({ + ...searchData, + commitSha: val.target.value, + }); + }} + onKeyDown={handleKeyDown} + /> + { + setSearchData({ + ...searchData, + projectID: val.target.value, + }); + }} + onKeyDown={handleKeyDown} + /> + + + { + // setPage({ + // pageSize: pagination.pageSize, + // current: pagination.current, + // }); + run({ + pageSize: pagination.pageSize, + current: pagination.current, + }); + }} + loading={loading} + pagination={{ pageSize: 5, total: data?.total || 0 }} + size={'small'} + rowKey={'id'} + dataSource={data?.list || []} + columns={columns} + /> + + ); +}; + +export default CoveragePage;