Merge pull request #14847 from MarcBruins/feature/MakeAzureDevOpsMultiProject
Make Azure DevOps Multiproject
This commit is contained in:
@@ -29,11 +29,11 @@ describe('azure', () => {
|
||||
|
||||
server.use(
|
||||
rest.post(
|
||||
`https://almsearch.dev.azure.com/shopify/engineering/_apis/search/codesearchresults`,
|
||||
`https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`,
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Basic OkFCQw==');
|
||||
expect(req.body).toEqual({
|
||||
searchText: 'path:/catalog-info.yaml repo:*',
|
||||
searchText: 'path:/catalog-info.yaml repo:* proj:engineering',
|
||||
$skip: 0,
|
||||
$top: 1000,
|
||||
});
|
||||
@@ -64,6 +64,9 @@ describe('azure', () => {
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
project: {
|
||||
name: 'backstage',
|
||||
},
|
||||
},
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
@@ -71,17 +74,20 @@ describe('azure', () => {
|
||||
repository: {
|
||||
name: 'ios-app',
|
||||
},
|
||||
project: {
|
||||
name: 'backstage',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
server.use(
|
||||
rest.post(
|
||||
`https://almsearch.dev.azure.com/shopify/engineering/_apis/search/codesearchresults`,
|
||||
`https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`,
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Basic OkFCQw==');
|
||||
expect(req.body).toEqual({
|
||||
searchText: 'path:/catalog-info.yaml repo:*',
|
||||
searchText: 'path:/catalog-info.yaml repo:* proj:engineering',
|
||||
$skip: 0,
|
||||
$top: 1000,
|
||||
});
|
||||
@@ -108,6 +114,9 @@ describe('azure', () => {
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
path: '/catalog-info.yaml',
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
@@ -117,11 +126,12 @@ describe('azure', () => {
|
||||
|
||||
server.use(
|
||||
rest.post(
|
||||
`https://almsearch.dev.azure.com/shopify/engineering/_apis/search/codesearchresults`,
|
||||
`https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`,
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Basic OkFCQw==');
|
||||
expect(req.body).toEqual({
|
||||
searchText: 'path:/catalog-info.yaml repo:backstage',
|
||||
searchText:
|
||||
'path:/catalog-info.yaml repo:backstage proj:engineering',
|
||||
$skip: 0,
|
||||
$top: 1000,
|
||||
});
|
||||
@@ -151,17 +161,20 @@ describe('azure', () => {
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
server.use(
|
||||
rest.post(
|
||||
`https://azuredevops.mycompany.com/shopify/engineering/_apis/search/codesearchresults`,
|
||||
`https://azuredevops.mycompany.com/shopify/_apis/search/codesearchresults`,
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Basic OkFCQw==');
|
||||
expect(req.body).toEqual({
|
||||
searchText: 'path:/catalog-info.yaml repo:*',
|
||||
searchText: 'path:/catalog-info.yaml repo:* proj:engineering',
|
||||
$skip: 0,
|
||||
$top: 1000,
|
||||
});
|
||||
@@ -190,16 +203,20 @@ describe('azure', () => {
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
project: {
|
||||
name: 'engineering',
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
server.use(
|
||||
rest.post(
|
||||
`https://almsearch.dev.azure.com/shopify/engineering/_apis/search/codesearchresults`,
|
||||
`https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`,
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Basic OkFCQw==');
|
||||
expect(req.body).toMatchObject({
|
||||
searchText: 'path:/catalog-info.yaml repo:backstage',
|
||||
searchText:
|
||||
'path:/catalog-info.yaml repo:backstage proj:engineering',
|
||||
$top: 1000,
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
|
||||
+12
@@ -135,6 +135,9 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
path: '/catalog-info.yaml',
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
@@ -142,6 +145,9 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
path: '/src/catalog-info.yaml',
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
repository: {
|
||||
name: 'ios-app',
|
||||
},
|
||||
@@ -191,6 +197,9 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
},
|
||||
]);
|
||||
const emitter = jest.fn();
|
||||
@@ -229,6 +238,9 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
|
||||
repository: {
|
||||
name: 'backstage',
|
||||
},
|
||||
project: {
|
||||
name: '*',
|
||||
},
|
||||
},
|
||||
]);
|
||||
const emitter = jest.fn();
|
||||
|
||||
@@ -164,6 +164,9 @@ describe('AzureDevOpsEntityProvider', () => {
|
||||
repository: {
|
||||
name: 'myrepo',
|
||||
},
|
||||
project: {
|
||||
name: 'myproject',
|
||||
},
|
||||
},
|
||||
],
|
||||
'https://dev.azure.com/myorganization/myproject',
|
||||
@@ -189,6 +192,9 @@ describe('AzureDevOpsEntityProvider', () => {
|
||||
repository: {
|
||||
name: 'myrepo',
|
||||
},
|
||||
project: {
|
||||
name: 'myproject',
|
||||
},
|
||||
},
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
@@ -196,6 +202,9 @@ describe('AzureDevOpsEntityProvider', () => {
|
||||
repository: {
|
||||
name: 'myotherrepo',
|
||||
},
|
||||
project: {
|
||||
name: 'myproject',
|
||||
},
|
||||
},
|
||||
],
|
||||
'https://dev.azure.com/myorganization/myproject',
|
||||
@@ -277,6 +286,9 @@ describe('AzureDevOpsEntityProvider', () => {
|
||||
repository: {
|
||||
name: 'myrepo',
|
||||
},
|
||||
project: {
|
||||
name: 'myproject',
|
||||
},
|
||||
},
|
||||
{
|
||||
fileName: 'catalog-info.yaml',
|
||||
@@ -284,6 +296,9 @@ describe('AzureDevOpsEntityProvider', () => {
|
||||
repository: {
|
||||
name: 'myotherrepo',
|
||||
},
|
||||
project: {
|
||||
name: 'myproject',
|
||||
},
|
||||
},
|
||||
],
|
||||
'https://dev.azure.com/myorganization/myproject',
|
||||
|
||||
@@ -166,15 +166,17 @@ 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}`;
|
||||
const baseUrl = `https://${this.config.host}/${this.config.organization}/${file.project.name}`;
|
||||
return encodeURI(
|
||||
`${baseUrl}/_git/${file.repository.name}?path=${file.path}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user