Add Azure DevOps publisher to scaffolder

This commit is contained in:
Mattias Frinnström
2020-09-21 13:50:31 +00:00
parent c109cbe4df
commit 56a9f8389b
10 changed files with 357 additions and 3 deletions
+1
View File
@@ -33,6 +33,7 @@
"@backstage/plugin-techdocs-backend": "^0.1.1-alpha.23",
"@gitbeaker/node": "^23.5.0",
"@octokit/rest": "^18.0.0",
"azure-devops-node-api": "^10.1.1",
"dockerode": "^3.2.0",
"example-app": "^0.1.1-alpha.23",
"express": "^4.17.1",
@@ -25,12 +25,14 @@ import {
Publishers,
GithubPublisher,
GitlabPublisher,
AzurePublisher,
CreateReactAppTemplater,
Templaters,
RepoVisibilityOptions,
} from '@backstage/plugin-scaffolder-backend';
import { Octokit } from '@octokit/rest';
import { Gitlab } from '@gitbeaker/node';
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
import type { PluginEnvironment } from '../types';
import Docker from 'dockerode';
@@ -114,6 +116,33 @@ export default async function createPlugin({
}
}
const azureConfig = config.getOptionalConfig('scaffolder.azure.api');
if (azureConfig) {
try {
const organization = azureConfig.getString('organization');
const azureToken = azureConfig.getString('token');
const serverUrl = `https://dev.azure.com/${organization}`;
const authHandler = getPersonalAccessTokenHandler(azureToken);
const webApi = new WebApi(serverUrl, authHandler);
const azureClient = await webApi.getGitApi();
const azurePublisher = new AzurePublisher(azureClient, azureToken);
publishers.register('azure/api', azurePublisher);
} catch (e) {
const providerName = 'azure';
if (process.env.NODE_ENV !== 'development') {
throw new Error(
`Failed to initialize ${providerName} scaffolding provider, ${e.message}`,
);
}
logger.warn(
`Skipping ${providerName} scaffolding provider, ${e.message}`,
);
}
}
const dockerClient = new Docker();
return await createRouter({
preparers,