@backstage/plugin-scaffolder-backend-module-azure 0.2.7 → 0.2.8-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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-azure
2
2
 
3
+ ## 0.2.8-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 2bd41ce: Made "publish:azure" action idempotent
8
+ - Updated dependencies
9
+ - @backstage/plugin-scaffolder-node@0.8.1-next.0
10
+ - @backstage/backend-plugin-api@1.2.1
11
+ - @backstage/config@1.3.2
12
+ - @backstage/errors@1.2.7
13
+ - @backstage/integration@1.16.2
14
+
3
15
  ## 0.2.7
4
16
 
5
17
  ### Patch Changes
@@ -115,32 +115,43 @@ function createPublishAzureAction(options) {
115
115
  const webApi = new azureDevopsNodeApi.WebApi(url, authHandler);
116
116
  const client = await webApi.getGitApi();
117
117
  const createOptions = { name: repo };
118
- const returnedRepo = await client.createRepository(
119
- createOptions,
120
- project
121
- );
122
- if (!returnedRepo) {
123
- throw new errors.InputError(
124
- `Unable to create the repository with Organization ${organization}, Project ${project} and Repo ${repo}.
118
+ const { remoteUrl, repositoryId, repoContentsUrl } = await ctx.checkpoint(
119
+ {
120
+ key: `create.repo.${repo}`,
121
+ fn: async () => {
122
+ const returnedRepo = await client.createRepository(
123
+ createOptions,
124
+ project
125
+ );
126
+ if (!returnedRepo) {
127
+ throw new errors.InputError(
128
+ `Unable to create the repository with Organization ${organization}, Project ${project} and Repo ${repo}.
125
129
  Please make sure that both the Org and Project are typed corrected and exist.`
126
- );
127
- }
128
- const remoteUrl = returnedRepo.remoteUrl;
129
- if (!remoteUrl) {
130
- throw new errors.InputError(
131
- "No remote URL returned from create repository for Azure"
132
- );
133
- }
134
- const repositoryId = returnedRepo.id;
135
- if (!repositoryId) {
136
- throw new errors.InputError("No Id returned from create repository for Azure");
137
- }
138
- const repoContentsUrl = returnedRepo.webUrl;
139
- if (!repoContentsUrl) {
140
- throw new errors.InputError(
141
- "No web URL returned from create repository for Azure"
142
- );
143
- }
130
+ );
131
+ }
132
+ if (!returnedRepo.remoteUrl) {
133
+ throw new errors.InputError(
134
+ "No remote URL returned from create repository for Azure"
135
+ );
136
+ }
137
+ if (!returnedRepo.id) {
138
+ throw new errors.InputError(
139
+ "No Id returned from create repository for Azure"
140
+ );
141
+ }
142
+ if (!returnedRepo.webUrl) {
143
+ throw new errors.InputError(
144
+ "No web URL returned from create repository for Azure"
145
+ );
146
+ }
147
+ return {
148
+ remoteUrl: returnedRepo.remoteUrl,
149
+ repositoryId: returnedRepo.id,
150
+ repoContentsUrl: returnedRepo.webUrl
151
+ };
152
+ }
153
+ }
154
+ );
144
155
  const gitAuthorInfo = {
145
156
  name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
146
157
  email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
@@ -155,17 +166,26 @@ function createPublishAzureAction(options) {
155
166
  "Signing commits is enabled but no signing key is provided in the configuration"
156
167
  );
157
168
  }
158
- const commitResult = await pluginScaffolderNode.initRepoAndPush({
159
- dir: pluginScaffolderNode.getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
160
- remoteUrl,
161
- defaultBranch,
162
- auth,
163
- logger: ctx.logger,
164
- commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
165
- gitAuthorInfo,
166
- signingKey: signCommit ? signingKey : void 0
169
+ const commitHash = await ctx.checkpoint({
170
+ key: `init.repo.and.push.${remoteUrl}`,
171
+ fn: async () => {
172
+ const commitResult = await pluginScaffolderNode.initRepoAndPush({
173
+ dir: pluginScaffolderNode.getRepoSourceDirectory(
174
+ ctx.workspacePath,
175
+ ctx.input.sourcePath
176
+ ),
177
+ remoteUrl,
178
+ defaultBranch,
179
+ auth,
180
+ logger: ctx.logger,
181
+ commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
182
+ gitAuthorInfo,
183
+ signingKey: signCommit ? signingKey : void 0
184
+ });
185
+ return commitResult?.commitHash;
186
+ }
167
187
  });
168
- ctx.output("commitHash", commitResult?.commitHash);
188
+ ctx.output("commitHash", commitHash);
169
189
  ctx.output("remoteUrl", remoteUrl);
170
190
  ctx.output("repoContentsUrl", repoContentsUrl);
171
191
  ctx.output("repositoryId", repositoryId);
@@ -1 +1 @@
1
- {"version":3,"file":"azure.cjs.js","sources":["../../src/actions/azure.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {\n DefaultAzureDevOpsCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';\nimport {\n getBearerHandler,\n getPersonalAccessTokenHandler,\n WebApi,\n} from 'azure-devops-node-api';\nimport { Config } from '@backstage/config';\nimport { examples } from './azure.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to Azure.\n * @public\n */\nexport function createPublishAzureAction(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 sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n signCommit?: boolean;\n }>({\n id: 'publish:azure',\n examples,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Azure.',\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 'master'`,\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 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 type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to Azure',\n },\n signCommit: {\n title: 'Sign commit',\n type: 'boolean',\n description: 'Sign commit with configured PGP private key',\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 repositoryId: {\n title: 'The Id of the created 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 defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n signCommit,\n } = ctx.input;\n\n const { project, repo, host, organization } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n if (!organization) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing organization`,\n );\n }\n\n const url = `https://${host}/${organization}`;\n const credentialProvider =\n DefaultAzureDevOpsCredentialsProvider.fromIntegrations(integrations);\n const credentials = await credentialProvider.getCredentials({ url: url });\n const integrationConfig = integrations.azure.byHost(host);\n\n if (credentials === undefined && ctx.input.token === undefined) {\n throw new InputError(\n `No credentials provided ${url}, please check your integrations config`,\n );\n }\n\n const authHandler =\n ctx.input.token || credentials?.type === 'pat'\n ? getPersonalAccessTokenHandler(ctx.input.token ?? credentials!.token)\n : getBearerHandler(credentials!.token);\n\n const webApi = new WebApi(url, authHandler);\n const client = await webApi.getGitApi();\n const createOptions: GitRepositoryCreateOptions = { name: repo };\n const returnedRepo = await client.createRepository(\n createOptions,\n project,\n );\n\n if (!returnedRepo) {\n throw new InputError(\n `Unable to create the repository with Organization ${organization}, Project ${project} and Repo ${repo}.\n Please make sure that both the Org and Project are typed corrected and exist.`,\n );\n }\n const remoteUrl = returnedRepo.remoteUrl;\n\n if (!remoteUrl) {\n throw new InputError(\n 'No remote URL returned from create repository for Azure',\n );\n }\n const repositoryId = returnedRepo.id;\n\n if (!repositoryId) {\n throw new InputError('No Id returned from create repository for Azure');\n }\n\n const repoContentsUrl = returnedRepo.webUrl;\n\n if (!repoContentsUrl) {\n throw new InputError(\n 'No web URL returned from create repository for Azure',\n );\n }\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\n const auth = {\n username: 'notempty',\n password: ctx.input.token ?? credentials!.token,\n };\n\n const signingKey =\n integrationConfig?.config.commitSigningKey ??\n config.getOptionalString('scaffolder.defaultCommitSigningKey');\n if (signCommit && !signingKey) {\n throw new Error(\n 'Signing commits is enabled but no signing key is provided in the configuration',\n );\n }\n\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl,\n defaultBranch,\n auth: auth,\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('repositoryId', repositoryId);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","DefaultAzureDevOpsCredentialsProvider","getPersonalAccessTokenHandler","getBearerHandler","WebApi","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;;AAyCO,SAAS,yBAAyB,OAGtC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAUJ,CAAA;AAAA,IACD,EAAI,EAAA,eAAA;AAAA,cACJC,uBAAA;AAAA,IACA,WACE,EAAA,0FAAA;AAAA,IACF,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,qBAAA;AAAA,YACP,IAAM,EAAA;AAAA,WACR;AAAA,UACA,WAAa,EAAA;AAAA,YACX,KAAO,EAAA,wBAAA;AAAA,YACP,IAAM,EAAA;AAAA,WACR;AAAA,UACA,aAAe,EAAA;AAAA,YACb,KAAO,EAAA,gBAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA,CAAA,wEAAA;AAAA,WACf;AAAA,UACA,gBAAkB,EAAA;AAAA,YAChB,KAAO,EAAA,oBAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA,CAAA,gFAAA;AAAA,WACf;AAAA,UACA,aAAe,EAAA;AAAA,YACb,KAAO,EAAA,qBAAA;AAAA,YACP,IAAM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AuB,CAAA,GAAA,CAAI,aAAe,EAAA,GAAA,CAAI,MAAM,UAAU,CAAA;AAAA,QACnE,SAAA;AAAA,QACA,aAAA;AAAA,QACA,IAAA;AAAA,QACA,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,aAAe,EAAA,gBAAA,GACX,gBACA,GAAA,MAAA,CAAO,kBAAkB,iCAAiC,CAAA;AAAA,QAC9D,aAAA;AAAA,QACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,OACvC,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAAA;AACzC,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"azure.cjs.js","sources":["../../src/actions/azure.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {\n DefaultAzureDevOpsCredentialsProvider,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport {\n createTemplateAction,\n getRepoSourceDirectory,\n initRepoAndPush,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';\nimport {\n getBearerHandler,\n getPersonalAccessTokenHandler,\n WebApi,\n} from 'azure-devops-node-api';\nimport { Config } from '@backstage/config';\nimport { examples } from './azure.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to Azure.\n * @public\n */\nexport function createPublishAzureAction(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 sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n signCommit?: boolean;\n }>({\n id: 'publish:azure',\n examples,\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to Azure.',\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 'master'`,\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 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 type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to Azure',\n },\n signCommit: {\n title: 'Sign commit',\n type: 'boolean',\n description: 'Sign commit with configured PGP private key',\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 repositoryId: {\n title: 'The Id of the created 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 defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n signCommit,\n } = ctx.input;\n\n const { project, repo, host, organization } = parseRepoUrl(\n repoUrl,\n integrations,\n );\n\n if (!organization) {\n throw new InputError(\n `Invalid URL provider was included in the repo URL to create ${ctx.input.repoUrl}, missing organization`,\n );\n }\n\n const url = `https://${host}/${organization}`;\n const credentialProvider =\n DefaultAzureDevOpsCredentialsProvider.fromIntegrations(integrations);\n const credentials = await credentialProvider.getCredentials({ url: url });\n const integrationConfig = integrations.azure.byHost(host);\n\n if (credentials === undefined && ctx.input.token === undefined) {\n throw new InputError(\n `No credentials provided ${url}, please check your integrations config`,\n );\n }\n\n const authHandler =\n ctx.input.token || credentials?.type === 'pat'\n ? getPersonalAccessTokenHandler(ctx.input.token ?? credentials!.token)\n : getBearerHandler(credentials!.token);\n\n const webApi = new WebApi(url, authHandler);\n const client = await webApi.getGitApi();\n const createOptions: GitRepositoryCreateOptions = { name: repo };\n\n const { remoteUrl, repositoryId, repoContentsUrl } = await ctx.checkpoint(\n {\n key: `create.repo.${repo}`,\n fn: async () => {\n const returnedRepo = await client.createRepository(\n createOptions,\n project,\n );\n\n if (!returnedRepo) {\n throw new InputError(\n `Unable to create the repository with Organization ${organization}, Project ${project} and Repo ${repo}.\n Please make sure that both the Org and Project are typed corrected and exist.`,\n );\n }\n\n if (!returnedRepo.remoteUrl) {\n throw new InputError(\n 'No remote URL returned from create repository for Azure',\n );\n }\n\n if (!returnedRepo.id) {\n throw new InputError(\n 'No Id returned from create repository for Azure',\n );\n }\n\n if (!returnedRepo.webUrl) {\n throw new InputError(\n 'No web URL returned from create repository for Azure',\n );\n }\n\n return {\n remoteUrl: returnedRepo.remoteUrl,\n repositoryId: returnedRepo.id,\n repoContentsUrl: returnedRepo.webUrl,\n };\n },\n },\n );\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\n const auth = {\n username: 'notempty',\n password: ctx.input.token ?? credentials!.token,\n };\n\n const signingKey =\n integrationConfig?.config.commitSigningKey ??\n config.getOptionalString('scaffolder.defaultCommitSigningKey');\n if (signCommit && !signingKey) {\n throw new Error(\n 'Signing commits is enabled but no signing key is provided in the configuration',\n );\n }\n\n const commitHash = await ctx.checkpoint({\n key: `init.repo.and.push.${remoteUrl}`,\n fn: async () => {\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(\n ctx.workspacePath,\n ctx.input.sourcePath,\n ),\n remoteUrl,\n defaultBranch,\n auth: auth,\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n signingKey: signCommit ? signingKey : undefined,\n });\n\n return commitResult?.commitHash;\n },\n });\n\n ctx.output('commitHash', commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('repositoryId', repositoryId);\n },\n });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","DefaultAzureDevOpsCredentialsProvider","getPersonalAccessTokenHandler","getBearerHandler","WebApi","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;;AAyCO,SAAS,yBAAyB,OAGtC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAUJ,CAAA;AAAA,IACD,EAAI,EAAA,eAAA;AAAA,cACJC,uBAAA;AAAA,IACA,WACE,EAAA,0FAAA;AAAA,IACF,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,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AAA;AACvB,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,cAAc,UAAU,CAAA;AACnC,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAAA;AACzC,GACD,CAAA;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-azure",
3
- "version": "0.2.7",
3
+ "version": "0.2.8-next.0",
4
4
  "description": "The azure module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -43,16 +43,16 @@
43
43
  "test": "backstage-cli package test"
44
44
  },
45
45
  "dependencies": {
46
- "@backstage/backend-plugin-api": "^1.2.1",
47
- "@backstage/config": "^1.3.2",
48
- "@backstage/errors": "^1.2.7",
49
- "@backstage/integration": "^1.16.2",
50
- "@backstage/plugin-scaffolder-node": "^0.8.0",
46
+ "@backstage/backend-plugin-api": "1.2.1",
47
+ "@backstage/config": "1.3.2",
48
+ "@backstage/errors": "1.2.7",
49
+ "@backstage/integration": "1.16.2",
50
+ "@backstage/plugin-scaffolder-node": "0.8.1-next.0",
51
51
  "azure-devops-node-api": "^14.0.0",
52
52
  "yaml": "^2.0.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@backstage/cli": "^0.31.0",
56
- "@backstage/plugin-scaffolder-node-test-utils": "^0.2.0"
55
+ "@backstage/cli": "0.32.0-next.0",
56
+ "@backstage/plugin-scaffolder-node-test-utils": "0.2.1-next.0"
57
57
  }
58
58
  }