diff --git a/.changeset/ninety-hats-serve.md b/.changeset/ninety-hats-serve.md new file mode 100644 index 0000000000..637d56d47e --- /dev/null +++ b/.changeset/ninety-hats-serve.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-azure': minor +--- + +This will add the ability to use Azure DevOps with multi project with a single value which is a new feature as previously this had to be done manually for each project that you wanted to add diff --git a/docs/integrations/azure/discovery.md b/docs/integrations/azure/discovery.md index 2156f60814..18686ebdc3 100644 --- a/docs/integrations/azure/discovery.md +++ b/docs/integrations/azure/discovery.md @@ -47,6 +47,11 @@ catalog: frequency: { minutes: 30 } # supports ISO duration, "human duration" as used in code timeout: { minutes: 3 } + yourSecondProviderId: # identifies your dataset / provider independent of config changes + organization: myorg + project: '*' # this will match all projects + repository: '*' # this will match all repos + path: /catalog-info.yaml anotherProviderId: # another identifier organization: myorg project: myproject @@ -62,7 +67,7 @@ The parameters available are: - **`host:`** _(optional)_ Leave empty for Cloud hosted, otherwise set to your self-hosted instance host. - **`organization:`** Your Organization slug (or Collection for on-premise users). Required. -- **`project:`** Your project slug. Required. +- **`project:`** Your project slug. Required. Wildcards are supported as show on the examples above. If not set, all projects will be searched. - **`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. - **`schedule`** _(optional)_: diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.ts b/plugins/catalog-backend-module-azure/src/lib/azure.ts index 316c9b0b8c..0c96d133d3 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.ts @@ -31,6 +31,9 @@ export interface CodeSearchResultItem { repository: { name: string; }; + project: { + name: string; + }; } const isCloud = (host: string) => host === 'dev.azure.com'; @@ -47,7 +50,7 @@ export async function codeSearch( const searchBaseUrl = isCloud(azureConfig.host) ? 'https://almsearch.dev.azure.com' : `https://${azureConfig.host}`; - const searchUrl = `${searchBaseUrl}/${org}/${project}/_apis/search/codesearchresults?api-version=6.0-preview.1`; + const searchUrl = `${searchBaseUrl}/${org}/_apis/search/codesearchresults?api-version=6.0-preview.1`; let items: CodeSearchResultItem[] = []; let hasMorePages = true; @@ -59,7 +62,7 @@ export async function codeSearch( }), method: 'POST', body: JSON.stringify({ - searchText: `path:${path} repo:${repo || '*'}`, + searchText: `path:${path} repo:${repo || '*'} proj:${project || '*'}`, $skip: items.length, $top: PAGE_SIZE, }), diff --git a/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.ts b/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.ts index b824d176ee..87ddde78d3 100644 --- a/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.ts +++ b/plugins/catalog-backend-module-azure/src/providers/AzureDevOpsEntityProvider.ts @@ -166,17 +166,18 @@ export class AzureDevOpsEntityProvider implements EntityProvider { } private createLocationSpec(file: CodeSearchResultItem): LocationSpec { + const target = this.createObjectUrl(file); + return { type: 'url', - target: this.createObjectUrl(file), + target: target, presence: 'required', }; } private createObjectUrl(file: CodeSearchResultItem): string { - const baseUrl = `https://${this.config.host}/${this.config.organization}/${this.config.project}`; - return encodeURI( - `${baseUrl}/_git/${file.repository.name}?path=${file.path}`, - ); + const baseUrl = `https://${this.config.host}/${this.config.organization}`; + const encodedUri = `${baseUrl}/${file.project.name}/_git/${file.repository.name}?path=${file.path}`; + return encodedUri; } }