Moved top so it will be provided by the future frontend
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -405,4 +405,3 @@ azureDevOps:
|
||||
host: dev.azure.com
|
||||
token: ${AZURE_TOKEN}
|
||||
organization: my-company
|
||||
top: 50
|
||||
|
||||
@@ -11,7 +11,6 @@ azureDevOps:
|
||||
host: dev.azure.com
|
||||
token: ${AZURE_TOKEN}
|
||||
organization: my-company
|
||||
top: 50
|
||||
```
|
||||
|
||||
Configuration Details:
|
||||
@@ -19,7 +18,6 @@ Configuration Details:
|
||||
- `host` and `token` can be the same as the ones used for the `integration` section
|
||||
- `AZURE_TOKEN` environment variable must be set to a [Personal Access Token](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page) with read access to both Code and Build
|
||||
- `organization` is your Azure DevOps Organization name or for Azure DevOps Server (on-premise) this will be your Collection name
|
||||
- `top` sets the max number of items to return - currently only applies to builds
|
||||
|
||||
## Links
|
||||
|
||||
|
||||
-4
@@ -30,9 +30,5 @@ export interface Config {
|
||||
* The organization of the given Azure instance
|
||||
*/
|
||||
organization: string;
|
||||
/**
|
||||
* The max number of items to return - applies to builds
|
||||
*/
|
||||
top: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,12 +26,11 @@ export class AzureDevOpsApi {
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly webApi: WebApi,
|
||||
private readonly top: number,
|
||||
) {}
|
||||
|
||||
async getGitRepository(projectName: string, repoName: string) {
|
||||
if (this.logger) {
|
||||
this.logger.info(
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
@@ -40,10 +39,12 @@ export class AzureDevOpsApi {
|
||||
return client.getRepository(repoName, projectName);
|
||||
}
|
||||
|
||||
async getBuildList(projectName: string, repoId: string) {
|
||||
async getBuildList(projectName: string, repoId: string, top: string) {
|
||||
const topBuilds: number = +top || 10;
|
||||
|
||||
if (this.logger) {
|
||||
this.logger.info(
|
||||
`Calling Azure DevOps REST API, getting up to ${this.top} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${topBuilds} Builds for Repository Id ${repoId} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ export class AzureDevOpsApi {
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
this.top,
|
||||
topBuilds,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -73,10 +74,10 @@ export class AzureDevOpsApi {
|
||||
);
|
||||
}
|
||||
|
||||
async getRepoBuilds(projectName: string, repoName: string) {
|
||||
async getRepoBuilds(projectName: string, repoName: string, top: string) {
|
||||
if (this.logger) {
|
||||
this.logger.info(
|
||||
`Calling Azure DevOps REST API, getting up to ${this.top} Builds for Repository ${repoName} for Project ${projectName}`,
|
||||
this.logger.debug(
|
||||
`Calling Azure DevOps REST API, getting up to ${top} Builds for Repository ${repoName} for Project ${projectName}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,6 +85,7 @@ export class AzureDevOpsApi {
|
||||
const buildList = await this.getBuildList(
|
||||
projectName,
|
||||
gitRepository.id as string,
|
||||
top,
|
||||
);
|
||||
|
||||
const repoBuilds = buildList.map(build => {
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('createRouter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /builds/:projectName/:repoId', () => {
|
||||
describe('GET /builds/:projectName/:repoId/:top', () => {
|
||||
it('fetches a list of builds', async () => {
|
||||
const firstBuild: Build = {
|
||||
id: 1,
|
||||
@@ -130,19 +130,20 @@ describe('createRouter', () => {
|
||||
azureDevOpsApi.getBuildList.mockResolvedValueOnce(builds);
|
||||
|
||||
const response = await request(app).get(
|
||||
'/builds/myProject/af4ae3af-e747-4129-9bbc-d1329f6b0998',
|
||||
'/builds/myProject/af4ae3af-e747-4129-9bbc-d1329f6b0998/50',
|
||||
);
|
||||
|
||||
expect(azureDevOpsApi.getBuildList.mock.calls[0]).toEqual([
|
||||
'myProject',
|
||||
'af4ae3af-e747-4129-9bbc-d1329f6b0998',
|
||||
'50',
|
||||
]);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(builds);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /repo-builds/:projectName/:repoName', () => {
|
||||
describe('GET /repo-builds/:projectName/:repoName/:top', () => {
|
||||
it('fetches a list of repo builds', async () => {
|
||||
const firstRepoBuild: RepoBuild = {
|
||||
id: 1,
|
||||
@@ -182,11 +183,14 @@ describe('createRouter', () => {
|
||||
|
||||
azureDevOpsApi.getRepoBuilds.mockResolvedValueOnce(repoBuilds);
|
||||
|
||||
const response = await request(app).get('/repo-builds/myProject/myRepo');
|
||||
const response = await request(app).get(
|
||||
'/repo-builds/myProject/myRepo/50',
|
||||
);
|
||||
|
||||
expect(azureDevOpsApi.getRepoBuilds.mock.calls[0]).toEqual([
|
||||
'myProject',
|
||||
'myRepo',
|
||||
'50',
|
||||
]);
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.body).toEqual(repoBuilds);
|
||||
|
||||
@@ -37,13 +37,12 @@ export async function createRouter(
|
||||
const token: string = config.getString('token');
|
||||
const host: string = config.getString('host');
|
||||
const organization: string = config.getString('organization');
|
||||
const top: number = config.getOptionalNumber('top') || 10;
|
||||
|
||||
const authHandler = getPersonalAccessTokenHandler(token);
|
||||
const webApi = new WebApi(`https://${host}/${organization}`, authHandler);
|
||||
|
||||
const azureDevOpsApi =
|
||||
options.azureDevOpsApi || new AzureDevOpsApi(logger, webApi, top);
|
||||
options.azureDevOpsApi || new AzureDevOpsApi(logger, webApi);
|
||||
|
||||
const router = Router();
|
||||
router.use(express.json());
|
||||
@@ -89,17 +88,22 @@ export async function createRouter(
|
||||
res.status(200).json(gitRepository);
|
||||
});
|
||||
|
||||
router.get('/builds/:projectName/:repoId', async (req, res) => {
|
||||
const { projectName, repoId } = req.params;
|
||||
const buildList = await azureDevOpsApi.getBuildList(projectName, repoId);
|
||||
router.get('/builds/:projectName/:repoId/:top', async (req, res) => {
|
||||
const { projectName, repoId, top } = req.params;
|
||||
const buildList = await azureDevOpsApi.getBuildList(
|
||||
projectName,
|
||||
repoId,
|
||||
top,
|
||||
);
|
||||
res.status(200).json(buildList);
|
||||
});
|
||||
|
||||
router.get('/repo-builds/:projectName/:repoName', async (req, res) => {
|
||||
const { projectName, repoName } = req.params;
|
||||
router.get('/repo-builds/:projectName/:repoName/:top', async (req, res) => {
|
||||
const { projectName, repoName, top } = req.params;
|
||||
const gitRepository = await azureDevOpsApi.getRepoBuilds(
|
||||
projectName,
|
||||
repoName,
|
||||
top,
|
||||
);
|
||||
res.status(200).json(gitRepository);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user