Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Feb 29, 2024
1 parent bed7ab2 commit 7a48c4e
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 30 deletions.
1 change: 1 addition & 0 deletions packages/canyon-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ model Project {
bu String
tag String
coverage String
defaultBranch String @map("default_branch")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3)
@@map("project")
Expand Down
6 changes: 4 additions & 2 deletions packages/canyon-backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ type Project {
tag: String!
coverage: String!
bu: String!
branchOptions: [String!]!
maxCoverage: Float!
defaultBranch: String!
reportTimes: Float!
lastReportTime: DateTime!
createdAt: DateTime!
Expand Down Expand Up @@ -196,7 +198,7 @@ type Query {
getProjectsBuOptions: [BuOption!]!

"""获取Project图表"""
getProjectChartData(projectID: String!): [ProjectChartDataModel!]!
getProjectChartData(projectID: String!, branch: String!): [ProjectChartDataModel!]!

"""获取Project宫格"""
getProjectCompartmentData(projectID: String!): [ProjectCompartmentDataModel!]!
Expand All @@ -220,5 +222,5 @@ type Mutation {
deleteProject(projectID: String!): Project2!

"""更新项目"""
updateProject(projectID: String!, description: String!, tag: String!, coverage: String!): Project2!
updateProject(projectID: String!, description: String!, tag: String!, coverage: String!, defaultBranch: String!): Project2!
}
22 changes: 21 additions & 1 deletion packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RetrieveCoverageTreeSummaryService } from './services/retrieve-coverage
import { getSpecificCoverageData } from '../adapter/coverage-data.adapter';
import { join } from 'path';
import { download } from '../utils/download';
import { PrismaService } from '../prisma/prisma.service';
// import * as platform from 'platform'
// export function getPlatformInfo(str) {
// return platform.parse(str)
Expand All @@ -32,6 +33,7 @@ export class CoverageController {
private readonly coverageClientService: CoverageClientService,
// private readonly retrieveCoverageSummaryService: RetrieveCoverageSummaryService,
private readonly retrieveCoverageTreeSummaryService: RetrieveCoverageTreeSummaryService,
private prisma: PrismaService,
) {}

@UseGuards(JwtAuthGuard)
Expand Down Expand Up @@ -60,7 +62,7 @@ export class CoverageController {

// 获取概览,重要!!!!!
@Get('coverage/treesummary')
coverageTreeSummary(
async coverageTreeSummary(
@Query()
params: {
reportId?: string;
Expand All @@ -70,8 +72,26 @@ export class CoverageController {
commitSha?: string;
commit_sha?: string;
sha?: string;
projectID?: string;
branch?: string;
},
) {
// 同时有projectID和branch时,联查出最新的sha
if (params.projectID && params.branch) {
const coverage = await this.prisma.coverage.findFirst({
orderBy: {
createdAt: 'desc',
},
where: {
projectID: params.projectID,
branch: params.branch,
},
});
if (coverage) {
params.sha = coverage.sha;
}
}
console.log(params.sha);
return this.retrieveCoverageTreeSummaryService.invoke({
reportID: params.reportId || params.report_id || params.reportID || null,
sha:
Expand Down
6 changes: 6 additions & 0 deletions packages/canyon-backend/src/project/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ export class Project {
@Field(() => String)
bu: string;

@Field(() => [String])
branchOptions: string[];

@Field(() => Number)
maxCoverage: number;

@Field(() => String)
defaultBranch: string;

@Field(() => Number)
reportTimes: number;

Expand Down
5 changes: 4 additions & 1 deletion packages/canyon-backend/src/project/project.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export class ProjectResolver {
})
getProjectChartData(
@Args('projectID', { type: () => String }) projectID: string,
@Args('branch', { type: () => String }) branch: string,
): Promise<ProjectChartDataModel[]> {
return this.getProjectChartDataService.invoke(projectID);
return this.getProjectChartDataService.invoke(projectID, branch);
}

@Query(() => [ProjectCompartmentDataModel], {
Expand Down Expand Up @@ -161,13 +162,15 @@ export class ProjectResolver {
@Args('description', { type: () => String }) description: string,
@Args('tag', { type: () => String }) tag: string,
@Args('coverage', { type: () => String }) coverage: string,
@Args('defaultBranch', { type: () => String }) defaultBranch: string,
): Promise<Project2> {
return this.projectService.updateProject(
user,
projectID,
description,
tag,
coverage,
defaultBranch,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
import { calculateCoverageOverviewByConditionFilter } from '../../utils/summary';
import { removeNullKeys } from '../../utils/utils';
// import { getProjectByID } from '../adapter/gitlab.adapter';
@Injectable()
export class GetProjectChartDataService {
constructor(private readonly prisma: PrismaService) {}
async invoke(projectID) {
const allCovTypeCoverages = await this.prisma.coverage.findMany({
async invoke(projectID, branch) {
const { defaultBranch } = await this.prisma.project.findFirst({
where: {
id: projectID,
},
});
const allCovTypeCoverages = await this.prisma.coverage.findMany({
where: removeNullKeys({
projectID: projectID,
covType: 'all',
},
branch: defaultBranch === '-' ? null : defaultBranch,
}),
orderBy: {
createdAt: 'desc',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class GetProjectCompartmentDataService {
});

const max = Math.max(...maxs);
console.log(max > 0, 'max');
return [
{
label: 'projects.total_times',
Expand Down
22 changes: 21 additions & 1 deletion packages/canyon-backend/src/project/services/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class ProjectService {
bu: bu || '默认',
coverage: '',
tag: '',
defaultBranch: '-',
},
});
}
Expand All @@ -80,7 +81,14 @@ export class ProjectService {
});
}

async updateProject(user, projectID, description, tag, coverage) {
async updateProject(
user,
projectID,
description,
tag,
coverage,
defaultBranch,
) {
function removeEmptyValues(obj) {
for (const key in obj) {
if (
Expand All @@ -101,11 +109,20 @@ export class ProjectService {
description: description,
tag: tag,
coverage: coverage,
defaultBranch: defaultBranch,
}),
});
}

async getProjectByID(projectID): Promise<Project> {
const branchOptions = await this.prisma.coverage
.groupBy({
by: ['branch'],
where: {
projectID: projectID,
},
})
.then((res) => res.map((item) => item.branch));
return this.prisma.project
.findFirst({
where: {
Expand All @@ -122,6 +139,7 @@ export class ProjectService {
createdAt,
coverage,
tag,
defaultBranch,
}) => {
return {
id,
Expand All @@ -135,6 +153,8 @@ export class ProjectService {
maxCoverage: 0,
tag,
coverage,
defaultBranch,
branchOptions,
};
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation UpdateProject($projectID: String!,$description: String!,$tag: String!,$coverage: String!) {
updateProject(projectID: $projectID,description: $description,tag: $tag,coverage: $coverage) {
mutation UpdateProject($projectID: String!,$description: String!,$tag: String!,$coverage: String!,$defaultBranch: String!) {
updateProject(projectID: $projectID,description: $description,tag: $tag,coverage: $coverage,defaultBranch: $defaultBranch) {
id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ query GetProjectByID($projectID: ID!) {
lastReportTime
coverage
tag
branchOptions
defaultBranch
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query GetProjectChartData($projectID: String!) {
getProjectChartData(projectID: $projectID){
query GetProjectChartData($projectID: String!,$branch: String!) {
getProjectChartData(projectID: $projectID, branch: $branch){
sha
newlines
statements
Expand Down
34 changes: 30 additions & 4 deletions packages/canyon-platform/src/layouts/genBreadcrumbItems.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import {useTranslation} from "react-i18next";
function matchPattern(str) {
function matchPattern(str: string) {
return /^\/projects\/\d+(?!(\/\d+))$/.test(str);
}

export function genBreadcrumbItems(pathname:string) {
export function genBreadcrumbItems(pathname: string) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const {t} = useTranslation();
const { t } = useTranslation();
// eslint-disable-next-line react-hooks/rules-of-hooks
const nav = useNavigate();
if (matchPattern(pathname)) {
Expand Down Expand Up @@ -47,6 +47,32 @@ export function genBreadcrumbItems(pathname:string) {
// title: 'Coverage Details',
},
];
} else if (pathname.includes('configure')) {
return [
{
title: <span className={'cursor-pointer'}>{t('menus.projects')}</span>,
onClick() {
nav('/projects');
},
},
{
title: <span className={'cursor-pointer'}>{t('projects.overview')}</span>,
onClick() {
const regex = /\/projects\/(\d+)\//;
const match = pathname.match(regex);
if (match) {
const projectId = match[1];
nav(`/projects/${projectId}`);
} else {
console.log('未找到匹配的项目ID');
}
},
},
{
title: '项目配置',
// title: 'Coverage Details',
},
];
} else {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const BasicForms: FC<{ data: any }> = ({ data }) => {
coverage: '__null__',
tag: values.tag,
description: values.description,
defaultBranch: '__null__',
},
}).then(() => {
message.success('成功');
Expand Down
Loading

0 comments on commit 7a48c4e

Please sign in to comment.