Skip to content

Commit

Permalink
Showing 4 changed files with 68 additions and 5 deletions.
12 changes: 12 additions & 0 deletions packages/gitlab/dev/index.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { gitlabPlugin, EntityGitlabContent } from '../src/plugin';
import { GitlabCIApiRef, GitlabCIClient } from '../src/api';
import { mockedGitlabReqToRes, projectId } from './mock-gitlab/api-v4-v15.7.0';
import { configApiRef, discoveryApiRef } from '@backstage/core-plugin-api';
import { GraphQLQuery } from '../src/api/GitlabCIApi';

createDevApp()
.registerPlugin(gitlabPlugin)
@@ -41,6 +42,17 @@ createDevApp()
return {
build: () => cli,
};

// Here we mock the client requests to GitLab
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cli.callGraphQLApi = async function (
query: GraphQLQuery
) {
const response = mockedGitlabReqToRes[query.query];

return response || undefined;
}
},
})
.addPage({
50 changes: 50 additions & 0 deletions packages/gitlab/dev/mock-gitlab/api-v4-v15.7.0.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
const graphqlProjectCoverageQuery = `
query getProjectCoverage(
$projectSlug: ID!
$updatedAfter: Time
) {
project(fullPath: $projectSlug) {
name
webUrl
pipelines(ref: "main", updatedAfter: $updatedAfter) {
nodes {
coverage
createdAt
}
}
}
}
`;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const mockedGitlabReqToRes: Record<string, any> = {
[graphqlProjectCoverageQuery]: {
data: {
project: {
name: 'veloren',
webUrl: 'https://gitlab.com/veloren/veloren',
pipelines: {
nodes: [
{
coverage: 98.4,
createdAt: '2019-01-02T16:18:45.823Z',
},
{
coverage: 97.4,
createdAt: '2019-01-02T16:18:45.823Z',
},
{
coverage: 96.4,
createdAt: '2019-01-02T16:18:45.823Z',
},
{
coverage: 95.4,
createdAt: '2019-01-02T16:18:45.823Z',
},
{
coverage: 94.4,
createdAt: '2019-01-02T16:18:45.823Z',
},
],
},
},
},
},
'projects/10174980?': {
id: 10174980,
description:
5 changes: 5 additions & 0 deletions packages/gitlab/src/api/GitlabCIApi.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,11 @@ export type GitlabCIBuilder = {
build(gitlabInstance: string): GitlabCIApi;
};

export type GraphQLQuery = {
variables: Record<string, string>;
query: string;
};

export type GitlabProjectCoverageResponse = {
data: {
project: {
6 changes: 1 addition & 5 deletions packages/gitlab/src/api/GitlabCIClient.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {
ContributorsSummary,
GitlabCIApi,
GitlabProjectCoverageResponse,
GraphQLQuery,
LanguagesSummary,
} from './GitlabCIApi';

@@ -20,11 +21,6 @@ import type {
} from '@gitbeaker/rest';
import dayjs from 'dayjs';

type GraphQLQuery = {
variables: Record<string, string>;
query: string;
};

export class GitlabCIClient implements GitlabCIApi {
discoveryApi: DiscoveryApi;
identityApi: IdentityApi;

0 comments on commit e035819

Please sign in to comment.