From 5eb8c9b9efcd28f44ba8bf7e8251ecb4c58efb9a Mon Sep 17 00:00:00 2001 From: Thibault Cohen Date: Fri, 8 Jan 2021 10:27:40 -0500 Subject: [PATCH] Fix gitlab scaffoler publisher --- .changeset/metal-mangos-jog.md | 5 +++++ .../src/scaffolder/stages/publish/gitlab.ts | 6 +++++- .../src/scaffolder/stages/publish/helpers.ts | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/metal-mangos-jog.md diff --git a/.changeset/metal-mangos-jog.md b/.changeset/metal-mangos-jog.md new file mode 100644 index 0000000000..54bb43608d --- /dev/null +++ b/.changeset/metal-mangos-jog.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Fix gitlab scaffoler publisher diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.ts index 156a4a249c..6e4dc93023 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/gitlab.ts @@ -20,6 +20,7 @@ import { JsonValue } from '@backstage/config'; import { initRepoAndPush } from './helpers'; import { RequiredTemplateValues } from '../templater'; + export class GitlabPublisher implements PublisherBase { private readonly client: Gitlab; private readonly token: string; @@ -52,7 +53,10 @@ export class GitlabPublisher implements PublisherBase { private async createRemote( values: RequiredTemplateValues & Record, ) { - const [owner, name] = values.storePath.split('/'); + const pathElements = values.storePath.split('/'); + const name = pathElements[pathElements.length - 1]; + pathElements.pop(); + const owner = pathElements.join('/'); let targetNamespace = ((await this.client.Namespaces.show(owner)) as { id: number; diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/helpers.ts index ffefb88cf0..987c1a730c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/helpers.ts @@ -45,6 +45,10 @@ export async function initRepoAndPush({ dot: true, }); + await git.init({ + dir, + }); + for (const filepath of paths) { await git.add({ dir, filepath }); }