Merge pull request #25119 from Maetis/bug/azure-scaffolder-wrong-repoContentsUrl

Fix bug in Azure Scaffolder that can produce a wrong repoContentsUrl
This commit is contained in:
Ben Lambert
2024-06-12 17:36:22 +02:00
committed by GitHub
4 changed files with 39 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-azure': patch
---
Use `GitRepository.webUrl` instead of `GitRepository.remoteUrl` to set the value of `repoContentsUrl` as `remoteUrl` can sometimes return an URL with the wrong format (e.g. `https://<organization>@dev.azure.com/<organization>/<project>/\_git/<repository>`).
@@ -72,6 +72,7 @@ describe('publish:azure examples', () => {
it('should call initRepoAndPush with the correct values', async () => {
mockGitClient.createRepository.mockResolvedValue({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
});
@@ -94,6 +95,7 @@ describe('publish:azure examples', () => {
it('should call initRepoAndPush with a changed default branch', async () => {
mockGitClient.createRepository.mockResolvedValue({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
});
@@ -131,6 +131,7 @@ describe('publish:azure', () => {
it('should not throw if there is a token provided through ctx.input', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'http://google.com',
webUrl: 'http://google.com',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -158,6 +159,7 @@ describe('publish:azure', () => {
it('should throw if there is no remoteUrl returned', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: null,
webUrl: 'http://google.com',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
await expect(
@@ -173,6 +175,7 @@ describe('publish:azure', () => {
it('should throw if there is no repositoryId returned', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'http://google.com',
webUrl: 'http://google.com',
id: null,
}));
await expect(
@@ -185,9 +188,26 @@ describe('publish:azure', () => {
).rejects.toThrow(/No Id returned/);
});
it('should throw if there is no repoContentsUrl returned', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'http://google.com',
webUrl: null,
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
await expect(
action.handler({
...mockContext,
input: {
repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org',
},
}),
).rejects.toThrow(/No web URL returned/);
});
it('should call the azureApis with the correct values', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'http://google.com',
webUrl: 'http://google.com',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -214,6 +234,7 @@ describe('publish:azure', () => {
it('should call initRepoAndPush with the correct values', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -233,6 +254,7 @@ describe('publish:azure', () => {
it('should call initRepoAndPush with the correct default branch', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -283,6 +305,7 @@ describe('publish:azure', () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -324,6 +347,7 @@ describe('publish:azure', () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -343,6 +367,7 @@ describe('publish:azure', () => {
it('should call output with the remoteUrl the repoContentsUrl and the repositoryId', async () => {
mockGitClient.createRepository.mockImplementation(() => ({
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
webUrl: 'https://dev.azure.com/organization/project/_git/repo',
id: '709e891c-dee7-4f91-b963-534713c0737f',
}));
@@ -187,9 +187,13 @@ export function createPublishAzureAction(options: {
throw new InputError('No Id returned from create repository for Azure');
}
// blam: Repo contents is serialized into the path,
// so it's just the base path I think
const repoContentsUrl = remoteUrl;
const repoContentsUrl = returnedRepo.webUrl;
if (!repoContentsUrl) {
throw new InputError(
'No web URL returned from create repository for Azure',
);
}
const gitAuthorInfo = {
name: gitAuthorName