Adding ability to list projects from Azure DevOps organization
Signed-off-by: Callen Barton <7515844+cal5barton@users.noreply.github.com>
This commit is contained in:
@@ -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`
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<Project[]> {
|
||||
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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -288,3 +288,9 @@ export type BuildRun = {
|
||||
export type BuildRunOptions = {
|
||||
top?: number;
|
||||
};
|
||||
|
||||
export type Project = {
|
||||
id?: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user