From e67c4b7d5aa875f040fb2f61c141c2b1c1c231f9 Mon Sep 17 00:00:00 2001 From: Callen Barton <7515844+cal5barton@users.noreply.github.com> Date: Thu, 7 Jul 2022 09:46:31 -0600 Subject: [PATCH 1/4] Adding ability to list projects from Azure DevOps organization Signed-off-by: Callen Barton <7515844+cal5barton@users.noreply.github.com> --- .changeset/wet-cameras-juggle.md | 8 +++++++ docs/overview/versioning-policy.md | 2 +- .../src/api/AzureDevOpsApi.ts | 22 ++++++++++++++++++- .../src/service/router.ts | 5 +++++ plugins/azure-devops-common/src/types.ts | 6 +++++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .changeset/wet-cameras-juggle.md diff --git a/.changeset/wet-cameras-juggle.md b/.changeset/wet-cameras-juggle.md new file mode 100644 index 0000000000..dad2a26eb7 --- /dev/null +++ b/.changeset/wet-cameras-juggle.md @@ -0,0 +1,8 @@ +--- +'@backstage/plugin-azure-devops-backend': minor +'@backstage/plugin-azure-devops-common': minor +--- + +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/docs/overview/versioning-policy.md b/docs/overview/versioning-policy.md index 282906c580..885a599ed8 100644 --- a/docs/overview/versioning-policy.md +++ b/docs/overview/versioning-policy.md @@ -49,7 +49,7 @@ functionality, breaking changes, and bug fixes, according the [versioning policy](#release-versioning-policy). Patch versions will only be released to address critical bug fixes. They are not -bound to the regular cadence and are instead releases whenever needed. +bound to the regular cadence and are instead released whenever needed. ## Next Release Line diff --git a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts index b6cc174056..51dbea8936 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,22 @@ export class AzureDevOpsApi { private readonly webApi: WebApi, ) {} + public async getProjects(): Promise { + this.logger?.debug(`Getting all projects.`); + + 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/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; +}; From 0869a85ff4bd5cc2f79845686a1d262f859141d7 Mon Sep 17 00:00:00 2001 From: Callen Barton <7515844+cal5barton@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:21:31 -0600 Subject: [PATCH 2/4] Changing to patch Signed-off-by: Callen Barton <7515844+cal5barton@users.noreply.github.com> --- .changeset/wet-cameras-juggle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/wet-cameras-juggle.md b/.changeset/wet-cameras-juggle.md index dad2a26eb7..62cc206356 100644 --- a/.changeset/wet-cameras-juggle.md +++ b/.changeset/wet-cameras-juggle.md @@ -1,6 +1,6 @@ --- -'@backstage/plugin-azure-devops-backend': minor -'@backstage/plugin-azure-devops-common': minor +'@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. From 2321793465756396c69ef83496f182d33537c0f9 Mon Sep 17 00:00:00 2001 From: Callen Barton <7515844+cal5barton@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:23:46 -0600 Subject: [PATCH 3/4] Removing log statement Signed-off-by: Callen Barton <7515844+cal5barton@users.noreply.github.com> --- plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts index 51dbea8936..240ba0b189 100644 --- a/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts +++ b/plugins/azure-devops-backend/src/api/AzureDevOpsApi.ts @@ -60,8 +60,6 @@ export class AzureDevOpsApi { ) {} public async getProjects(): Promise { - this.logger?.debug(`Getting all projects.`); - const client = await this.webApi.getCoreApi(); const projectList: TeamProjectReference[] = await client.getProjects(); From fc583608d8cfc00a4a165bfa0145ca7f3816d60c Mon Sep 17 00:00:00 2001 From: Callen Barton <7515844+cal5barton@users.noreply.github.com> Date: Thu, 7 Jul 2022 10:29:38 -0600 Subject: [PATCH 4/4] Updating api reports Signed-off-by: Callen Barton <7515844+cal5barton@users.noreply.github.com> --- plugins/azure-devops-backend/api-report.md | 3 +++ plugins/azure-devops-common/api-report.md | 9 +++++++++ 2 files changed, 12 insertions(+) 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-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)