@backstage/plugin-scaffolder-backend 1.8.0-next.0 → 1.8.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 1.8.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 5921b5ce49: - The GitLab Project ID for the `publish:gitlab:merge-request` action is now passed through the query parameter `project` in the `repoUrl`. It still allows people to not use the `projectid` and use the `repoUrl` with the `owner` and `repo` query parameters instead. This makes it easier to publish to repositories instead of writing the full path to the project.
8
+
3
9
  ## 1.8.0-next.0
4
10
 
5
11
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
- "version": "1.8.0-next.0",
3
+ "version": "1.8.0-next.1",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -565,7 +565,7 @@ sourcePath?: string | undefined;
565
565
  targetPath?: string | undefined;
566
566
  token?: string | undefined;
567
567
  commitAction?: "update" | "create" | "delete" | undefined;
568
- /** @deprecated Use projectPath instead */
568
+ /** @deprecated projectID passed as query parameters in the repoUrl */
569
569
  projectid?: string | undefined;
570
570
  removeSourceBranch?: boolean | undefined;
571
571
  assignee?: string | undefined;
@@ -565,7 +565,7 @@ sourcePath?: string | undefined;
565
565
  targetPath?: string | undefined;
566
566
  token?: string | undefined;
567
567
  commitAction?: "update" | "create" | "delete" | undefined;
568
- /** @deprecated Use projectPath instead */
568
+ /** @deprecated projectID passed as query parameters in the repoUrl */
569
569
  projectid?: string | undefined;
570
570
  removeSourceBranch?: boolean | undefined;
571
571
  assignee?: string | undefined;
package/dist/index.cjs.js CHANGED
@@ -851,34 +851,41 @@ const parseRepoUrl = (repoUrl, integrations) => {
851
851
  `No matching integration configuration for host ${host}, please check your integrations config`
852
852
  );
853
853
  }
854
- if (type === "bitbucket") {
855
- if (host === "bitbucket.org") {
856
- if (!workspace) {
857
- throw new errors.InputError(
858
- `Invalid repo URL passed to publisher: ${repoUrl}, missing workspace`
859
- );
854
+ const repo = parsed.searchParams.get("repo");
855
+ switch (type) {
856
+ case "bitbucket": {
857
+ if (host === "www.bitbucket.org") {
858
+ checkRequiredParams(parsed, "workspace");
860
859
  }
860
+ checkRequiredParams(parsed, "project", "repo");
861
+ break;
861
862
  }
862
- if (!project) {
863
- throw new errors.InputError(
864
- `Invalid repo URL passed to publisher: ${repoUrl}, missing project`
865
- );
863
+ case "gitlab": {
864
+ if (!project) {
865
+ checkRequiredParams(parsed, "owner", "repo");
866
+ }
867
+ break;
866
868
  }
867
- } else {
868
- if (!owner && type !== "gerrit") {
869
- throw new errors.InputError(
870
- `Invalid repo URL passed to publisher: ${repoUrl}, missing owner`
871
- );
869
+ case "gerrit": {
870
+ checkRequiredParams(parsed, "repo");
871
+ break;
872
+ }
873
+ default: {
874
+ checkRequiredParams(parsed, "repo", "owner");
875
+ break;
872
876
  }
873
- }
874
- const repo = parsed.searchParams.get("repo");
875
- if (!repo) {
876
- throw new errors.InputError(
877
- `Invalid repo URL passed to publisher: ${repoUrl}, missing repo`
878
- );
879
877
  }
880
878
  return { host, owner, repo, organization, workspace, project };
881
879
  };
880
+ function checkRequiredParams(repoUrl, ...params) {
881
+ for (let i = 0; i < params.length; i++) {
882
+ if (!repoUrl.searchParams.get(params[i])) {
883
+ throw new errors.InputError(
884
+ `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${params[i]}`
885
+ );
886
+ }
887
+ }
888
+ }
882
889
 
883
890
  const executeShellCommand = async (options) => {
884
891
  const {
@@ -3525,13 +3532,11 @@ const createPublishGitlabMergeRequestAction = (options) => {
3525
3532
  title,
3526
3533
  token: providedToken
3527
3534
  } = ctx.input;
3528
- const { host, owner, repo } = parseRepoUrl(repoUrl, integrations);
3529
- const projectPath = `${owner}/${repo}`;
3530
- if (ctx.input.projectid) {
3531
- const deprecationWarning = `Property "projectid" is deprecated and no longer to needed to create a MR`;
3532
- ctx.logger.warn(deprecationWarning);
3533
- console.warn(deprecationWarning);
3534
- }
3535
+ const { host, owner, repo, project } = parseRepoUrl(
3536
+ repoUrl,
3537
+ integrations
3538
+ );
3539
+ const repoID = project ? project : `${owner}/${repo}`;
3535
3540
  const integrationConfig = integrations.gitlab.byHost(host);
3536
3541
  if (!integrationConfig) {
3537
3542
  throw new errors.InputError(
@@ -3579,19 +3584,15 @@ const createPublishGitlabMergeRequestAction = (options) => {
3579
3584
  execute_filemode: file.executable
3580
3585
  };
3581
3586
  });
3582
- const projects = await api.Projects.show(projectPath);
3587
+ const projects = await api.Projects.show(repoID);
3583
3588
  const { default_branch: defaultBranch } = projects;
3584
3589
  try {
3585
- await api.Branches.create(
3586
- projectPath,
3587
- branchName,
3588
- String(defaultBranch)
3589
- );
3590
+ await api.Branches.create(repoID, branchName, String(defaultBranch));
3590
3591
  } catch (e) {
3591
3592
  throw new errors.InputError(`The branch creation failed ${e}`);
3592
3593
  }
3593
3594
  try {
3594
- await api.Commits.create(projectPath, branchName, title, actions);
3595
+ await api.Commits.create(repoID, branchName, ctx.input.title, actions);
3595
3596
  } catch (e) {
3596
3597
  throw new errors.InputError(
3597
3598
  `Committing the changes to ${branchName} failed ${e}`
@@ -3599,7 +3600,7 @@ const createPublishGitlabMergeRequestAction = (options) => {
3599
3600
  }
3600
3601
  try {
3601
3602
  const mergeRequestUrl = await api.MergeRequests.create(
3602
- projectPath,
3603
+ repoID,
3603
3604
  branchName,
3604
3605
  String(defaultBranch),
3605
3606
  title,
@@ -3611,8 +3612,8 @@ const createPublishGitlabMergeRequestAction = (options) => {
3611
3612
  ).then((mergeRequest) => {
3612
3613
  return mergeRequest.web_url;
3613
3614
  });
3614
- ctx.output("projectid", projectPath);
3615
- ctx.output("projectPath", projectPath);
3615
+ ctx.output("projectid", repoID);
3616
+ ctx.output("projectPath", repoID);
3616
3617
  ctx.output("mergeRequestUrl", mergeRequestUrl);
3617
3618
  } catch (e) {
3618
3619
  throw new errors.InputError(`Merge request creation failed${e}`);