feature(jenkins-backend): added support for standalone jenkins projects

Signed-off-by: Gabriel Testault <gabriel.testault@goto.com>
This commit is contained in:
Gabriel Testault
2022-12-12 17:43:23 +01:00
parent 0e5f8270f0
commit 496201574d
2 changed files with 42 additions and 3 deletions
@@ -75,6 +75,37 @@ describe('JenkinsApi', () => {
},
};
describe('standalone project', () => {
it('should return the only build', async () => {
mockedJenkinsClient.job.get
.mockResolvedValueOnce(project)
.mockResolvedValueOnce(project);
const result = await jenkinsApi.getProjects(jenkinsInfo);
expect(result).toHaveLength(1);
expect(result[0]).toEqual({
actions: [],
displayName: 'Example Build',
fullDisplayName: 'Example jobName » Example Build',
fullName: 'example-jobName/exampleBuild',
inQueue: false,
lastBuild: {
actions: [],
timestamp: 1,
building: false,
duration: 10,
result: 'success',
displayName: '#7',
fullDisplayName: 'Example jobName » Example Build #7',
url: 'https://jenkins.example.com/job/example-jobName/job/exampleBuild',
number: 7,
status: 'success',
source: {},
},
status: 'success',
});
});
});
describe('unfiltered', () => {
it('standard github layout', async () => {
mockedJenkinsClient.job.get.mockResolvedValueOnce({ jobs: [project] });
@@ -89,7 +89,7 @@ export class JenkinsApiImpl {
} else {
// We aren't filtering
// Assume jenkinsInfo.jobFullName is a folder which contains one job per branch.
const folder = await client.job.get({
const project = await client.job.get({
name: jenkinsInfo.jobFullName,
// Filter only be the information we need, instead of loading all fields.
// Limit to only show the latest build for each job and only load 50 jobs
@@ -99,8 +99,16 @@ export class JenkinsApiImpl {
tree: JenkinsApiImpl.jobsTreeSpec.replace(/\s/g, ''),
});
// TODO: support this being a project itself.
for (const jobDetails of folder.jobs) {
const isStandaloneProject = !project.jobs;
if (isStandaloneProject) {
const standaloneProject = await client.job.get({
name: jenkinsInfo.jobFullName,
tree: JenkinsApiImpl.jobTreeSpec.replace(/\s/g, ''),
});
projects.push(this.augmentProject(standaloneProject));
return projects;
}
for (const jobDetails of project.jobs) {
// for each branch (we assume)
if (jobDetails?.jobs) {
// skipping folders inside folders for now