diff --git a/.changeset/wet-cameras-juggle.md b/.changeset/wet-cameras-juggle.md new file mode 100644 index 0000000000..62cc206356 --- /dev/null +++ b/.changeset/wet-cameras-juggle.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-azure-devops-backend': patch +'@backstage/plugin-azure-devops-common': patch +--- + +Adding getProjects endpoint to list out all projects associated with the Azure DevOps organization. + +It can be accessed by using this endpoint `{backendUrl}/api/azure-devops/projects` diff --git a/plugins/azure-devops-backend/api-report.md b/plugins/azure-devops-backend/api-report.md index e3e3d9e161..eaebea4d7b 100644 --- a/plugins/azure-devops-backend/api-report.md +++ b/plugins/azure-devops-backend/api-report.md @@ -12,6 +12,7 @@ import express from 'express'; import { GitRepository } from 'azure-devops-node-api/interfaces/GitInterfaces'; import { GitTag } from '@backstage/plugin-azure-devops-common'; import { Logger } from 'winston'; +import { Project } from '@backstage/plugin-azure-devops-common'; import { PullRequest } from '@backstage/plugin-azure-devops-common'; import { PullRequestOptions } from '@backstage/plugin-azure-devops-common'; import { RepoBuild } from '@backstage/plugin-azure-devops-common'; @@ -64,6 +65,8 @@ export class AzureDevOpsApi { // (undocumented) getGitTags(projectName: string, repoName: string): Promise; // (undocumented) + getProjects(): Promise; + // (undocumented) getPullRequests( projectName: string, repoName: string, diff --git a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts index b6cc174056..240ba0b189 100644 --- a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts +++ b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts @@ -30,6 +30,7 @@ import { RepoBuild, Team, TeamMember, + Project, } from '@backstage/plugin-azure-devops-common'; import { GitPullRequest, @@ -47,7 +48,10 @@ import { TeamMember as AdoTeamMember } from 'azure-devops-node-api/interfaces/co import { Logger } from 'winston'; import { PolicyEvaluationRecord } from 'azure-devops-node-api/interfaces/PolicyInterfaces'; import { WebApi } from 'azure-devops-node-api'; -import { WebApiTeam } from 'azure-devops-node-api/interfaces/CoreInterfaces'; +import { + TeamProjectReference, + WebApiTeam, +} from 'azure-devops-node-api/interfaces/CoreInterfaces'; export class AzureDevOpsApi { public constructor( @@ -55,6 +59,20 @@ export class AzureDevOpsApi { private readonly webApi: WebApi, ) {} + public async getProjects(): Promise { + const client = await this.webApi.getCoreApi(); + const projectList: TeamProjectReference[] = await client.getProjects(); + + const projects: Project[] = projectList.map(project => ({ + id: project.id, + name: project.name, + description: project.description, + })); + + return projects.sort((a, b) => + a.name && b.name ? a.name.localeCompare(b.name) : 0, + ); + } public async getGitRepository( projectName: string, repoName: string, diff --git a/plugins/azure-devops-backend/src/service/router.ts b/plugins/azure-devops-backend/src/service/router.ts index 23ed7f146d..a4a76b4a14 100644 --- a/plugins/azure-devops-backend/src/service/router.ts +++ b/plugins/azure-devops-backend/src/service/router.ts @@ -63,6 +63,11 @@ export async function createRouter( res.status(200).json({ status: 'ok' }); }); + router.get('/projects', async (_req, res) => { + const projects = await azureDevOpsApi.getProjects(); + res.status(200).json(projects); + }); + router.get('/repository/:projectName/:repoName', async (req, res) => { const { projectName, repoName } = req.params; const gitRepository = await azureDevOpsApi.getGitRepository( diff --git a/plugins/azure-devops-common/api-report.md b/plugins/azure-devops-common/api-report.md index bdb4cc424d..34d911dac6 100644 --- a/plugins/azure-devops-common/api-report.md +++ b/plugins/azure-devops-common/api-report.md @@ -168,6 +168,15 @@ export enum PolicyTypeId { Status = 'cbdc66da-9728-4af8-aada-9a5a32e4a226', } +// Warning: (ae-missing-release-tag) "Project" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type Project = { + id?: string; + name?: string; + description?: string; +}; + // Warning: (ae-missing-release-tag) "PullRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) diff --git a/plugins/azure-devops-common/src/types.ts b/plugins/azure-devops-common/src/types.ts index 0ff5e897ed..db2813dec1 100644 --- a/plugins/azure-devops-common/src/types.ts +++ b/plugins/azure-devops-common/src/types.ts @@ -288,3 +288,9 @@ export type BuildRun = { export type BuildRunOptions = { top?: number; }; + +export type Project = { + id?: string; + name?: string; + description?: string; +};