@backstage/plugin-scaffolder-backend-module-azure 0.2.10-next.0 → 0.2.10-next.2

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,28 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-azure
2
2
 
3
+ ## 0.2.10-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.9.0-next.2
9
+ - @backstage/backend-plugin-api@1.4.0-next.1
10
+ - @backstage/config@1.3.2
11
+ - @backstage/errors@1.2.7
12
+ - @backstage/integration@1.17.0
13
+
14
+ ## 0.2.10-next.1
15
+
16
+ ### Patch Changes
17
+
18
+ - e89d7b6: Migrating `azure` actions to using the new `zod` schema format
19
+ - Updated dependencies
20
+ - @backstage/plugin-scaffolder-node@0.8.3-next.1
21
+ - @backstage/backend-plugin-api@1.4.0-next.1
22
+ - @backstage/config@1.3.2
23
+ - @backstage/errors@1.2.7
24
+ - @backstage/integration@1.17.0
25
+
3
26
  ## 0.2.10-next.0
4
27
 
5
28
  ### Patch Changes
@@ -14,74 +14,47 @@ function createPublishAzureAction(options) {
14
14
  description: "Initializes a git repository of the content in the workspace, and publishes it to Azure.",
15
15
  schema: {
16
16
  input: {
17
- type: "object",
18
- required: ["repoUrl"],
19
- properties: {
20
- repoUrl: {
21
- title: "Repository Location",
22
- type: "string"
23
- },
24
- description: {
25
- title: "Repository Description",
26
- type: "string"
27
- },
28
- defaultBranch: {
29
- title: "Default Branch",
30
- type: "string",
31
- description: `Sets the default branch on the repository. The default value is 'master'`
32
- },
33
- gitCommitMessage: {
34
- title: "Git Commit Message",
35
- type: "string",
36
- description: `Sets the commit message on the repository. The default value is 'initial commit'`
37
- },
38
- gitAuthorName: {
39
- title: "Default Author Name",
40
- type: "string",
41
- description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
42
- },
43
- gitAuthorEmail: {
44
- title: "Default Author Email",
45
- type: "string",
46
- description: `Sets the default author email for the commit.`
47
- },
48
- sourcePath: {
49
- title: "Source Path",
50
- description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
51
- type: "string"
52
- },
53
- token: {
54
- title: "Authentication Token",
55
- type: "string",
56
- description: "The token to use for authorization to Azure"
57
- },
58
- signCommit: {
59
- title: "Sign commit",
60
- type: "boolean",
61
- description: "Sign commit with configured PGP private key"
62
- }
63
- }
17
+ repoUrl: (z) => z.string({
18
+ description: "Repository Location"
19
+ }),
20
+ description: (z) => z.string({
21
+ description: "Repository Description"
22
+ }).optional(),
23
+ defaultBranch: (z) => z.string({
24
+ description: `Sets the default branch on the repository. The default value is 'master'`
25
+ }).optional(),
26
+ sourcePath: (z) => z.string({
27
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository."
28
+ }).optional(),
29
+ token: (z) => z.string({
30
+ description: "The token to use for authorization to Azure"
31
+ }).optional(),
32
+ gitCommitMessage: (z) => z.string({
33
+ description: `Sets the commit message on the repository. The default value is 'initial commit'`
34
+ }).optional(),
35
+ gitAuthorName: (z) => z.string({
36
+ description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
37
+ }).optional(),
38
+ gitAuthorEmail: (z) => z.string({
39
+ description: `Sets the default author email for the commit.`
40
+ }).optional(),
41
+ signCommit: (z) => z.boolean({
42
+ description: "Sign commit with configured PGP private key"
43
+ }).optional()
64
44
  },
65
45
  output: {
66
- type: "object",
67
- properties: {
68
- remoteUrl: {
69
- title: "A URL to the repository with the provider",
70
- type: "string"
71
- },
72
- repoContentsUrl: {
73
- title: "A URL to the root of the repository",
74
- type: "string"
75
- },
76
- repositoryId: {
77
- title: "The Id of the created repository",
78
- type: "string"
79
- },
80
- commitHash: {
81
- title: "The git commit hash of the initial commit",
82
- type: "string"
83
- }
84
- }
46
+ remoteUrl: (z) => z.string({
47
+ description: "A URL to the repository with the provider"
48
+ }).optional(),
49
+ repoContentsUrl: (z) => z.string({
50
+ description: "A URL to the root of the repository"
51
+ }).optional(),
52
+ repositoryId: (z) => z.string({
53
+ description: "The Id of the created repository"
54
+ }).optional(),
55
+ commitHash: (z) => z.string({
56
+ description: "The git commit hash of the initial commit"
57
+ }).optional()
85
58
  }
86
59
  },
87
60
  async handler(ctx) {
@@ -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\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,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,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A,CAAI,KAAM,CAAA,KAAA,IAAS,WAAa,CAAA;AAAA,OAC5C;AAEA,MAAA,MAAM,aACJ,iBAAmB,EAAA,MAAA,CAAO,gBAC1B,IAAA,MAAA,CAAO,kBAAkB,oCAAoC,CAAA;AAC/D,MAAI,IAAA,UAAA,IAAc,CAAC,UAAY,EAAA;AAC7B,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SACF;AAAA;AAGF,MAAM,MAAA,UAAA,GAAa,MAAM,GAAA,CAAI,UAAW,CAAA;AAAA,QACtC,GAAA,EAAK,sBAAsB,SAAS,CAAA,CAAA;AAAA,QACpC,IAAI,YAAY;AACd,UAAM,MAAA,YAAA,GAAe,MAAMK,oCAAgB,CAAA;AAAA,YACzC,GAAK,EAAAC,2CAAA;AAAA,cACH,GAAI,CAAA,aAAA;AAAA,cACJ,IAAI,KAAM,CAAA;AAAA,aACZ;AAAA,YACA,SAAA;AAAA,YACA,aAAA;AAAA,YACA,IAAA;AAAA,YACA,QAAQ,GAAI,CAAA,MAAA;AAAA,YACZ,aAAe,EAAA,gBAAA,GACX,gBACA,GAAA,MAAA,CAAO,kBAAkB,iCAAiC,CAAA;AAAA,YAC9D,aAAA;AAAA,YACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,WACvC,CAAA;AAED,UAAA,OAAO,YAAc,EAAA,UAAA;AAAA;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;;;;"}
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 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 repoUrl: z =>\n z.string({\n description: 'Repository Location',\n }),\n description: z =>\n z\n .string({\n description: 'Repository Description',\n })\n .optional(),\n defaultBranch: z =>\n z\n .string({\n description: `Sets the default branch on the repository. The default value is 'master'`,\n })\n .optional(),\n sourcePath: z =>\n z\n .string({\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 })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to Azure',\n })\n .optional(),\n gitCommitMessage: z =>\n z\n .string({\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n })\n .optional(),\n gitAuthorName: z =>\n z\n .string({\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n })\n .optional(),\n gitAuthorEmail: z =>\n z\n .string({\n description: `Sets the default author email for the commit.`,\n })\n .optional(),\n signCommit: z =>\n z\n .boolean({\n description: 'Sign commit with configured PGP private key',\n })\n .optional(),\n },\n output: {\n remoteUrl: z =>\n z\n .string({\n description: 'A URL to the repository with the provider',\n })\n .optional(),\n repoContentsUrl: z =>\n z\n .string({\n description: 'A URL to the root of the repository',\n })\n .optional(),\n repositoryId: z =>\n z\n .string({\n description: 'The Id of the created repository',\n })\n .optional(),\n commitHash: z =>\n z\n .string({\n description: 'The git commit hash of the initial commit',\n })\n .optional(),\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"],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H,GAAI,CAAA,aAAA;AAAA,cACJ,IAAI,KAAM,CAAA;AAAA,aACZ;AAAA,YACA,SAAA;AAAA,YACA,aAAA;AAAA,YACA,IAAA;AAAA,YACA,QAAQ,GAAI,CAAA,MAAA;AAAA,YACZ,aAAe,EAAA,gBAAA,GACX,gBACA,GAAA,MAAA,CAAO,kBAAkB,iCAAiC,CAAA;AAAA,YAC9D,aAAA;AAAA,YACA,UAAA,EAAY,aAAa,UAAa,GAAA,KAAA;AAAA,WACvC,CAAA;AAED,UAAA,OAAO,YAAc,EAAA,UAAA;AAAA;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/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
2
- import * as _backstage_types from '@backstage/types';
3
2
  import { ScmIntegrationRegistry } from '@backstage/integration';
4
3
  import { Config } from '@backstage/config';
5
4
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
@@ -14,15 +13,20 @@ declare function createPublishAzureAction(options: {
14
13
  config: Config;
15
14
  }): _backstage_plugin_scaffolder_node.TemplateAction<{
16
15
  repoUrl: string;
17
- description?: string;
18
- defaultBranch?: string;
19
- sourcePath?: string;
20
- token?: string;
21
- gitCommitMessage?: string;
22
- gitAuthorName?: string;
23
- gitAuthorEmail?: string;
24
- signCommit?: boolean;
25
- }, _backstage_types.JsonObject, "v1">;
16
+ description?: string | undefined;
17
+ defaultBranch?: string | undefined;
18
+ sourcePath?: string | undefined;
19
+ token?: string | undefined;
20
+ gitCommitMessage?: string | undefined;
21
+ gitAuthorName?: string | undefined;
22
+ gitAuthorEmail?: string | undefined;
23
+ signCommit?: boolean | undefined;
24
+ }, {
25
+ remoteUrl?: string | undefined;
26
+ repoContentsUrl?: string | undefined;
27
+ repositoryId?: string | undefined;
28
+ commitHash?: string | undefined;
29
+ }, "v2">;
26
30
 
27
31
  /**
28
32
  * @public
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-azure",
3
- "version": "0.2.10-next.0",
3
+ "version": "0.2.10-next.2",
4
4
  "description": "The azure module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -50,16 +50,16 @@
50
50
  "test": "backstage-cli package test"
51
51
  },
52
52
  "dependencies": {
53
- "@backstage/backend-plugin-api": "1.4.0-next.0",
53
+ "@backstage/backend-plugin-api": "1.4.0-next.1",
54
54
  "@backstage/config": "1.3.2",
55
55
  "@backstage/errors": "1.2.7",
56
56
  "@backstage/integration": "1.17.0",
57
- "@backstage/plugin-scaffolder-node": "0.8.3-next.0",
57
+ "@backstage/plugin-scaffolder-node": "0.9.0-next.2",
58
58
  "azure-devops-node-api": "^14.0.0",
59
59
  "yaml": "^2.0.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@backstage/cli": "0.32.1",
63
- "@backstage/plugin-scaffolder-node-test-utils": "0.2.3-next.0"
62
+ "@backstage/cli": "0.33.0-next.1",
63
+ "@backstage/plugin-scaffolder-node-test-utils": "0.3.0-next.2"
64
64
  }
65
65
  }