Merge pull request #4183 from backstage/bug/azure-configuration

Fix Azure Organisation Interpolation and the timeout
This commit is contained in:
Ben Lambert
2021-01-21 12:17:50 +01:00
committed by GitHub
2 changed files with 26 additions and 14 deletions
@@ -17,7 +17,7 @@ jest.mock('./helpers');
jest.mock('azure-devops-node-api', () => ({
WebApi: jest.fn(),
getPersonalAccessTokenHandler: jest.fn(),
getPersonalAccessTokenHandler: jest.fn().mockReturnValue(() => {}),
}));
import { AzurePublisher } from './azure';
@@ -50,13 +50,18 @@ describe('Azure Publisher', () => {
const result = await publisher!.publish({
values: {
storePath: 'project/repo',
storePath: 'https://dev.azure.com/organisation/project/_git/repo',
owner: 'bob',
},
directory: '/tmp/test',
logger,
});
expect(WebApi).toHaveBeenCalledWith(
'https://dev.azure.com/organisation',
expect.any(Function),
);
expect(result).toEqual({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
catalogInfoUrl:
@@ -27,24 +27,30 @@ export class AzurePublisher implements PublisherBase {
if (!config.token) {
return undefined;
}
const authHandler = getPersonalAccessTokenHandler(config.token);
const webApi = new WebApi(config.host, authHandler);
const azureClient = await webApi.getGitApi();
return new AzurePublisher({ token: config.token, client: azureClient });
return new AzurePublisher({ token: config.token });
}
constructor(private readonly config: { token: string; client: IGitApi }) {}
constructor(private readonly config: { token: string }) {}
async publish({
values,
directory,
logger,
}: PublisherOptions): Promise<PublisherResult> {
const { owner, name } = parseGitUrl(values.storePath);
const { owner, name, organization, resource } = parseGitUrl(
values.storePath,
);
const authHandler = getPersonalAccessTokenHandler(this.config.token);
const webApi = new WebApi(
`https://${resource}/${organization}`,
authHandler,
);
const client = await webApi.getGitApi();
const remoteUrl = await this.createRemote({
project: owner,
name,
client,
});
const catalogInfoUrl = `${remoteUrl}?path=%2Fcatalog-info.yaml`;
@@ -62,13 +68,14 @@ export class AzurePublisher implements PublisherBase {
return { remoteUrl, catalogInfoUrl };
}
private async createRemote(opts: { name: string; project: string }) {
const { name, project } = opts;
private async createRemote(opts: {
name: string;
project: string;
client: IGitApi;
}) {
const { name, project, client } = opts;
const createOptions: GitRepositoryCreateOptions = { name };
const repo = await this.config.client.createRepository(
createOptions,
project,
);
const repo = await client.createRepository(createOptions, project);
return repo.remoteUrl || '';
}