Refactored top to be number from query string
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -36,12 +36,10 @@ export class AzureDevOpsApi {
|
||||
return client.getRepository(repoName, projectName);
|
||||
}
|
||||
|
||||
async getBuildList(projectName: string, repoId: string, top: string) {
|
||||
const topBuilds: number = +top || 10;
|
||||
|
||||
async getBuildList(projectName: string, repoId: string, top: number) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${topBuilds} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,7 +57,7 @@ export class AzureDevOpsApi {
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
topBuilds,
|
||||
top,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -71,7 +69,7 @@ export class AzureDevOpsApi {
|
||||
);
|
||||
}
|
||||
|
||||
async getRepoBuilds(projectName: string, repoName: string, top: string) {
|
||||
async getRepoBuilds(projectName: string, repoName: string, top: number) {
|
||||
if (this.logger) {
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository ${repoName} for Project ${projectName}`,
|
||||
|
||||
@@ -93,14 +93,14 @@ describe('createRouter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /builds/:projectName/:repoId/:top', () => {
|
||||
describe('GET /builds/:projectName/:repoId', () => {
|
||||
it('fetches a list of builds', async () => {
|
||||
const firstBuild: Build = {
|
||||
id: 1,
|
||||
buildNumber: 'Build-1',
|
||||
status: BuildStatus.Completed,
|
||||
result: BuildResult.Succeeded,
|
||||
queueTime: '2020-09-12T06:10:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
sourceBranch: 'refs/heads/develop',
|
||||
sourceVersion: '9bedf67800b2923982bdf60c89c57ce6fd2d9a1c',
|
||||
};
|
||||
@@ -110,7 +110,7 @@ describe('createRouter', () => {
|
||||
buildNumber: 'Build-2',
|
||||
status: BuildStatus.InProgress,
|
||||
result: BuildResult.None,
|
||||
queueTime: '2020-09-12T06:20:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
sourceBranch: 'refs/heads/develop',
|
||||
sourceVersion: '13c988d4f15e06bcdd0b0af290086a3079cdadb0',
|
||||
};
|
||||
@@ -120,7 +120,7 @@ describe('createRouter', () => {
|
||||
buildNumber: 'Build-3',
|
||||
status: BuildStatus.Completed,
|
||||
result: BuildResult.PartiallySucceeded,
|
||||
queueTime: '2020-09-12T06:30:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
sourceBranch: 'refs/heads/develop',
|
||||
sourceVersion: 'f4f78b319c308600eab015a5d6529add21660dc1',
|
||||
};
|
||||
@@ -129,21 +129,21 @@ describe('createRouter', () => {
|
||||
|
||||
azureDevOpsApi.getBuildList.mockResolvedValueOnce(builds);
|
||||
|
||||
const response = await request(app).get(
|
||||
'/builds/myProject/af4ae3af-e747-4129-9bbc-d1329f6b0998/50',
|
||||
);
|
||||
const response = await request(app)
|
||||
.get('/builds/myProject/af4ae3af-e747-4129-9bbc-d1329f6b0998')
|
||||
.query({ top: '40' });
|
||||
|
||||
expect(azureDevOpsApi.getBuildList).toHaveBeenCalledWith(
|
||||
'myProject',
|
||||
'af4ae3af-e747-4129-9bbc-d1329f6b0998',
|
||||
'50',
|
||||
40,
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(builds);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /repo-builds/:projectName/:repoName/:top', () => {
|
||||
describe('GET /repo-builds/:projectName/:repoName', () => {
|
||||
it('fetches a list of repo builds', async () => {
|
||||
const firstRepoBuild: RepoBuild = {
|
||||
id: 1,
|
||||
@@ -151,7 +151,7 @@ describe('createRouter', () => {
|
||||
link: 'https://host.com/myOrg/0bcc0c0d-2d02/_build/results?buildId=1',
|
||||
status: BuildStatus.Completed,
|
||||
result: BuildResult.PartiallySucceeded,
|
||||
queueTime: '2020-09-12T06:10:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
source: 'refs/heads/develop (f4f78b31)',
|
||||
};
|
||||
|
||||
@@ -161,7 +161,7 @@ describe('createRouter', () => {
|
||||
link: 'https://host.com/myOrg/0bcc0c0d-2d02/_build/results?buildId=2',
|
||||
status: BuildStatus.InProgress,
|
||||
result: BuildResult.None,
|
||||
queueTime: '2020-09-12T06:20:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
source: 'refs/heads/develop (13c988d4)',
|
||||
};
|
||||
|
||||
@@ -171,7 +171,7 @@ describe('createRouter', () => {
|
||||
link: 'https://host.com/myOrg/0bcc0c0d-2d02/_build/results?buildId=3',
|
||||
status: BuildStatus.Completed,
|
||||
result: BuildResult.Succeeded,
|
||||
queueTime: '2020-09-12T06:30:23.9325232Z' as unknown as Date,
|
||||
queueTime: undefined,
|
||||
source: 'refs/heads/develop (9bedf678)',
|
||||
};
|
||||
|
||||
@@ -183,14 +183,14 @@ describe('createRouter', () => {
|
||||
|
||||
azureDevOpsApi.getRepoBuilds.mockResolvedValueOnce(repoBuilds);
|
||||
|
||||
const response = await request(app).get(
|
||||
'/repo-builds/myProject/myRepo/50',
|
||||
);
|
||||
const response = await request(app)
|
||||
.get('/repo-builds/myProject/myRepo')
|
||||
.query({ top: '50' });
|
||||
|
||||
expect(azureDevOpsApi.getRepoBuilds).toHaveBeenCalledWith(
|
||||
'myProject',
|
||||
'myRepo',
|
||||
'50',
|
||||
50,
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(repoBuilds);
|
||||
|
||||
@@ -22,6 +22,8 @@ import { Config } from '@backstage/config';
|
||||
import { getPersonalAccessTokenHandler, WebApi } from 'azure-devops-node-api';
|
||||
import { AzureDevOpsApi } from '../api';
|
||||
|
||||
const DEFAULT_TOP: number = 10;
|
||||
|
||||
export interface RouterOptions {
|
||||
azureDevOpsApi?: AzureDevOpsApi;
|
||||
logger: Logger;
|
||||
@@ -88,8 +90,9 @@ export async function createRouter(
|
||||
res.status(200).json(gitRepository);
|
||||
});
|
||||
|
||||
router.get('/builds/:projectName/:repoId/:top', async (req, res) => {
|
||||
const { projectName, repoId, top } = req.params;
|
||||
router.get('/builds/:projectName/:repoId', async (req, res) => {
|
||||
const { projectName, repoId } = req.params;
|
||||
const top = req.query.top ? Number(req.query.top) : DEFAULT_TOP;
|
||||
const buildList = await azureDevOpsApi.getBuildList(
|
||||
projectName,
|
||||
repoId,
|
||||
@@ -98,8 +101,9 @@ export async function createRouter(
|
||||
res.status(200).json(buildList);
|
||||
});
|
||||
|
||||
router.get('/repo-builds/:projectName/:repoName/:top', async (req, res) => {
|
||||
const { projectName, repoName, top } = req.params;
|
||||
router.get('/repo-builds/:projectName/:repoName', async (req, res) => {
|
||||
const { projectName, repoName } = req.params;
|
||||
const top = req.query.top ? Number(req.query.top) : DEFAULT_TOP;
|
||||
const gitRepository = await azureDevOpsApi.getRepoBuilds(
|
||||
projectName,
|
||||
repoName,
|
||||
|
||||
Reference in New Issue
Block a user