@backstage/plugin-scaffolder-backend 1.2.0 → 1.3.0-next.0
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 +14 -0
- package/dist/index.cjs.js +149 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +18 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend
|
|
2
2
|
|
|
3
|
+
## 1.3.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 72dfcbc8bf: A new scaffolder action has been added: `gerrit:publish`
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 6901f6be4a: Adds more of an explanation when the `publish:github` scaffolder action fails to create a repository.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @backstage/backend-common@0.13.6-next.0
|
|
14
|
+
- @backstage/integration@1.2.1-next.0
|
|
15
|
+
- @backstage/plugin-catalog-backend@1.2.0-next.0
|
|
16
|
+
|
|
3
17
|
## 1.2.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -16,6 +16,7 @@ var child_process = require('child_process');
|
|
|
16
16
|
var stream = require('stream');
|
|
17
17
|
var azureDevopsNodeApi = require('azure-devops-node-api');
|
|
18
18
|
var fetch = require('node-fetch');
|
|
19
|
+
var crypto = require('crypto');
|
|
19
20
|
var octokit = require('octokit');
|
|
20
21
|
var lodash = require('lodash');
|
|
21
22
|
var octokitPluginCreatePullRequest = require('octokit-plugin-create-pull-request');
|
|
@@ -58,6 +59,7 @@ var yaml__namespace = /*#__PURE__*/_interopNamespace(yaml);
|
|
|
58
59
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
59
60
|
var globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
|
|
60
61
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
62
|
+
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
61
63
|
var ObservableImpl__default = /*#__PURE__*/_interopDefaultLegacy(ObservableImpl);
|
|
62
64
|
var winston__namespace = /*#__PURE__*/_interopNamespace(winston);
|
|
63
65
|
var nunjucks__default = /*#__PURE__*/_interopDefaultLegacy(nunjucks);
|
|
@@ -1578,6 +1580,138 @@ function createPublishFileAction() {
|
|
|
1578
1580
|
});
|
|
1579
1581
|
}
|
|
1580
1582
|
|
|
1583
|
+
const createGerritProject = async (config, options) => {
|
|
1584
|
+
const { projectName, parent, owner, description } = options;
|
|
1585
|
+
const fetchOptions = {
|
|
1586
|
+
method: "PUT",
|
|
1587
|
+
body: JSON.stringify({
|
|
1588
|
+
parent,
|
|
1589
|
+
description,
|
|
1590
|
+
owners: [owner],
|
|
1591
|
+
create_empty_commit: false
|
|
1592
|
+
}),
|
|
1593
|
+
headers: {
|
|
1594
|
+
...integration.getGerritRequestOptions(config).headers,
|
|
1595
|
+
"Content-Type": "application/json"
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
const response = await fetch__default["default"](`${config.baseUrl}/a/projects/${encodeURIComponent(projectName)}`, fetchOptions);
|
|
1599
|
+
if (response.status !== 201) {
|
|
1600
|
+
throw new Error(`Unable to create repository, ${response.status} ${response.statusText}, ${await response.text()}`);
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const generateCommitMessage = (config, commitSubject) => {
|
|
1604
|
+
const changeId = crypto__default["default"].randomBytes(20).toString("hex");
|
|
1605
|
+
const msg = `${config.getOptionalString("scaffolder.defaultCommitMessage") || commitSubject}
|
|
1606
|
+
|
|
1607
|
+
Change-Id: I${changeId}`;
|
|
1608
|
+
return msg;
|
|
1609
|
+
};
|
|
1610
|
+
function createPublishGerritAction(options) {
|
|
1611
|
+
const { integrations, config } = options;
|
|
1612
|
+
return createTemplateAction({
|
|
1613
|
+
id: "publish:gerrit",
|
|
1614
|
+
description: "Initializes a git repository of the content in the workspace, and publishes it to Gerrit.",
|
|
1615
|
+
schema: {
|
|
1616
|
+
input: {
|
|
1617
|
+
type: "object",
|
|
1618
|
+
required: ["repoUrl"],
|
|
1619
|
+
properties: {
|
|
1620
|
+
repoUrl: {
|
|
1621
|
+
title: "Repository Location",
|
|
1622
|
+
type: "string"
|
|
1623
|
+
},
|
|
1624
|
+
description: {
|
|
1625
|
+
title: "Repository Description",
|
|
1626
|
+
type: "string"
|
|
1627
|
+
},
|
|
1628
|
+
defaultBranch: {
|
|
1629
|
+
title: "Default Branch",
|
|
1630
|
+
type: "string",
|
|
1631
|
+
description: `Sets the default branch on the repository. The default value is 'master'`
|
|
1632
|
+
},
|
|
1633
|
+
gitCommitMessage: {
|
|
1634
|
+
title: "Git Commit Message",
|
|
1635
|
+
type: "string",
|
|
1636
|
+
description: `Sets the commit message on the repository. The default value is 'initial commit'`
|
|
1637
|
+
},
|
|
1638
|
+
gitAuthorName: {
|
|
1639
|
+
title: "Default Author Name",
|
|
1640
|
+
type: "string",
|
|
1641
|
+
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
1642
|
+
},
|
|
1643
|
+
gitAuthorEmail: {
|
|
1644
|
+
title: "Default Author Email",
|
|
1645
|
+
type: "string",
|
|
1646
|
+
description: `Sets the default author email for the commit.`
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
},
|
|
1650
|
+
output: {
|
|
1651
|
+
type: "object",
|
|
1652
|
+
properties: {
|
|
1653
|
+
remoteUrl: {
|
|
1654
|
+
title: "A URL to the repository with the provider",
|
|
1655
|
+
type: "string"
|
|
1656
|
+
},
|
|
1657
|
+
repoContentsUrl: {
|
|
1658
|
+
title: "A URL to the root of the repository",
|
|
1659
|
+
type: "string"
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
},
|
|
1664
|
+
async handler(ctx) {
|
|
1665
|
+
const {
|
|
1666
|
+
repoUrl,
|
|
1667
|
+
description,
|
|
1668
|
+
defaultBranch = "master",
|
|
1669
|
+
gitAuthorName,
|
|
1670
|
+
gitAuthorEmail,
|
|
1671
|
+
gitCommitMessage = "initial commit"
|
|
1672
|
+
} = ctx.input;
|
|
1673
|
+
const { repo, host, owner, workspace } = parseRepoUrl(repoUrl, integrations);
|
|
1674
|
+
const integrationConfig = integrations.gerrit.byHost(host);
|
|
1675
|
+
if (!integrationConfig) {
|
|
1676
|
+
throw new errors.InputError(`No matching integration configuration for host ${host}, please check your integrations config`);
|
|
1677
|
+
}
|
|
1678
|
+
if (!owner) {
|
|
1679
|
+
throw new errors.InputError(`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing owner`);
|
|
1680
|
+
}
|
|
1681
|
+
if (!workspace) {
|
|
1682
|
+
throw new errors.InputError(`Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing workspace`);
|
|
1683
|
+
}
|
|
1684
|
+
await createGerritProject(integrationConfig.config, {
|
|
1685
|
+
description,
|
|
1686
|
+
owner,
|
|
1687
|
+
projectName: repo,
|
|
1688
|
+
parent: workspace
|
|
1689
|
+
});
|
|
1690
|
+
const auth = {
|
|
1691
|
+
username: integrationConfig.config.username,
|
|
1692
|
+
password: integrationConfig.config.password
|
|
1693
|
+
};
|
|
1694
|
+
const gitAuthorInfo = {
|
|
1695
|
+
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
1696
|
+
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
1697
|
+
};
|
|
1698
|
+
const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`;
|
|
1699
|
+
await initRepoAndPush({
|
|
1700
|
+
dir: getRepoSourceDirectory(ctx.workspacePath, void 0),
|
|
1701
|
+
remoteUrl,
|
|
1702
|
+
auth,
|
|
1703
|
+
defaultBranch,
|
|
1704
|
+
logger: ctx.logger,
|
|
1705
|
+
commitMessage: generateCommitMessage(config, gitCommitMessage),
|
|
1706
|
+
gitAuthorInfo
|
|
1707
|
+
});
|
|
1708
|
+
const repoContentsUrl = `${integrationConfig.config.gitilesBaseUrl}/${repo}/+/refs/heads/${defaultBranch}`;
|
|
1709
|
+
ctx.output("remoteUrl", remoteUrl);
|
|
1710
|
+
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1581
1715
|
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
1582
1716
|
async function getOctokitOptions(options) {
|
|
1583
1717
|
var _a;
|
|
@@ -1803,7 +1937,16 @@ function createPublishGithubAction(options) {
|
|
|
1803
1937
|
allow_squash_merge: allowSquashMerge,
|
|
1804
1938
|
allow_rebase_merge: allowRebaseMerge
|
|
1805
1939
|
});
|
|
1806
|
-
|
|
1940
|
+
let newRepo;
|
|
1941
|
+
try {
|
|
1942
|
+
newRepo = (await repoCreationPromise).data;
|
|
1943
|
+
} catch (e) {
|
|
1944
|
+
errors.assertError(e);
|
|
1945
|
+
if (e.message === "Resource not accessible by integration") {
|
|
1946
|
+
ctx.logger.warn(`The GitHub app or token provided may not have the required permissions to create the ${user.data.type} repository ${owner}/${repo}.`);
|
|
1947
|
+
}
|
|
1948
|
+
throw new Error(`Failed to create the ${user.data.type} repository ${owner}/${repo}, ${e.message}`);
|
|
1949
|
+
}
|
|
1807
1950
|
if (access == null ? void 0 : access.startsWith(`${owner}/`)) {
|
|
1808
1951
|
const [, team] = access.split("/");
|
|
1809
1952
|
await client.rest.teams.addOrUpdateRepoPermissionsInOrg({
|
|
@@ -2566,6 +2709,10 @@ const createBuiltinActions = (options) => {
|
|
|
2566
2709
|
reader,
|
|
2567
2710
|
additionalTemplateFilters
|
|
2568
2711
|
}),
|
|
2712
|
+
createPublishGerritAction({
|
|
2713
|
+
integrations,
|
|
2714
|
+
config
|
|
2715
|
+
}),
|
|
2569
2716
|
createPublishGithubAction({
|
|
2570
2717
|
integrations,
|
|
2571
2718
|
config,
|
|
@@ -3504,6 +3651,7 @@ exports.createPublishBitbucketAction = createPublishBitbucketAction;
|
|
|
3504
3651
|
exports.createPublishBitbucketCloudAction = createPublishBitbucketCloudAction;
|
|
3505
3652
|
exports.createPublishBitbucketServerAction = createPublishBitbucketServerAction;
|
|
3506
3653
|
exports.createPublishFileAction = createPublishFileAction;
|
|
3654
|
+
exports.createPublishGerritAction = createPublishGerritAction;
|
|
3507
3655
|
exports.createPublishGithubAction = createPublishGithubAction;
|
|
3508
3656
|
exports.createPublishGithubPullRequestAction = createPublishGithubPullRequestAction;
|
|
3509
3657
|
exports.createPublishGitlabAction = createPublishGitlabAction;
|