Skip to content

Commit

Permalink
[Fleet] Fix package category count (#99677) (#99924)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
  • Loading branch information
kibanamachine and nchaulet authored May 12, 2021
1 parent 75150f6 commit bf720ce
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions x-pack/plugins/fleet/server/services/epm/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export const pkgToPkgKey = ({ name, version }: { name: string; version: string }
export async function fetchList(params?: SearchParams): Promise<RegistrySearchResults> {
const registryUrl = getRegistryUrl();
const url = new URL(`${registryUrl}/search`);
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be x.y.z-SNAPSHOT
const kibanaBranch = appContextService.getKibanaBranch();
if (params) {
if (params.category) {
url.searchParams.set('category', params.category);
Expand All @@ -88,10 +86,7 @@ export async function fetchList(params?: SearchParams): Promise<RegistrySearchRe
}
}

// on master, request all packages regardless of version
if (kibanaVersion && kibanaBranch !== 'master') {
url.searchParams.set('kibana.version', kibanaVersion);
}
setKibanaVersion(url);

return fetchUrl(url.toString()).then(JSON.parse);
}
Expand Down Expand Up @@ -145,6 +140,16 @@ export async function fetchFile(filePath: string): Promise<Response> {
return getResponse(`${registryUrl}${filePath}`);
}

function setKibanaVersion(url: URL) {
const kibanaVersion = appContextService.getKibanaVersion().split('-')[0]; // may be x.y.z-SNAPSHOT
const kibanaBranch = appContextService.getKibanaBranch();

// on master, request all packages regardless of version
if (kibanaVersion && kibanaBranch !== 'master') {
url.searchParams.set('kibana.version', kibanaVersion);
}
}

export async function fetchCategories(params?: CategoriesParams): Promise<CategorySummaryList> {
const registryUrl = getRegistryUrl();
const url = new URL(`${registryUrl}/categories`);
Expand All @@ -154,6 +159,8 @@ export async function fetchCategories(params?: CategoriesParams): Promise<Catego
}
}

setKibanaVersion(url);

return fetchUrl(url.toString()).then(JSON.parse);
}

Expand Down

0 comments on commit bf720ce

Please sign in to comment.