Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 8, 2023
1 parent bc05272 commit fa1b617
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 || '',
});
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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: [],
};
},
);
}

0 comments on commit fa1b617

Please sign in to comment.