From 55542797a9cbb156792774c502b44155c985fa2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Marschollek?= Date: Mon, 7 Sep 2020 08:18:03 +0200 Subject: [PATCH] Add GitLab integration for scaffolder This adds a GitLab integration for the scaffolder backend. We're introduceing a preparer and a publisher for GitLab so that we can read templates from GitLab and publish them to a configured GitLab instance. The two instances don't need to be the same. For instance, templates could be public on gitlab.com, but the created repos will live in a hosted GitLab somewhere else. The publisher gets its own config object in `app-config.yaml` where the target instance and token can be specified. The service catalogue defines both `gitlab` and `gitlab/api` as processors. They are both handled by the same preparer. Closes #2372 --- app-config.yaml | 6 + docs/features/software-templates/index.md | 4 +- .../software-templates/installation.md | 46 +++- packages/backend/package.json | 1 + packages/backend/src/plugins/scaffolder.ts | 28 ++- .../packages/backend/package.json.hbs | 1 + .../backend/src/plugins/scaffolder.ts | 32 ++- plugins/scaffolder-backend/package.json | 4 +- .../__mocks__/@gitbeaker/node/index.ts | 33 +++ .../stages/{prepare => }/helpers.test.ts | 0 .../stages/{prepare => }/helpers.ts | 0 .../src/scaffolder/stages/index.ts | 1 + .../src/scaffolder/stages/prepare/file.ts | 2 +- .../src/scaffolder/stages/prepare/github.ts | 2 +- .../scaffolder/stages/prepare/gitlab.test.ts | 143 ++++++++++++ .../src/scaffolder/stages/prepare/gitlab.ts | 73 +++++++ .../src/scaffolder/stages/prepare/index.ts | 2 +- .../scaffolder/stages/prepare/preparers.ts | 5 +- .../src/scaffolder/stages/prepare/types.ts | 3 +- .../scaffolder/stages/publish/gitlab.test.ts | 205 ++++++++++++++++++ .../src/scaffolder/stages/publish/gitlab.ts | 90 ++++++++ .../src/scaffolder/stages/publish/index.ts | 2 + .../stages/publish/publishers.test.ts | 133 ++++++++++++ .../scaffolder/stages/publish/publishers.ts | 39 ++++ .../src/scaffolder/stages/publish/types.ts | 6 + .../src/scaffolder/stages/types.ts | 16 ++ .../src/service/router.test.ts | 5 +- .../scaffolder-backend/src/service/router.ts | 7 +- plugins/techdocs-backend/package.json | 2 +- yarn.lock | 83 ++++++- 30 files changed, 945 insertions(+), 29 deletions(-) create mode 100644 plugins/scaffolder-backend/src/scaffolder/__mocks__/@gitbeaker/node/index.ts rename plugins/scaffolder-backend/src/scaffolder/stages/{prepare => }/helpers.test.ts (100%) rename plugins/scaffolder-backend/src/scaffolder/stages/{prepare => }/helpers.ts (100%) create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/prepare/gitlab.test.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/prepare/gitlab.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.test.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/publish/publishers.test.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/publish/publishers.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/stages/types.ts diff --git a/app-config.yaml b/app-config.yaml index 3349a6585f..e018eef87e 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -116,6 +116,12 @@ scaffolder: $secret: env: GITHUB_ACCESS_TOKEN visibility: public # or 'internal' or 'private' + gitlab: + api: + baseUrl: https://gitlab.com + token: + $secret: + env: GITLAB_ACCESS_TOKEN auth: providers: diff --git a/docs/features/software-templates/index.md b/docs/features/software-templates/index.md index 7a8a3bc3dc..ae121f8029 100644 --- a/docs/features/software-templates/index.md +++ b/docs/features/software-templates/index.md @@ -8,8 +8,8 @@ you create Components inside Backstage The Software Templates part of Backstage is a tool that can help you create Components inside Backstage. By default, it has the ability to load skeletons of -code, template in some variables, and then publish the template to some location -like GitHub. +code, template in some variables, and then publish the template to some +locations like GitHub or GitLab.