Merge pull request #16749 from ymoreiratiti/feature/plugin-catalog-backend-module-azure-branch-filter

feat(@backstage/plugin-catalog-backend-module-azure): Add branch filt…
This commit is contained in:
Johan Haals
2023-03-10 13:15:09 +01:00
committed by GitHub
8 changed files with 89 additions and 11 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-catalog-backend-module-azure': patch
---
Add branch filter support
https://backstage.io/docs/integrations/azure/discovery
+13 -3
View File
@@ -60,6 +60,7 @@ catalog:
host: selfhostedazure.yourcompany.com
organization: myorg
project: myproject
branch: development
```
The parameters available are:
@@ -69,6 +70,7 @@ The parameters available are:
- **`project:`** _(optional)_ Your project slug. Wildcards are supported as show on the examples above. If not set, all projects will be searched. For a project name containing spaces, use both single and double quotes as in `project: '"My Project Name"'`.
- **`repository:`** _(optional)_ The repository name. Wildcards are supported as show on the examples above. If not set, all repositories will be searched.
- **`path:`** _(optional)_ Where to find catalog-info.yaml files. Defaults to /catalog-info.yaml.
- **`branch:`** _(optional)_ The branch name to use.
- **`schedule`** _(optional)_:
- **`frequency`**:
How often you want the task to run. The system does its best to avoid overlapping invocations.
@@ -79,9 +81,17 @@ The parameters available are:
- **`scope`** _(optional)_:
`'global'` or `'local'`. Sets the scope of concurrency control.
_Note:_ the path parameter follows the same rules as the search on Azure DevOps
web interface. For more details visit the
[official search documentation](https://docs.microsoft.com/en-us/azure/devops/project/search/get-started-search?view=azure-devops).
_Note:_
- The path parameter follows the same rules as the search on Azure DevOps web interface. For more details visit the [official search documentation](https://docs.microsoft.com/en-us/azure/devops/project/search/get-started-search?view=azure-devops).
- To use branch parameters, it is necessary that the desired branch be added to the "Searchable branches" list within Azure DevOps Repositories. To do this, follow the instructions below:
1. Access your Azure DevOps and open the repository in which you want to add the branch.
2. Click on "Settings" in the lower-left corner of the screen.
3. Select the "Options" option in the left navigation bar.
4. In the "Searchable branches" section, click on the "Add" button to add a new branch.
5. In the window that appears, enter the name of the branch you want to add and click "Add".
6. The added branch will now appear in the "Searchable branches" list.
As this provider is not one of the default providers, you will first need to install
the Azure catalog plugin:
@@ -34,6 +34,7 @@ export interface CodeSearchResultItem {
project: {
name: string;
};
branch?: string;
}
const isCloud = (host: string) => host === 'dev.azure.com';
@@ -105,9 +105,13 @@ describe('AzureDevOpsEntityProvider', () => {
await (taskDef.fn as () => Promise<void>)();
const expectedEntities = codeSearchResults.map(item => {
const url = encodeURI(
`${expectedBaseUrl}/_git/${item.repository.name}?path=${item.path}`,
);
const url = item.branch
? encodeURI(
`${expectedBaseUrl}/_git/${item.repository.name}?path=${item.path}&version=GB${item.branch}`,
)
: encodeURI(
`${expectedBaseUrl}/_git/${item.repository.name}?path=${item.path}`,
);
return {
entity: {
apiVersion: 'backstage.io/v1alpha1',
@@ -177,6 +181,36 @@ describe('AzureDevOpsEntityProvider', () => {
);
});
// eslint-disable-next-line jest/expect-expect
it('single mutation when repos use branch filter', async () => {
return expectMutation(
'allReposSingleFile',
{
organization: 'myorganization',
project: 'myproject',
branch: 'mybranch',
},
[
{
fileName: 'catalog-info.yaml',
path: '/catalog-info.yaml',
repository: {
name: 'myrepo',
},
project: {
name: 'myproject',
},
branch: 'mybranch',
},
],
'https://dev.azure.com/myorganization/myproject',
{
'myrepo?path=/catalog-info.yaml':
'generated-589e8cc47341987c7a34f5291791151fa64f7754',
},
);
});
// eslint-disable-next-line jest/expect-expect
it('single mutation when multiple repos have multiple files', async () => {
return expectMutation(
@@ -177,8 +177,12 @@ export class AzureDevOpsEntityProvider implements EntityProvider {
private createObjectUrl(file: CodeSearchResultItem): string {
const baseUrl = `https://${this.config.host}/${this.config.organization}/${file.project.name}`;
return encodeURI(
`${baseUrl}/_git/${file.repository.name}?path=${file.path}`,
);
let fullUrl = `${baseUrl}/_git/${file.repository.name}?path=${file.path}`;
if (this.config.branch) {
fullUrl += `&version=GB${this.config.branch}`;
}
return encodeURI(fullUrl);
}
}
@@ -44,17 +44,30 @@ describe('readAzureDevOpsConfigs', () => {
},
},
};
const provider5 = {
host: 'azure.mycompany.com',
organization: 'mycompany',
project: 'myproject',
branch: 'mybranch',
};
const config = {
catalog: {
providers: {
azureDevOps: { provider1, provider2, provider3, provider4 },
azureDevOps: {
provider1,
provider2,
provider3,
provider4,
provider5,
},
},
},
};
const actual = readAzureDevOpsConfigs(new ConfigReader(config));
expect(actual).toHaveLength(4);
expect(actual).toHaveLength(5);
expect(actual[0]).toEqual({
...provider1,
path: '/catalog-info.yaml',
@@ -85,5 +98,12 @@ describe('readAzureDevOpsConfigs', () => {
frequency: Duration.fromISO(provider4.schedule.frequency),
},
});
expect(actual[4]).toEqual({
...provider5,
branch: 'mybranch',
path: '/catalog-info.yaml',
repository: '*',
id: 'provider5',
});
});
});
@@ -41,6 +41,7 @@ function readAzureDevOpsConfig(id: string, config: Config): AzureDevOpsConfig {
const project = config.getString('project');
const host = config.getOptionalString('host') || 'dev.azure.com';
const repository = config.getOptionalString('repository') || '*';
const branch = config.getOptionalString('branch');
const path = config.getOptionalString('path') || '/catalog-info.yaml';
const schedule = config.has('schedule')
@@ -53,6 +54,7 @@ function readAzureDevOpsConfig(id: string, config: Config): AzureDevOpsConfig {
organization,
project,
repository,
branch,
path,
schedule,
};
@@ -22,6 +22,7 @@ export type AzureDevOpsConfig = {
organization: string;
project: string;
repository: string;
branch?: string;
path: string;
schedule?: TaskScheduleDefinition;
};