@backstage/plugin-scaffolder-backend-module-gitea 0.0.0-nightly-20240217020958
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 +16 -0
- package/README.md +110 -0
- package/dist/index.cjs.js +403 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @backstage/plugin-scaffolder-backend-module-gitea
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20240217020958
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 458bf21: Created a gitea module for the scaffolder. This module provides a new action "publish:gitea" able to create a gitea repository owned by an organization. See: https://gitea.com/api/swagger#/organization/createOrgRepo
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/backend-plugin-api@0.0.0-nightly-20240217020958
|
|
13
|
+
- @backstage/integration@0.0.0-nightly-20240217020958
|
|
14
|
+
- @backstage/plugin-scaffolder-node@0.0.0-nightly-20240217020958
|
|
15
|
+
- @backstage/config@1.1.1
|
|
16
|
+
- @backstage/errors@1.2.3
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# scaffolder-backend-module-gitea
|
|
2
|
+
|
|
3
|
+
Welcome to the `publish:gitea` action of the `scaffolder-gitea-backend`.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
To use this action, you will have to add the package using the following command to be executed at the root of your backstage project:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
yarn add --cwd packages/backend
|
|
11
|
+
@backstage/plugin-scaffolder-backend-module-gitea
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Configure the action (if not yet done):
|
|
15
|
+
(you can check the [docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions) to see all options):
|
|
16
|
+
|
|
17
|
+
Before to create a template, include to your `app-config.yaml` file the
|
|
18
|
+
gitea host and credentials under the `integrations:` section
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
integrations:
|
|
22
|
+
gitea:
|
|
23
|
+
- host: gitea.com
|
|
24
|
+
username: '<GITEA_USER>'
|
|
25
|
+
password: '<GITEA_PASSWORD>'
|
|
26
|
+
- host: localhost:3333
|
|
27
|
+
username: '<GITEA_LOCALHOST_USER>'
|
|
28
|
+
password: '<GITEA_LOCALHOST_PASSWORD>'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**NOTE**: As backstage will issue HTTPS/TLS requests to the gitea instance, it is needed to configure `gitea` with a valid certificate or at least with a
|
|
32
|
+
self-signed certificate `gitea cert --host localhost -ca`. Don't forget to set the env var `NODE_EXTRA_CA_CERTS` to point to the CA file before launching backstage !
|
|
33
|
+
|
|
34
|
+
When done, you can create a template which:
|
|
35
|
+
|
|
36
|
+
- Declare the `RepoUrlPicker` within the `spec/parameters` section to select the gitea hosts
|
|
37
|
+
- Include a step able to publish by example the newly generated project using the action `action: publish:gitea`
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
apiVersion: scaffolder.backstage.io/v1beta3
|
|
41
|
+
kind: Template
|
|
42
|
+
metadata:
|
|
43
|
+
name: quarkus-web-template
|
|
44
|
+
title: Quarkus Hello world
|
|
45
|
+
description: Create a simple microservice using Quarkus
|
|
46
|
+
tags:
|
|
47
|
+
- java
|
|
48
|
+
- quarkus
|
|
49
|
+
spec:
|
|
50
|
+
owner: quarkus
|
|
51
|
+
type: service
|
|
52
|
+
parameters:
|
|
53
|
+
- title: Git repository Information
|
|
54
|
+
required:
|
|
55
|
+
- repoUrl
|
|
56
|
+
properties:
|
|
57
|
+
repoUrl:
|
|
58
|
+
title: Repository Location
|
|
59
|
+
type: string
|
|
60
|
+
ui:field: RepoUrlPicker
|
|
61
|
+
ui:options:
|
|
62
|
+
allowedHosts:
|
|
63
|
+
- gitea.<YOUR_DOMAIN>:<PORT>
|
|
64
|
+
- localhost:<PORT>
|
|
65
|
+
|
|
66
|
+
steps:
|
|
67
|
+
- id: template
|
|
68
|
+
name: Generating component
|
|
69
|
+
action: fetch:template
|
|
70
|
+
input:
|
|
71
|
+
url: ./skeleton
|
|
72
|
+
copyWithoutTemplating:
|
|
73
|
+
- .github/workflows/*
|
|
74
|
+
values:
|
|
75
|
+
component_id: ${{ parameters.component_id }}
|
|
76
|
+
namespace: ${{ parameters.component_id }}-dev
|
|
77
|
+
description: ${{ parameters.description }}
|
|
78
|
+
group_id: ${{ parameters.group_id }}
|
|
79
|
+
artifact_id: ${{ parameters.artifact_id }}
|
|
80
|
+
java_package_name: ${{ parameters.java_package_name }}
|
|
81
|
+
owner: ${{ parameters.owner }}
|
|
82
|
+
destination: ${{ (parameters.repoUrl | parseRepoUrl).owner }}/${{ (parameters.repoUrl | parseRepoUrl).repo }
|
|
83
|
+
port: 8080
|
|
84
|
+
|
|
85
|
+
- id: publish
|
|
86
|
+
name: Publishing to a gitea git repository
|
|
87
|
+
action: publish:gitea
|
|
88
|
+
input:
|
|
89
|
+
description: This is ${{ parameters.component_id }}
|
|
90
|
+
repoUrl: ${{ parameters.repoUrl }}
|
|
91
|
+
defaultBranch: main
|
|
92
|
+
|
|
93
|
+
- id: register
|
|
94
|
+
if: ${{ parameters.dryRun !== true }}
|
|
95
|
+
name: Register
|
|
96
|
+
action: catalog:register
|
|
97
|
+
input:
|
|
98
|
+
repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
|
|
99
|
+
catalogInfoPath: 'main/catalog-info.yaml'
|
|
100
|
+
|
|
101
|
+
output:
|
|
102
|
+
links:
|
|
103
|
+
- title: Source Code Repository
|
|
104
|
+
url: ${{ steps.publish.output.remoteUrl }}
|
|
105
|
+
- title: Open Component in catalog
|
|
106
|
+
icon: catalog
|
|
107
|
+
entityRef: ${{ steps.register.output.entityRef }}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Access the newly gitea repository created using the `repoContentsUrl` ;-)
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var errors = require('@backstage/errors');
|
|
6
|
+
var integration = require('@backstage/integration');
|
|
7
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
8
|
+
var yaml = require('yaml');
|
|
9
|
+
var crypto = require('crypto');
|
|
10
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
11
|
+
var alpha = require('@backstage/plugin-scaffolder-node/alpha');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
|
|
16
|
+
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
17
|
+
|
|
18
|
+
const examples = [
|
|
19
|
+
{
|
|
20
|
+
description: "Initializes a Gitea repository using the content of the workspace and publish it to Gitea with default configuration.",
|
|
21
|
+
example: yaml__default["default"].stringify({
|
|
22
|
+
steps: [
|
|
23
|
+
{
|
|
24
|
+
id: "publish",
|
|
25
|
+
action: "publish:gitea",
|
|
26
|
+
name: "Publish to Gitea",
|
|
27
|
+
input: {
|
|
28
|
+
repoUrl: "gitea.com?repo=repo&owner=owner"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
})
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
description: "Initializes a Gitea repository with a description.",
|
|
36
|
+
example: yaml__default["default"].stringify({
|
|
37
|
+
steps: [
|
|
38
|
+
{
|
|
39
|
+
id: "publish",
|
|
40
|
+
action: "publish:gitea",
|
|
41
|
+
name: "Publish to Gitea",
|
|
42
|
+
input: {
|
|
43
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
44
|
+
description: "Initialize a gitea repository"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
})
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
description: "Initializes a Gitea repository with a default Branch, if not set defaults to main",
|
|
52
|
+
example: yaml__default["default"].stringify({
|
|
53
|
+
steps: [
|
|
54
|
+
{
|
|
55
|
+
id: "publish",
|
|
56
|
+
action: "publish:gitea",
|
|
57
|
+
name: "Publish to Gitea",
|
|
58
|
+
input: {
|
|
59
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
60
|
+
defaultBranch: "main"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
description: "Initializes a Gitea repository with an initial commit message, if not set defaults to initial commit",
|
|
68
|
+
example: yaml__default["default"].stringify({
|
|
69
|
+
steps: [
|
|
70
|
+
{
|
|
71
|
+
id: "publish",
|
|
72
|
+
action: "publish:gitea",
|
|
73
|
+
name: "Publish to Gitea",
|
|
74
|
+
input: {
|
|
75
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
76
|
+
gitCommitMessage: "Initial Commit Message"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
description: "Initializes a Gitea repository with a repo Author Name, if not set defaults to Scaffolder",
|
|
84
|
+
example: yaml__default["default"].stringify({
|
|
85
|
+
steps: [
|
|
86
|
+
{
|
|
87
|
+
id: "publish",
|
|
88
|
+
action: "publish:gitea",
|
|
89
|
+
name: "Publish to Gitea",
|
|
90
|
+
input: {
|
|
91
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
92
|
+
gitAuthorName: "John Doe"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
description: "Initializes a Gitea repository with a repo Author Email",
|
|
100
|
+
example: yaml__default["default"].stringify({
|
|
101
|
+
steps: [
|
|
102
|
+
{
|
|
103
|
+
id: "publish",
|
|
104
|
+
action: "publish:gitea",
|
|
105
|
+
name: "Publish to Gitea",
|
|
106
|
+
input: {
|
|
107
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
108
|
+
gitAuthorEmail: "johndoe@email.com"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository",
|
|
116
|
+
example: yaml__default["default"].stringify({
|
|
117
|
+
steps: [
|
|
118
|
+
{
|
|
119
|
+
id: "publish",
|
|
120
|
+
action: "publish:gitea",
|
|
121
|
+
name: "Publish to Gitea",
|
|
122
|
+
input: {
|
|
123
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
124
|
+
sourcePath: "repository/"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
description: "Initializes a Gitea repository with all properties being set",
|
|
132
|
+
example: yaml__default["default"].stringify({
|
|
133
|
+
steps: [
|
|
134
|
+
{
|
|
135
|
+
id: "publish",
|
|
136
|
+
action: "publish:gitea",
|
|
137
|
+
name: "Publish to Gitea",
|
|
138
|
+
input: {
|
|
139
|
+
repoUrl: "gitea.com?repo=repo&owner=owner",
|
|
140
|
+
description: "Initialize a gitea repository",
|
|
141
|
+
defaultBranch: "staging",
|
|
142
|
+
gitCommitMessage: "Initial Commit Message",
|
|
143
|
+
gitAuthorName: "John Doe",
|
|
144
|
+
gitAuthorEmail: "johndoe@email.com",
|
|
145
|
+
sourcePath: "repository/"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
const checkGiteaContentUrl = async (config, options) => {
|
|
154
|
+
const { owner, repo, defaultBranch } = options;
|
|
155
|
+
let response;
|
|
156
|
+
const getOptions = {
|
|
157
|
+
method: "GET"
|
|
158
|
+
};
|
|
159
|
+
try {
|
|
160
|
+
response = await fetch(
|
|
161
|
+
`${config.baseUrl}/${owner}/${repo}/src/branch/${defaultBranch}`,
|
|
162
|
+
getOptions
|
|
163
|
+
);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Unable to get the repository: ${owner}/${repo} metadata , ${e}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return response;
|
|
170
|
+
};
|
|
171
|
+
const checkGiteaOrg = async (config, options) => {
|
|
172
|
+
const { owner } = options;
|
|
173
|
+
let response;
|
|
174
|
+
const getOptions = {
|
|
175
|
+
method: "GET",
|
|
176
|
+
headers: {
|
|
177
|
+
...integration.getGiteaRequestOptions(config).headers,
|
|
178
|
+
"Content-Type": "application/json"
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
try {
|
|
182
|
+
response = await fetch(
|
|
183
|
+
`${config.baseUrl}/api/v1/orgs/${owner}`,
|
|
184
|
+
getOptions
|
|
185
|
+
);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
throw new Error(`Unable to get the Organization: ${owner}, ${e}`);
|
|
188
|
+
}
|
|
189
|
+
if (response.status !== 200) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Organization ${owner} do not exist. Please create it first !`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const createGiteaProject = async (config, options) => {
|
|
196
|
+
const { projectName, description, owner } = options;
|
|
197
|
+
let response;
|
|
198
|
+
const postOptions = {
|
|
199
|
+
method: "POST",
|
|
200
|
+
body: JSON.stringify({
|
|
201
|
+
name: projectName,
|
|
202
|
+
description
|
|
203
|
+
}),
|
|
204
|
+
headers: {
|
|
205
|
+
...integration.getGiteaRequestOptions(config).headers,
|
|
206
|
+
"Content-Type": "application/json"
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
response = await fetch(
|
|
211
|
+
`${config.baseUrl}/api/v1/orgs/${owner}/repos`,
|
|
212
|
+
postOptions
|
|
213
|
+
);
|
|
214
|
+
} catch (e) {
|
|
215
|
+
throw new Error(`Unable to create repository, ${e}`);
|
|
216
|
+
}
|
|
217
|
+
if (response.status !== 201) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Unable to create repository, ${response.status} ${response.statusText}, ${await response.text()}`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const generateCommitMessage = (config, commitSubject) => {
|
|
224
|
+
const changeId = crypto__default["default"].randomBytes(20).toString("hex");
|
|
225
|
+
const msg = `${config.getOptionalString("scaffolder.defaultCommitMessage") || commitSubject}
|
|
226
|
+
|
|
227
|
+
Change-Id: I${changeId}`;
|
|
228
|
+
return msg;
|
|
229
|
+
};
|
|
230
|
+
async function checkAvailabilityGiteaRepository(maxDuration, integrationConfig, options) {
|
|
231
|
+
var _a;
|
|
232
|
+
const startTimestamp = Date.now();
|
|
233
|
+
const { owner, repo, defaultBranch, ctx } = options;
|
|
234
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
235
|
+
let response;
|
|
236
|
+
while (Date.now() - startTimestamp < maxDuration) {
|
|
237
|
+
if ((_a = ctx.signal) == null ? void 0 : _a.aborted)
|
|
238
|
+
return;
|
|
239
|
+
response = await checkGiteaContentUrl(integrationConfig, {
|
|
240
|
+
owner,
|
|
241
|
+
repo,
|
|
242
|
+
defaultBranch
|
|
243
|
+
});
|
|
244
|
+
if (response.status !== 200) {
|
|
245
|
+
await sleep(1e3);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function createPublishGiteaAction(options) {
|
|
250
|
+
const { integrations, config } = options;
|
|
251
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
252
|
+
id: "publish:gitea",
|
|
253
|
+
description: "Initializes a git repository using the content of the workspace, and publishes it to Gitea.",
|
|
254
|
+
examples,
|
|
255
|
+
schema: {
|
|
256
|
+
input: {
|
|
257
|
+
type: "object",
|
|
258
|
+
required: ["repoUrl"],
|
|
259
|
+
properties: {
|
|
260
|
+
repoUrl: {
|
|
261
|
+
title: "Repository Location",
|
|
262
|
+
type: "string"
|
|
263
|
+
},
|
|
264
|
+
description: {
|
|
265
|
+
title: "Repository Description",
|
|
266
|
+
type: "string"
|
|
267
|
+
},
|
|
268
|
+
defaultBranch: {
|
|
269
|
+
title: "Default Branch",
|
|
270
|
+
type: "string",
|
|
271
|
+
description: `Sets the default branch on the repository. The default value is 'main'`
|
|
272
|
+
},
|
|
273
|
+
gitCommitMessage: {
|
|
274
|
+
title: "Git Commit Message",
|
|
275
|
+
type: "string",
|
|
276
|
+
description: `Sets the commit message on the repository. The default value is 'initial commit'`
|
|
277
|
+
},
|
|
278
|
+
gitAuthorName: {
|
|
279
|
+
title: "Default Author Name",
|
|
280
|
+
type: "string",
|
|
281
|
+
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
282
|
+
},
|
|
283
|
+
gitAuthorEmail: {
|
|
284
|
+
title: "Default Author Email",
|
|
285
|
+
type: "string",
|
|
286
|
+
description: `Sets the default author email for the commit.`
|
|
287
|
+
},
|
|
288
|
+
sourcePath: {
|
|
289
|
+
title: "Source Path",
|
|
290
|
+
type: "string",
|
|
291
|
+
description: `Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.`
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
output: {
|
|
296
|
+
type: "object",
|
|
297
|
+
properties: {
|
|
298
|
+
remoteUrl: {
|
|
299
|
+
title: "A URL to the repository with the provider",
|
|
300
|
+
type: "string"
|
|
301
|
+
},
|
|
302
|
+
repoContentsUrl: {
|
|
303
|
+
title: "A URL to the root of the repository",
|
|
304
|
+
type: "string"
|
|
305
|
+
},
|
|
306
|
+
commitHash: {
|
|
307
|
+
title: "The git commit hash of the initial commit",
|
|
308
|
+
type: "string"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
async handler(ctx) {
|
|
314
|
+
const {
|
|
315
|
+
repoUrl,
|
|
316
|
+
description,
|
|
317
|
+
defaultBranch = "main",
|
|
318
|
+
gitAuthorName,
|
|
319
|
+
gitAuthorEmail,
|
|
320
|
+
gitCommitMessage = "initial commit",
|
|
321
|
+
sourcePath
|
|
322
|
+
} = ctx.input;
|
|
323
|
+
const { repo, host, owner } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
324
|
+
const integrationConfig = integrations.gitea.byHost(host);
|
|
325
|
+
if (!integrationConfig) {
|
|
326
|
+
throw new errors.InputError(
|
|
327
|
+
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const { username, password } = integrationConfig.config;
|
|
331
|
+
if (!username || !password) {
|
|
332
|
+
throw new Error("Credentials for the gitea ${host} required.");
|
|
333
|
+
}
|
|
334
|
+
if (owner) {
|
|
335
|
+
await checkGiteaOrg(integrationConfig.config, { owner });
|
|
336
|
+
}
|
|
337
|
+
await createGiteaProject(integrationConfig.config, {
|
|
338
|
+
description,
|
|
339
|
+
owner,
|
|
340
|
+
projectName: repo
|
|
341
|
+
});
|
|
342
|
+
const auth = {
|
|
343
|
+
username,
|
|
344
|
+
password
|
|
345
|
+
};
|
|
346
|
+
const gitAuthorInfo = {
|
|
347
|
+
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
348
|
+
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
349
|
+
};
|
|
350
|
+
const remoteUrl = `${integrationConfig.config.baseUrl}/${owner}/${repo}.git`;
|
|
351
|
+
const commitResult = await pluginScaffolderNode.initRepoAndPush({
|
|
352
|
+
dir: pluginScaffolderNode.getRepoSourceDirectory(ctx.workspacePath, sourcePath),
|
|
353
|
+
remoteUrl,
|
|
354
|
+
auth,
|
|
355
|
+
defaultBranch,
|
|
356
|
+
logger: ctx.logger,
|
|
357
|
+
commitMessage: generateCommitMessage(config, gitCommitMessage),
|
|
358
|
+
gitAuthorInfo
|
|
359
|
+
});
|
|
360
|
+
const maxDuration = 2e4;
|
|
361
|
+
await checkAvailabilityGiteaRepository(
|
|
362
|
+
maxDuration,
|
|
363
|
+
integrationConfig.config,
|
|
364
|
+
{
|
|
365
|
+
owner,
|
|
366
|
+
repo,
|
|
367
|
+
defaultBranch,
|
|
368
|
+
ctx
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
const repoContentsUrl = `${integrationConfig.config.baseUrl}/${owner}/${repo}/src/branch/${defaultBranch}/`;
|
|
372
|
+
ctx.output("remoteUrl", remoteUrl);
|
|
373
|
+
ctx.output("commitHash", commitResult == null ? void 0 : commitResult.commitHash);
|
|
374
|
+
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const giteaModule = backendPluginApi.createBackendModule({
|
|
380
|
+
pluginId: "scaffolder",
|
|
381
|
+
moduleId: "gitea",
|
|
382
|
+
register({ registerInit }) {
|
|
383
|
+
registerInit({
|
|
384
|
+
deps: {
|
|
385
|
+
scaffolder: alpha.scaffolderActionsExtensionPoint,
|
|
386
|
+
config: backendPluginApi.coreServices.rootConfig
|
|
387
|
+
},
|
|
388
|
+
async init({ scaffolder, config }) {
|
|
389
|
+
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
390
|
+
scaffolder.addActions(
|
|
391
|
+
createPublishGiteaAction({
|
|
392
|
+
integrations,
|
|
393
|
+
config
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
exports.createPublishGiteaAction = createPublishGiteaAction;
|
|
402
|
+
exports["default"] = giteaModule;
|
|
403
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/actions/gitea.examples.ts","../src/actions/gitea.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a Gitea repository using the content of the workspace and publish it to Gitea with default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a Gitea repository with a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n description: 'Initialize a gitea repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a Gitea repository with a default Branch, if not set defaults to main',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n defaultBranch: 'main',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a Gitea repository with an initial commit message, if not set defaults to initial commit',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n gitCommitMessage: 'Initial Commit Message',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a Gitea repository with a repo Author Name, if not set defaults to Scaffolder',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n gitAuthorName: 'John Doe',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a Gitea repository with a repo Author Email',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n gitAuthorEmail: 'johndoe@email.com',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n sourcePath: 'repository/',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a Gitea repository with all properties being set',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitea',\n name: 'Publish to Gitea',\n input: {\n repoUrl: 'gitea.com?repo=repo&owner=owner',\n description: 'Initialize a gitea repository',\n defaultBranch: 'staging',\n gitCommitMessage: 'Initial Commit Message',\n gitAuthorName: 'John Doe',\n gitAuthorEmail: 'johndoe@email.com',\n sourcePath: 'repository/',\n },\n },\n ],\n }),\n },\n];\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { Config } from '@backstage/config';\nimport {\n getGiteaRequestOptions,\n GiteaIntegrationConfig,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n ActionContext,\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './gitea.examples';\nimport crypto from 'crypto';\n\nconst checkGiteaContentUrl = async (\n config: GiteaIntegrationConfig,\n options: {\n owner?: string;\n repo: string;\n defaultBranch?: string;\n },\n): Promise<Response> => {\n const { owner, repo, defaultBranch } = options;\n let response: Response;\n const getOptions: RequestInit = {\n method: 'GET',\n };\n\n try {\n response = await fetch(\n `${config.baseUrl}/${owner}/${repo}/src/branch/${defaultBranch}`,\n getOptions,\n );\n } catch (e) {\n throw new Error(\n `Unable to get the repository: ${owner}/${repo} metadata , ${e}`,\n );\n }\n return response;\n};\n\nconst checkGiteaOrg = async (\n config: GiteaIntegrationConfig,\n options: {\n owner: string;\n },\n): Promise<void> => {\n const { owner } = options;\n let response: Response;\n // check first if the org = owner exists\n const getOptions: RequestInit = {\n method: 'GET',\n headers: {\n ...getGiteaRequestOptions(config).headers,\n 'Content-Type': 'application/json',\n },\n };\n try {\n response = await fetch(\n `${config.baseUrl}/api/v1/orgs/${owner}`,\n getOptions,\n );\n } catch (e) {\n throw new Error(`Unable to get the Organization: ${owner}, ${e}`);\n }\n if (response.status !== 200) {\n throw new Error(\n `Organization ${owner} do not exist. Please create it first !`,\n );\n }\n};\n\nconst createGiteaProject = async (\n config: GiteaIntegrationConfig,\n options: {\n projectName: string;\n owner?: string;\n description: string;\n },\n): Promise<void> => {\n const { projectName, description, owner } = options;\n\n /*\n Several options exist to create a repository using either the user or organisation\n User: https://gitea.com/api/swagger#/user/createCurrentUserRepo\n Api: URL/api/v1/user/repos\n Remark: The user is the username defined part of the backstage integration config for the gitea URL !\n\n Org: https://gitea.com/api/swagger#/organization/createOrgRepo\n Api: URL/api/v1/orgs/${org_owner}/repos\n This is the default scenario that we support currently\n */\n let response: Response;\n\n const postOptions: RequestInit = {\n method: 'POST',\n body: JSON.stringify({\n name: projectName,\n description,\n }),\n headers: {\n ...getGiteaRequestOptions(config).headers,\n 'Content-Type': 'application/json',\n },\n };\n try {\n response = await fetch(\n `${config.baseUrl}/api/v1/orgs/${owner}/repos`,\n postOptions,\n );\n } catch (e) {\n throw new Error(`Unable to create repository, ${e}`);\n }\n if (response.status !== 201) {\n throw new Error(\n `Unable to create repository, ${response.status} ${\n response.statusText\n }, ${await response.text()}`,\n );\n }\n};\n\nconst generateCommitMessage = (\n config: Config,\n commitSubject?: string,\n): string => {\n const changeId = crypto.randomBytes(20).toString('hex');\n const msg = `${\n config.getOptionalString('scaffolder.defaultCommitMessage') || commitSubject\n }\\n\\nChange-Id: I${changeId}`;\n return msg;\n};\n\nasync function checkAvailabilityGiteaRepository(\n maxDuration: number,\n integrationConfig: GiteaIntegrationConfig,\n options: {\n owner?: string;\n repo: string;\n defaultBranch: string;\n ctx: ActionContext<any>;\n },\n) {\n const startTimestamp = Date.now();\n\n const { owner, repo, defaultBranch, ctx } = options;\n const sleep = (ms: number | undefined) => new Promise(r => setTimeout(r, ms));\n let response: Response;\n\n while (Date.now() - startTimestamp < maxDuration) {\n if (ctx.signal?.aborted) return;\n\n response = await checkGiteaContentUrl(integrationConfig, {\n owner,\n repo,\n defaultBranch,\n });\n\n if (response.status !== 200) {\n // Repository is not yet available/accessible ...\n await sleep(1000);\n }\n }\n}\n\n/**\n * Creates a new action that initializes a git repository using the content of the workspace.\n * and publishes it to a Gitea instance.\n * @public\n */\nexport function createPublishGiteaAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n description: string;\n defaultBranch?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n sourcePath?: string;\n }>({\n id: 'publish:gitea',\n description:\n 'Initializes a git repository using the content of the workspace, and publishes it to Gitea.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n description: {\n title: 'Repository Description',\n type: 'string',\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'main'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n type: 'string',\n description: `Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n description,\n defaultBranch = 'main',\n gitAuthorName,\n gitAuthorEmail,\n gitCommitMessage = 'initial commit',\n sourcePath,\n } = ctx.input;\n\n const { repo, host, owner } = parseRepoUrl(repoUrl, integrations);\n\n const integrationConfig = integrations.gitea.byHost(host);\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n const { username, password } = integrationConfig.config;\n\n if (!username || !password) {\n throw new Error('Credentials for the gitea ${host} required.');\n }\n\n // check if the org exists within the gitea server\n if (owner) {\n await checkGiteaOrg(integrationConfig.config, { owner });\n }\n\n await createGiteaProject(integrationConfig.config, {\n description,\n owner: owner,\n projectName: repo,\n });\n\n const auth = {\n username: username,\n password: password,\n };\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n // The owner to be used should be either the org name or user authenticated with the gitea server\n const remoteUrl = `${integrationConfig.config.baseUrl}/${owner}/${repo}.git`;\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),\n remoteUrl,\n auth,\n defaultBranch,\n logger: ctx.logger,\n commitMessage: generateCommitMessage(config, gitCommitMessage),\n gitAuthorInfo,\n });\n\n // Check if the gitea repo URL is available before to exit\n const maxDuration = 20000; // 20 seconds\n await checkAvailabilityGiteaRepository(\n maxDuration,\n integrationConfig.config,\n {\n owner,\n repo,\n defaultBranch,\n ctx,\n },\n );\n\n const repoContentsUrl = `${integrationConfig.config.baseUrl}/${owner}/${repo}/src/branch/${defaultBranch}/`;\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('repoContentsUrl', repoContentsUrl);\n },\n });\n}\n","/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n createBackendModule,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport { createPublishGiteaAction } from './actions';\nimport { ScmIntegrations } from '@backstage/integration';\n\n/**\n * @public\n * The Gitea Module for the Scaffolder Backend\n */\nexport const giteaModule = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'gitea',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ scaffolder, config }) {\n const integrations = ScmIntegrations.fromConfig(config);\n scaffolder.addActions(\n createPublishGiteaAction({\n integrations,\n config,\n }),\n );\n },\n });\n },\n});\n"],"names":["yaml","getGiteaRequestOptions","crypto","createTemplateAction","parseRepoUrl","InputError","initRepoAndPush","getRepoSourceDirectory","createBackendModule","scaffolderActionsExtensionPoint","coreServices","ScmIntegrations"],"mappings":";;;;;;;;;;;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,uHAAA;AAAA,IACF,OAAA,EAASA,yBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,eAAA;AAAA,UACR,IAAM,EAAA,kBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,iCAAA;AAAA,WACX;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oDAAA;AAAA,IACb,OAAA,EAASA,yBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,eAAA;AAAA,UACR,IAAM,EAAA,kBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,iCAAA;AAAA,YACT,WAAa,EAAA,+BAAA;AAAA,WACf;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,mFAAA;AAAA,IACF,OAAA,EAASA,yBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AA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AAmB,eAAe,CAAA,CAAA;AAAA,KAC/C;AAAA,GACD,CAAA,CAAA;AACH;;AC9TO,MAAM,cAAcC,oCAAoB,CAAA;AAAA,EAC7C,QAAU,EAAA,YAAA;AAAA,EACV,QAAU,EAAA,OAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAgB,EAAA;AACzB,IAAa,YAAA,CAAA;AAAA,MACX,IAAM,EAAA;AAAA,QACJ,UAAY,EAAAC,qCAAA;AAAA,QACZ,QAAQC,6BAAa,CAAA,UAAA;AAAA,OACvB;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAA,EAAY,QAAU,EAAA;AACjC,QAAM,MAAA,YAAA,GAAeC,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA,CAAA;AACtD,QAAW,UAAA,CAAA,UAAA;AAAA,UACT,wBAAyB,CAAA;AAAA,YACvB,YAAA;AAAA,YACA,MAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
|
|
2
|
+
import * as _backstage_types from '@backstage/types';
|
|
3
|
+
import { Config } from '@backstage/config';
|
|
4
|
+
import { ScmIntegrationRegistry } from '@backstage/integration';
|
|
5
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new action that initializes a git repository using the content of the workspace.
|
|
9
|
+
* and publishes it to a Gitea instance.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
declare function createPublishGiteaAction(options: {
|
|
13
|
+
integrations: ScmIntegrationRegistry;
|
|
14
|
+
config: Config;
|
|
15
|
+
}): _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
16
|
+
repoUrl: string;
|
|
17
|
+
description: string;
|
|
18
|
+
defaultBranch?: string | undefined;
|
|
19
|
+
gitCommitMessage?: string | undefined;
|
|
20
|
+
gitAuthorName?: string | undefined;
|
|
21
|
+
gitAuthorEmail?: string | undefined;
|
|
22
|
+
sourcePath?: string | undefined;
|
|
23
|
+
}, _backstage_types.JsonObject>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
* The Gitea Module for the Scaffolder Backend
|
|
28
|
+
*/
|
|
29
|
+
declare const giteaModule: () => _backstage_backend_plugin_api.BackendFeature;
|
|
30
|
+
|
|
31
|
+
export { createPublishGiteaAction, giteaModule as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-scaffolder-backend-module-gitea",
|
|
3
|
+
"description": "The gitea module for @backstage/plugin-scaffolder-backend",
|
|
4
|
+
"version": "0.0.0-nightly-20240217020958",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/backstage/backstage",
|
|
14
|
+
"directory": "plugins/scaffolder-backend-module-gitea"
|
|
15
|
+
},
|
|
16
|
+
"backstage": {
|
|
17
|
+
"role": "backend-plugin-module"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/index.cjs.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.cjs.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "backstage-cli package start",
|
|
29
|
+
"build": "backstage-cli package build",
|
|
30
|
+
"lint": "backstage-cli package lint",
|
|
31
|
+
"test": "backstage-cli package test",
|
|
32
|
+
"clean": "backstage-cli package clean",
|
|
33
|
+
"prepack": "backstage-cli package prepack",
|
|
34
|
+
"postpack": "backstage-cli package postpack"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@backstage/backend-plugin-api": "^0.0.0-nightly-20240217020958",
|
|
38
|
+
"@backstage/config": "^1.1.1",
|
|
39
|
+
"@backstage/errors": "^1.2.3",
|
|
40
|
+
"@backstage/integration": "^0.0.0-nightly-20240217020958",
|
|
41
|
+
"@backstage/plugin-scaffolder-node": "^0.0.0-nightly-20240217020958",
|
|
42
|
+
"node-fetch": "^2.6.7",
|
|
43
|
+
"yaml": "^2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@backstage/backend-common": "^0.0.0-nightly-20240217020958",
|
|
47
|
+
"@backstage/backend-test-utils": "^0.0.0-nightly-20240217020958",
|
|
48
|
+
"@backstage/cli": "^0.0.0-nightly-20240217020958",
|
|
49
|
+
"msw": "^1.0.0"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist"
|
|
53
|
+
]
|
|
54
|
+
}
|