Skip to content

Commit

Permalink
feat: use project id to list Azure repos
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Aug 31, 2022
1 parent bfd28a5 commit 87d73f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/lib/source-handlers/azure/list-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ interface AzureReposResponse {
export async function fetchAllRepos(
url: string,
orgName: string,
project: string,
project: {
name: string;
id: string;
},
token: string,
): Promise<AzureRepoData[]> {
debug('Fetching repos for ' + project);
debug('Fetching repos for ' + project.name);
let repoList: AzureRepoData[] = [];
try {
repoList = await getRepos(url, orgName, project, token);
repoList = await getRepos(url, orgName, project.id, token);
} catch (err) {
throw new Error(JSON.stringify(err));
}
Expand All @@ -36,7 +39,7 @@ export async function fetchAllRepos(
async function getRepos(
url: string,
orgName: string,
project: string,
projectId: string,
token: string,
): Promise<AzureRepoData[]> {
const repoList: AzureRepoData[] = [];
Expand All @@ -48,17 +51,13 @@ async function getRepos(
AzureReposResponse
>(
'get',
`${url}/${orgName}/` +
encodeURIComponent(project) +
'/_apis/git/repositories?api-version=4.1',
`${url}/${orgName}/${projectId}/_apis/git/repositories?api-version=4.1`,
headers,
limiter,
60000,
);
if (statusCode != 200) {
throw new Error(`Failed to fetch repos for ${url}/${orgName}/${encodeURIComponent(
project,
)}/_apis/git/repositories?api-version=4.1\n
throw new Error(`Failed to fetch repos for ${url}/${orgName}/${projectId}/_apis/git/repositories?api-version=4.1\n
Status Code: ${statusCode}\n
Response body: ${JSON.stringify(body)}`);
}
Expand Down Expand Up @@ -87,7 +86,12 @@ export async function listAzureRepos(
const projectList = await listAzureProjects(orgName, baseUrl);
for (const project of projectList) {
repoList.push(
...(await fetchAllRepos(baseUrl, orgName, project.name, azureToken)),
...(await fetchAllRepos(
baseUrl,
orgName,
{ name: project.name, id: project.id },
azureToken,
)),
);
}
return repoList;
Expand Down
2 changes: 1 addition & 1 deletion test/lib/source-handlers/azure/azure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ beforeEach(() => {
'utf8',
),
);
case '/reposTestOrg/Test68/_apis/git/repositories?api-version=4.1':
case '/reposTestOrg/371efd3e-3e86-4d33-846d-e5e46397dd91/_apis/git/repositories?api-version=4.1':
return JSON.parse(
fs.readFileSync(fixturesFolderPath + 'org-repos.json', 'utf8'),
);
Expand Down

0 comments on commit 87d73f9

Please sign in to comment.