@backstage/plugin-scaffolder-backend 0.15.16 → 0.15.17

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,16 @@
1
1
  # @backstage/plugin-scaffolder-backend
2
2
 
3
+ ## 0.15.17
4
+
5
+ ### Patch Changes
6
+
7
+ - eec0750d8d: Makes cookiecutter a default, but optional action based on if a containerRunner argument is passed in to createRouter or createBuiltinActions
8
+ - ed52f74ab3: Adding changes to create GitLab Merge Request using custom action
9
+ - Updated dependencies
10
+ - @backstage/plugin-catalog-backend@0.19.2
11
+ - @backstage/backend-common@0.9.14
12
+ - @backstage/catalog-model@0.9.8
13
+
3
14
  ## 0.15.16
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -1622,6 +1622,120 @@ function createPublishGitlabAction(options) {
1622
1622
  });
1623
1623
  }
1624
1624
 
1625
+ const createPublishGitlabMergeRequestAction = (options) => {
1626
+ const { integrations } = options;
1627
+ return createTemplateAction({
1628
+ id: "publish:gitlab:merge-request",
1629
+ schema: {
1630
+ input: {
1631
+ required: ["projectid", "repoUrl", "targetPath", "branchName"],
1632
+ type: "object",
1633
+ properties: {
1634
+ repoUrl: {
1635
+ type: "string",
1636
+ title: "Repository Location",
1637
+ description: `Accepts the format 'gitlab.com/group_name/project_name' where 'project_name' is the repository name and 'group_name' is a group or username`
1638
+ },
1639
+ projectid: {
1640
+ type: "string",
1641
+ title: "projectid",
1642
+ description: "Project ID/Name(slug) of the Gitlab Project"
1643
+ },
1644
+ title: {
1645
+ type: "string",
1646
+ title: "Merge Request Name",
1647
+ description: "The name for the merge request"
1648
+ },
1649
+ description: {
1650
+ type: "string",
1651
+ title: "Merge Request Description",
1652
+ description: "The description of the merge request"
1653
+ },
1654
+ branchName: {
1655
+ type: "string",
1656
+ title: "Destination Branch name",
1657
+ description: "The description of the merge request"
1658
+ },
1659
+ targetPath: {
1660
+ type: "string",
1661
+ title: "Repository Subdirectory",
1662
+ description: "Subdirectory of repository to apply changes to"
1663
+ }
1664
+ }
1665
+ },
1666
+ output: {
1667
+ type: "object",
1668
+ properties: {
1669
+ projectid: {
1670
+ title: "Gitlab Project id/Name(slug)",
1671
+ type: "string"
1672
+ },
1673
+ mergeRequestURL: {
1674
+ title: "MergeRequest(MR) URL",
1675
+ type: "string",
1676
+ description: "Link to the merge request in GitLab"
1677
+ }
1678
+ }
1679
+ }
1680
+ },
1681
+ async handler(ctx) {
1682
+ const repoUrl = ctx.input.repoUrl;
1683
+ const { host } = parseRepoUrl(repoUrl, integrations);
1684
+ const integrationConfig = integrations.gitlab.byHost(host);
1685
+ const actions = [];
1686
+ const destinationBranch = ctx.input.branchName;
1687
+ if (!integrationConfig) {
1688
+ throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
1689
+ }
1690
+ if (!integrationConfig.config.token) {
1691
+ throw new errors.InputError(`No token available for host ${host}`);
1692
+ }
1693
+ const api = new node.Gitlab({
1694
+ host: integrationConfig.config.baseUrl,
1695
+ token: integrationConfig.config.token
1696
+ });
1697
+ const fileRoot = ctx.workspacePath;
1698
+ const localFilePaths = await globby__default["default"]([`${ctx.input.targetPath}/**`], {
1699
+ cwd: fileRoot,
1700
+ gitignore: true,
1701
+ dot: true
1702
+ });
1703
+ const fileContents = await Promise.all(localFilePaths.map((p) => fs.readFile(backendCommon.resolveSafeChildPath(fileRoot, p))));
1704
+ const repoFilePaths = localFilePaths.map((repoFilePath) => {
1705
+ return repoFilePath;
1706
+ });
1707
+ for (let i = 0; i < repoFilePaths.length; i++) {
1708
+ actions.push({
1709
+ action: "create",
1710
+ filePath: repoFilePaths[i],
1711
+ content: fileContents[i].toString()
1712
+ });
1713
+ }
1714
+ const projects = await api.Projects.show(ctx.input.projectid);
1715
+ const { default_branch: defaultBranch } = projects;
1716
+ try {
1717
+ await api.Branches.create(ctx.input.projectid, destinationBranch, String(defaultBranch));
1718
+ } catch (e) {
1719
+ throw new errors.InputError(`The branch creation failed ${e}`);
1720
+ }
1721
+ try {
1722
+ await api.Commits.create(ctx.input.projectid, destinationBranch, ctx.input.title, actions);
1723
+ } catch (e) {
1724
+ throw new errors.InputError(`Committing the changes to ${destinationBranch} failed ${e}`);
1725
+ }
1726
+ try {
1727
+ const mergeRequestUrl = await api.MergeRequests.create(ctx.input.projectid, destinationBranch, String(defaultBranch), ctx.input.title, { description: ctx.input.description }).then((mergeRequest) => {
1728
+ return mergeRequest.web_url;
1729
+ });
1730
+ ctx.output("projectid", ctx.input.projectid);
1731
+ ctx.output("mergeRequestUrl", mergeRequestUrl);
1732
+ } catch (e) {
1733
+ throw new errors.InputError(`Merge request creation failed${e}`);
1734
+ }
1735
+ }
1736
+ });
1737
+ };
1738
+
1625
1739
  function createGithubActionsDispatchAction(options) {
1626
1740
  const { integrations } = options;
1627
1741
  const octokitProvider = new OctokitProvider(integrations);
@@ -1768,16 +1882,11 @@ function createGithubWebhookAction(options) {
1768
1882
 
1769
1883
  const createBuiltinActions = (options) => {
1770
1884
  const { reader, integrations, containerRunner, catalogClient, config } = options;
1771
- return [
1885
+ const actions = [
1772
1886
  createFetchPlainAction({
1773
1887
  reader,
1774
1888
  integrations
1775
1889
  }),
1776
- pluginScaffolderBackendModuleCookiecutter.createFetchCookiecutterAction({
1777
- reader,
1778
- integrations,
1779
- containerRunner
1780
- }),
1781
1890
  createFetchTemplateAction({
1782
1891
  integrations,
1783
1892
  reader
@@ -1793,6 +1902,9 @@ const createBuiltinActions = (options) => {
1793
1902
  integrations,
1794
1903
  config
1795
1904
  }),
1905
+ createPublishGitlabMergeRequestAction({
1906
+ integrations
1907
+ }),
1796
1908
  createPublishBitbucketAction({
1797
1909
  integrations,
1798
1910
  config
@@ -1813,6 +1925,14 @@ const createBuiltinActions = (options) => {
1813
1925
  integrations
1814
1926
  })
1815
1927
  ];
1928
+ if (containerRunner) {
1929
+ actions.push(pluginScaffolderBackendModuleCookiecutter.createFetchCookiecutterAction({
1930
+ reader,
1931
+ integrations,
1932
+ containerRunner
1933
+ }));
1934
+ }
1935
+ return actions;
1816
1936
  };
1817
1937
 
1818
1938
  class TemplateActionRegistry {
@@ -2875,6 +2995,7 @@ exports.createPublishFileAction = createPublishFileAction;
2875
2995
  exports.createPublishGithubAction = createPublishGithubAction;
2876
2996
  exports.createPublishGithubPullRequestAction = createPublishGithubPullRequestAction;
2877
2997
  exports.createPublishGitlabAction = createPublishGitlabAction;
2998
+ exports.createPublishGitlabMergeRequestAction = createPublishGitlabMergeRequestAction;
2878
2999
  exports.createRouter = createRouter;
2879
3000
  exports.createTemplateAction = createTemplateAction;
2880
3001
  exports.fetchContents = fetchContents;