Skip to content

Commit

Permalink
Add gitlab integration to show CI/CD status
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Mar 23, 2023
1 parent 297b190 commit 7dc76b1
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 37 deletions.
1 change: 1 addition & 0 deletions backstage/packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@backstage/plugin-techdocs-react": "^1.1.2",
"@backstage/plugin-user-settings": "^0.6.2",
"@backstage/theme": "^0.2.16",
"@immobiliarelabs/backstage-plugin-gitlab": "^5.0.0",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@remix-run/router": "^1.3.3",
Expand Down
55 changes: 30 additions & 25 deletions backstage/packages/app/src/components/catalog/EntityPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import React from 'react';
import { Button, Grid } from '@material-ui/core';
import {
RELATION_API_CONSUMED_BY,
RELATION_API_PROVIDED_BY,
RELATION_CONSUMES_API,
RELATION_DEPENDENCY_OF,
RELATION_DEPENDS_ON,
RELATION_HAS_PART,
RELATION_PART_OF,
RELATION_PROVIDES_API,
} from '@backstage/catalog-model';
import { EmptyState } from '@backstage/core-components';
import {
EntityApiDefinitionCard,
EntityConsumedApisCard,
Expand All @@ -18,43 +27,37 @@ import {
EntityHasSystemsCard,
EntityLayout,
EntityLinksCard,
EntitySwitch,
EntityOrphanWarning,
EntityProcessingErrorsPanel,
EntitySwitch,
hasCatalogProcessingErrors,
isComponentType,
isKind,
hasCatalogProcessingErrors,
isOrphan,
} from '@backstage/plugin-catalog';
import {
isGithubActionsAvailable,
Direction,
EntityCatalogGraphCard,
} from '@backstage/plugin-catalog-graph';
import {
EntityGithubActionsContent,
isGithubActionsAvailable,
} from '@backstage/plugin-github-actions';
import {
EntityUserProfileCard,
EntityGroupProfileCard,
EntityMembersListCard,
EntityOwnershipCard,
EntityUserProfileCard,
} from '@backstage/plugin-org';
import { EntityTechdocsContent } from '@backstage/plugin-techdocs';
import { EmptyState } from '@backstage/core-components';
import {
Direction,
EntityCatalogGraphCard,
} from '@backstage/plugin-catalog-graph';
import {
RELATION_API_CONSUMED_BY,
RELATION_API_PROVIDED_BY,
RELATION_CONSUMES_API,
RELATION_DEPENDENCY_OF,
RELATION_DEPENDS_ON,
RELATION_HAS_PART,
RELATION_PART_OF,
RELATION_PROVIDES_API,
} from '@backstage/catalog-model';

import { TechDocsAddons } from '@backstage/plugin-techdocs-react';
import { ReportIssue } from '@backstage/plugin-techdocs-module-addons-contrib';
import { TechDocsAddons } from '@backstage/plugin-techdocs-react';
import {
EntityGitlabPipelinesTable,
isGitlabAvailable,
} from '@immobiliarelabs/backstage-plugin-gitlab';
import { Button, Grid } from '@material-ui/core';
import React from 'react';

const techdocsContent = (
<EntityTechdocsContent>
Expand All @@ -65,13 +68,15 @@ const techdocsContent = (
);

const cicdContent = (
// This is an example of how you can implement your company's logic in entity page.
// You can for example enforce that all components of type 'service' should use GitHubActions
<EntitySwitch>
<EntitySwitch.Case if={isGithubActionsAvailable}>
<EntityGithubActionsContent />
</EntitySwitch.Case>

<EntitySwitch.Case if={isGitlabAvailable}>
<EntityGitlabPipelinesTable />
</EntitySwitch.Case>

<EntitySwitch.Case>
<EmptyState
title="No CI/CD available for this entity"
Expand Down
1 change: 1 addition & 0 deletions backstage/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@backstage/plugin-search-backend-module-pg": "^0.5.1",
"@backstage/plugin-search-backend-node": "^1.1.1",
"@backstage/plugin-techdocs-backend": "^1.5.1",
"@immobiliarelabs/backstage-plugin-gitlab-backend": "^5.0.0",
"better-sqlite3": "^8.0.0",
"dockerode": "^3.3.1",
"express": "^4.17.1",
Expand Down
11 changes: 3 additions & 8 deletions backstage/packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
* Hi!
*
* Note that this is an EXAMPLE Backstage backend. Please check the README.
*
* Happy hacking!
*/

import {
CacheManager,
createServiceBuilder,
Expand All @@ -25,6 +17,7 @@ import { ServerPermissionClient } from '@backstage/plugin-permission-node';
import Router from 'express-promise-router';
import auth from './plugins/auth';
import catalog from './plugins/catalog';
import gitlab from './plugins/gitlab';
import proxy from './plugins/proxy';
import scaffolder from './plugins/scaffolder';
import search from './plugins/search';
Expand Down Expand Up @@ -83,6 +76,7 @@ async function main() {
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
const searchEnv = useHotMemoize(module, () => createEnv('search'));
const gitlabEnv = useHotMemoize(module, () => createEnv('gitlab'));

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
Expand All @@ -91,6 +85,7 @@ async function main() {
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/search', await search(searchEnv));
apiRouter.use('/gitlab', await gitlab(gitlabEnv));

// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());
Expand Down
2 changes: 2 additions & 0 deletions backstage/packages/backend/src/plugins/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GithubEntityProvider } from '@backstage/plugin-catalog-backend-module-g
import { GitlabDiscoveryEntityProvider } from '@backstage/plugin-catalog-backend-module-gitlab';
import { LdapOrgEntityProvider } from '@backstage/plugin-catalog-backend-module-ldap';
import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend';
import { GitlabFillerProcessor } from '@immobiliarelabs/backstage-plugin-gitlab-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

Expand Down Expand Up @@ -34,6 +35,7 @@ export default async function createPlugin(
}),
);
builder.addProcessor(new ScaffolderEntitiesProcessor());
builder.addProcessor(new GitlabFillerProcessor(env.config));
const { processingEngine, router } = await builder.build();
await processingEngine.start();
return router;
Expand Down
12 changes: 12 additions & 0 deletions backstage/packages/backend/src/plugins/gitlab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createRouter } from '@immobiliarelabs/backstage-plugin-gitlab-backend';
import { Router } from 'express-serve-static-core';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return createRouter({
logger: env.logger,
config: env.config,
});
}
Loading

0 comments on commit 7dc76b1

Please sign in to comment.