diff --git a/src/lib/source-handlers/bitbucket-server/list-repos.ts b/src/lib/source-handlers/bitbucket-server/list-repos.ts index 1bf26a88..1e6ac74b 100644 --- a/src/lib/source-handlers/bitbucket-server/list-repos.ts +++ b/src/lib/source-handlers/bitbucket-server/list-repos.ts @@ -11,6 +11,7 @@ interface BitbucketServeRepoData { name: string; project: { key: string; + name?: string; }; }[]; isLastPage: boolean; @@ -18,7 +19,7 @@ interface BitbucketServeRepoData { } export const fetchAllRepos = async ( url: string, - projectKey: string, + projectName: string, token: string, ): Promise => { let lastPage = false; @@ -27,11 +28,11 @@ export const fetchAllRepos = async ( let startFrom = 0; const limit = 100; while (!lastPage) { - debug(`Fetching page ${pageCount} for ${projectKey}\n`); + debug(`Fetching page ${pageCount} for ${projectName}\n`); try { const { repos, isLastPage, start } = await getRepos( url, - projectKey, + projectName, token, startFrom, limit, @@ -49,7 +50,7 @@ export const fetchAllRepos = async ( const getRepos = async ( url: string, - projectKey: string, + projectName: string, token: string, startFrom: number, limit: number, @@ -65,20 +66,20 @@ const getRepos = async ( const { body, statusCode } = await limiterWithRateLimitRetries( 'get', - `${url}/rest/api/1.0/repos?projectname=${projectKey}&state=AVAILABLE&start=${startFrom}&limit=${limit}`, + `${url}/rest/api/1.0/repos?projectname=${projectName}&state=AVAILABLE&start=${startFrom}&limit=${limit}`, headers, limiter, 60000, ); if (statusCode != 200) { - throw new Error(`Failed to fetch repos for ${url}/rest/api/1.0/repos?projectname=${projectKey}&state=AVAILABLE&start=${startFrom}&limit=${limit}\n + throw new Error(`Failed to fetch repos for ${url}/rest/api/1.0/repos?projectname=${projectName}&state=AVAILABLE&start=${startFrom}&limit=${limit}\n Status Code: ${statusCode}\n Response body: ${JSON.stringify(body)}`); } const { values, isLastPage, nextPageStart } = body; start = nextPageStart || -1; for (const repo of values) { - if (repo.project.key === projectKey) { + if (repo.project.name === projectName) { repos.push({ projectKey: repo.project.key, repoSlug: repo.name }); } } diff --git a/src/lib/source-handlers/bitbucket-server/project-is-empty.ts b/src/lib/source-handlers/bitbucket-server/project-is-empty.ts index 3b5534c5..5dcdb874 100644 --- a/src/lib/source-handlers/bitbucket-server/project-is-empty.ts +++ b/src/lib/source-handlers/bitbucket-server/project-is-empty.ts @@ -2,7 +2,7 @@ import { getBitbucketServerToken } from './get-bitbucket-server-token'; import { fetchAllRepos } from './list-repos'; export async function bitbucketServerProjectIsEmpty( - projectKey: string, + projectName: string, sourceUrl?: string, ): Promise { const bitbucketServerToken = getBitbucketServerToken(); @@ -13,7 +13,7 @@ export async function bitbucketServerProjectIsEmpty( } const repos = await fetchAllRepos( sourceUrl, - projectKey, + projectName, bitbucketServerToken, ); if (!repos || repos.length === 0) { diff --git a/test/system/fixtures/org-data/bitbucket-server-orgs.json b/test/system/fixtures/org-data/bitbucket-server-orgs.json index ae12db9d..dadb3112 100644 --- a/test/system/fixtures/org-data/bitbucket-server-orgs.json +++ b/test/system/fixtures/org-data/bitbucket-server-orgs.json @@ -1,7 +1,7 @@ { "orgData": [ { - "name": "AN", + "name": "antoine-snyk-demo", "orgId": "", "integrations": { "bitbucket-server": ""