From fa1b617f55a6c8bff7d0306ee4a7b7a2a24f4624 Mon Sep 17 00:00:00 2001 From: Allen Zhang <37892968+zhangtao25@users.noreply.github.com> Date: Wed, 8 Nov 2023 14:32:39 +0800 Subject: [PATCH] feat: update --- .../src/coverage/services/coverage.service.ts | 1 + .../src/pages/project/[id]/commits/[sha].tsx | 12 ++-- .../project/[id]/commits/helper/index.ts | 66 +++++++++++++++++++ 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 packages/canyon-platform/src/pages/project/[id]/commits/helper/index.ts diff --git a/packages/canyon-backend/src/coverage/services/coverage.service.ts b/packages/canyon-backend/src/coverage/services/coverage.service.ts index c59e0e90..2efec8df 100755 --- a/packages/canyon-backend/src/coverage/services/coverage.service.ts +++ b/packages/canyon-backend/src/coverage/services/coverage.service.ts @@ -182,6 +182,7 @@ export class CoverageService { // 私有方法 private async getCoverageDataFromAdapter(commitSha, reportID) { + console.log(commitSha, reportID) const { relationID } = await this.prisma.coverage.findFirst({ where: { commitSha: commitSha, diff --git a/packages/canyon-platform/src/pages/project/[id]/commits/[sha].tsx b/packages/canyon-platform/src/pages/project/[id]/commits/[sha].tsx index 92ccd2a6..4ce7c200 100644 --- a/packages/canyon-platform/src/pages/project/[id]/commits/[sha].tsx +++ b/packages/canyon-platform/src/pages/project/[id]/commits/[sha].tsx @@ -5,6 +5,7 @@ import { useParams } from 'react-router'; import { useSearchParams } from 'react-router-dom'; import { GetCoverageSummaryMapDocument } from '../../../../helpers/backend/gen/graphql.ts'; +import { handleSelectFile } from './helper'; const Sha = () => { const prm = useParams(); const [sprm] = useSearchParams(); @@ -21,12 +22,11 @@ const Sha = () => { reportRef.current, { onSelectFile(path: string) { - console.log(path, 'path'); - return new Promise((resolve) => { - resolve({ - fileContent: '', - fileCoverage: '', - }); + return handleSelectFile({ + filepath: path, + reportID: sprm.get('report_id') || '', + commitSha: prm.sha || '', + projectID: prm.id || '', }); }, }, diff --git a/packages/canyon-platform/src/pages/project/[id]/commits/helper/index.ts b/packages/canyon-platform/src/pages/project/[id]/commits/helper/index.ts new file mode 100644 index 00000000..c6714442 --- /dev/null +++ b/packages/canyon-platform/src/pages/project/[id]/commits/helper/index.ts @@ -0,0 +1,66 @@ +import axios from 'axios'; +function getDecode(str: string) { + return decodeURIComponent( + atob(str) + .split('') + .map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join(''), + ); +} +export function handleSelectFile({ projectID, commitSha, filepath, reportID }) { + const fileContentRequest = axios.post( + `/graphql`, + { + operationName: 'GetFileInfo', + variables: { + projectID: projectID, + commitSha: commitSha, + filepath: filepath, + }, + query: `query GetFileInfo ($projectID: ID!, $filepath: String!, $commitSha: String!) { + getFileInfo (projectID: $projectID, filepath: $filepath, commitSha: $commitSha) { + content + } +} +`, + }, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + }, + ); + const fileCoverageRequest = axios.post( + `/graphql`, + { + operationName: 'GetCoverageData', + variables: { + reportID: reportID, + commitSha: commitSha, + filepath: filepath, + }, + query: `query GetCoverageData($commitSha: String!, $reportID: String!, $filepath: String!) { + getCoverageData( + commitSha: $commitSha + reportID: $reportID + filepath: $filepath) + }`, + }, + { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + }, + ); + return Promise.all([fileContentRequest, fileCoverageRequest]).then( + ([fileContent, fileCoverage]) => { + return { + fileContent: getDecode(fileContent.data.data.getFileInfo.content), + fileCoverage: JSON.parse(fileCoverage.data.data.getCoverageData), + fileCodeChange: [], + }; + }, + ); +}