Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Jan 16, 2024
1 parent bb806a7 commit 5ddcea3
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 24 deletions.
14 changes: 14 additions & 0 deletions packages/canyon-backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,24 @@ type ProjectPagesModel {
total: Float!
}

type ProjectChartDataModel {
"""整体覆盖率"""
statements: Float!

"""New Lines"""
newlines: Float!

"""sha"""
sha: String!
}

type Query {
"""提供执行此查询的用户的详细信息(通过授权 Bearer 标头)"""
me: User!

"""获取Project"""
getProjects(current: Int!, pageSize: Int!, keyword: String!): ProjectPagesModel!

"""获取Project"""
getProjectChartData(projectID: String!): [ProjectChartDataModel!]!
}
183 changes: 183 additions & 0 deletions packages/canyon-backend/src/adapter/gitlab.adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import axios from 'axios';

interface FileInfo {
file_name: string;
file_path: string;
size: number;
encoding: string;
content_sha256: string;
ref: string;
blob_id: string;
commit_id: string;
last_commit_id: string;
content: string;
}

interface Commit {
id: string;
short_id: string;
created_at: string;
parent_ids: string[];
title: string;
message: string;
author_name: string;
author_email: string;
authored_date: string;
committer_name: string;
committer_email: string;
committed_date: string;
web_url: string;
ci_reports: any[];
stats: {
additions: number;
deletions: number;
total: number;
};
status: string;
project_id: number;
last_pipeline: {
id: number;
project_id: number;
sha: string;
ref: string;
status: string;
created_at: string;
updated_at: string;
web_url: string;
};
}

export interface ProjectInfo {
id: number;
description: string;
main_language: string;
name: string;
name_with_namespace: string;
path: string;
path_with_namespace: string;
created_at: string;
default_branch: string;
tag_list: string[];
ssh_url_to_repo: string;
http_url_to_repo: string;
web_url: string;
avatar_url: string | null;
forks_count: number;
star_count: number;
last_activity_at: string;
bu: string;
properties: {
node_version: string;
};
packages_enabled: boolean;
empty_repo: boolean;
archived: boolean;
visibility: string;
resolve_outdated_diff_discussions: boolean;
container_registry_enabled: boolean;
issues_enabled: boolean;
merge_requests_enabled: boolean;
wiki_enabled: boolean;
jobs_enabled: boolean;
snippets_enabled: boolean;
service_desk_enabled: boolean;
service_desk_address: string | null;
can_create_merge_request_in: boolean;
issues_access_level: string;
repository_access_level: string;
merge_requests_access_level: string;
forking_access_level: string;
wiki_access_level: string;
builds_access_level: string;
snippets_access_level: string;
pages_access_level: string;
operations_access_level: string;
analytics_access_level: string;
emails_disabled: any; // You may want to define a more specific type here
shared_runners_enabled: boolean;
lfs_enabled: boolean;
creator_id: number;
import_status: string;
import_error: string | null;
open_issues_count: number;
runners_token: string;
ci_default_git_depth: number;
ci_forward_deployment_enabled: boolean;
public_jobs: boolean;
build_git_strategy: string;
build_timeout: number;
auto_cancel_pending_pipelines: string;
build_coverage_regex: string | null;
ci_config_path: string | null;
shared_with_groups: any[]; // You may want to define a more specific type here
only_allow_merge_if_pipeline_succeeds: boolean;
allow_merge_on_skipped_pipeline: any; // You may want to define a more specific type here
restrict_user_defined_variables: boolean;
request_access_enabled: boolean;
only_allow_merge_if_all_discussions_are_resolved: boolean;
remove_source_branch_after_merge: boolean;
printing_merge_request_link_enabled: boolean;
merge_method: string;
suggestion_commit_message: string | null;
auto_devops_enabled: boolean;
auto_devops_deploy_strategy: string;
autoclose_referenced_issues: boolean;
}

const { GITLAB_URL } = process.env;

export const getFileInfo = async (
{
projectID,
filepath,
commitSha,
}: { projectID: string; filepath: string; commitSha: string },
token: string,
) => {
return await axios
.get<FileInfo>(
`${GITLAB_URL}/api/v4/projects/${projectID}/repository/files/${filepath}`,
{
params: {
ref: commitSha,
},
headers: {
// Authorization: `Bearer ${token}`,
'private-token': process.env.PRIVATE_TOKEN,
},
},
)
.then(({ data }) => data);
};

