Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
肖恩 authored and 肖恩 committed Dec 29, 2023
1 parent b4dd5c5 commit 8e3b3f6
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ REDIRECT_URI=http://localhost:3000/login

APP_URI=http://localhost:3000
UPLOAD_URL=http://localhost:3000


PRIVATE_TOKEN=***
6 changes: 3 additions & 3 deletions packages/canyon-backend/src/adapter/gitlab.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const getFileInfo = async (
},
headers: {
// Authorization: `Bearer ${token}`,
'private-token': 'dpxTutmZv_wPogCkpCmc',
'private-token': process.env.PRIVATE_TOKEN,
},
},
)
Expand All @@ -162,7 +162,7 @@ export const getCommits = async (
{
headers: {
// Authorization: `Bearer ${token}`,
'private-token': 'dpxTutmZv_wPogCkpCmc',
'private-token': process.env.PRIVATE_TOKEN,
},
},
)
Expand All @@ -176,7 +176,7 @@ export async function getProjectByID(projectID: string, token: string) {
.get<ProjectInfo>(`${GITLAB_URL}/api/v4/projects/${projectID}`, {
headers: {
// Authorization: `Bearer ${token}`,
'private-token': 'dpxTutmZv_wPogCkpCmc',
'private-token': process.env.PRIVATE_TOKEN,
},
})
.then(({ data }) => data);
Expand Down
25 changes: 25 additions & 0 deletions packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ export class CoverageController {
private readonly prismaService: PrismaService,
) {}

@Get('/api/coverage')
async getcoverage(@Query() query: any): Promise<any> {
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(
Expand Down
6 changes: 3 additions & 3 deletions packages/canyon-backend/src/utils/diffline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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,
},
},
)
Expand Down Expand Up @@ -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',
},
Expand Down
139 changes: 139 additions & 0 deletions packages/canyon-platform/src/pages/coverage/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Space className={'mb-5'}>
<Input
placeholder={'Sha'}
onChange={(val) => {
setSearchData({
...searchData,
commitSha: val.target.value,
});
}}
onKeyDown={handleKeyDown}
/>
<Input
placeholder={'Project ID'}
onChange={(val) => {
setSearchData({
...searchData,
projectID: val.target.value,
});
}}
onKeyDown={handleKeyDown}
/>
<Button
onClick={() => {
run();
}}
>
Search
</Button>
</Space>
<Table
onChange={(pagination) => {
// 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}
/>
</div>
);
};

export default CoveragePage;

0 comments on commit 8e3b3f6

Please sign in to comment.