Merge pull request #12509 from cal5barton/feature/azure-devops-get-projects

Adding ability to list projects from Azure DevOps organization
This commit is contained in:
Patrik Oldsberg
2022-07-08 09:45:42 +02:00
committed by GitHub
6 changed files with 50 additions and 1 deletions
@@ -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<GitTag[]>;
// (undocumented)
getProjects(): Promise<Project[]>;
// (undocumented)
getPullRequests(
projectName: string,
repoName: string,
@@ -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<Project[]> {
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(
@@ -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)
+6
View File
@@ -288,3 +288,9 @@ export type BuildRun = {
export type BuildRunOptions = {
top?: number;
};
export type Project = {
id?: string;
name?: string;
description?: string;
};