export const getCommits = async (
{ projectID, commitShas }: { projectID: string; commitShas: string[] },
token: string,
) => {
return await Promise.all(
commitShas.map((commitSha) =>
axios
.get<Commit>(
`${GITLAB_URL}/api/v4/projects/${projectID}/repository/commits/${commitSha}`,
{
headers: {
// Authorization: `Bearer ${token}`,
'private-token': process.env.PRIVATE_TOKEN,
},
},
)
.then(({ data }) => data),
),
);
};

export async function getProjectByID(projectID: string, token: string) {
return await axios
.get<ProjectInfo>(`${GITLAB_URL}/api/v4/projects/${projectID}`, {
headers: {
// Authorization: `Bearer ${token}`,
'private-token': process.env.PRIVATE_TOKEN,
},
})
.then(({ data }) => data);
}
7 changes: 6 additions & 1 deletion packages/canyon-backend/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Body, Controller, Get, Post, Request } from '@nestjs/common';

@Controller()
export class AppController {}
export class AppController {
@Get('vi/health')
viHealth() {
return '230614ms';
}
}
16 changes: 5 additions & 11 deletions packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ export class CoverageController {
@Body() coverageClientDto: CoverageClientDto,
@Request() req: any,
): Promise<any> {
console.log(req.user);
return this.coverageClientService.invoke(
req?.user?.id || 1,
req.user.id,
coverageClientDto,
req.headers['user-agent'],
req.ip,
);
}

@Get('coverage/summary')
coverageSummary(): Promise<any> {
return this.retrieveCoverageSummaryService.invoke();
}

@Get('vi/health')
viHealth() {
return '230614ms';
}
// @Get('coverage/summary')
// coverageSummary(): Promise<any> {
// // return this.retrieveCoverageSummaryService.invoke();
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType()
export class ProjectChartDataModel {
@Field(() => Number, {
description: '整体覆盖率',
})
statements: number;
@Field(() => Number, {
description: 'New Lines',
})
newlines: number;
@Field(() => String, {
description: 'sha',
})
sha: string;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Field, ID, ObjectType, Resolver} from '@nestjs/graphql';
import { Project } from './project.model';
import { Project } from '../project.model';

@ObjectType()
export class ProjectPagesModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType()
class Log {
@Field(() => String, {
description: 'ID',
})
id: string;
@Field(() => String, {
description: 'Commit Sha',
})
commitSha: string;
@Field(() => String, {
description: '上报ID',
})
reportID: string;
@Field(() => String, {
description: '关系ID',
})
relationID: string;
@Field(() => Date, {
description: '创建时间',
})
createdAt: string;
@Field(() => String, {
description: '上报人',
})
reporterUsername: string;
@Field(() => String, {
description: '上报人头像',
})
reporterAvatar: string;

@Field(() => Number, {
description: '新增',
})
newlines: number;

@Field(() => Number, {
description: '全量',
})
statements: number;
}

@ObjectType()
export class ProjectRecordsModel {
@Field(() => String, {
description: 'commit信息',
})
message: string;
@Field(() => String, {
description: 'commit sha',
})
commitSha: string;

@Field(() => String, {
description: 'Compare Target',
})
compareTarget: string;

@Field(() => String, {
description: 'branch',
})
branch: string;

@Field(() => String, {
description: 'Compare Url',
})
compareUrl: string;

@Field(() => String, {
description: 'web url',
})
webUrl: string;

@Field(() => Number, {
description: '新增',
})
newlines: number;

@Field(() => Number, {
description: '全量',
})
statements: number;

@Field(() => Date, {
description: '最近一次上报',
})
lastReportTime: string;
@Field(() => Number, {
description: '上报次数',
})
times: number;
@Field(() => [Log], {
description: '上报日志',
})
logs: Log[];
}
5 changes: 3 additions & 2 deletions packages/canyon-backend/src/project/project.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from '@nestjs/common';
import { PrismaModule } from 'src/prisma/prisma.module';
import { ProjectResolver } from './project.resolver';
import { ProjectService } from './project.service';
import { ProjectService } from './services/project.service';
import {GetProjectChartDataService} from "./services/get-project-chart-data.service";
@Module({
imports: [PrismaModule],
controllers: [],
providers: [ProjectResolver, ProjectService],
providers: [ProjectResolver, ProjectService,GetProjectChartDataService],
exports: [],
})
export class ProjectModule {}
Loading

0 comments on commit 5ddcea3

Please sign in to comment.