Permalink
Browse files

fix(): show correct status of previous build run

  • Loading branch information...
Izak88 committed Aug 16, 2017
1 parent 633b030 commit 79009b423ccc6a7cad7cf6b17f6b3229a9a6579f
@@ -14,9 +14,12 @@ export function getBuilds(limit: number, offset: number): Promise<any> {
builds = builds.toJSON();
builds = builds.map(build => {
build.jobs = build.jobs.map(job => {
job.end_time = job.runs[job.runs.length - 1].end_time;
job.start_time = job.runs[job.runs.length - 1].start_time;
job.status = job.runs[job.runs.length - 1].status;
if (job.runs.length > 0) {
job.end_time = job.runs[job.runs.length - 1].end_time;
job.start_time = job.runs[job.runs.length - 1].start_time;
job.status = job.runs[job.runs.length - 1].status;
}

return job;
});

@@ -30,7 +33,7 @@ export function getBuilds(limit: number, offset: number): Promise<any> {

export function getBuild(id: number): Promise<any> {
return new Promise((resolve, reject) => {
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs'] })
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs.job_runs'] })
.then(build => {
if (!build) {
reject();
@@ -44,6 +47,22 @@ export function getBuild(id: number): Promise<any> {
return job;
});

build.runs = build.runs.map(run => {
if (run.job_runs) {
if (run.job_runs.findIndex(j => j.status === 'queued') !== -1) {
run.status = 'queued';
} else if (run.job_runs.findIndex(j => j.status === 'running') !== -1) {
run.status = 'running';
} else if (run.job_runs.findIndex(j => j.status === 'failed') !== -1) {
run.status = 'failed';
} else if (run.job_runs.findIndex(j => j.status === 'success') !== -1) {
run.status = 'success';
}
}

return run;
});

return build;
})
.then(build => {
@@ -75,7 +94,7 @@ export function getLastRunId(buildId: number): Promise<any> {
}
const runs = build.related('runs').toJSON();

resolve (runs[runs.length - 1].id);
resolve(runs.length > 0 ? runs[runs.length - 1].id : -1);
});
});
}
@@ -49,7 +49,7 @@ export function getLastRunId(jobId: number): Promise<any> {
}
const runs = job.related('runs').toJSON();

resolve (runs[runs.length - 1].id);
resolve(runs.length > 0 ? runs[runs.length - 1].id : -1);
});
});
}
@@ -97,14 +97,7 @@ export function resetJobs(buildId: number): Promise<any> {
};

new Job().where({ builds_id: buildId }).save(data, { method: 'update', require: false })
.then(jobs => {
if (!jobs) {
reject();
} else {
new Job().where({ builds_id: buildId }).fetchAll()
.then(jobs => jobs ? resolve(jobs.toJSON()) : reject(jobs));
}
});
.then(jobs => !jobs ? reject() : resolve(jobs.toJSON()));
});
}

@@ -24,6 +24,7 @@ export class BuildRun extends Bookshelf.Model<any> {
get tableName() { return 'build_runs'; }
get hasTimestamps() { return true; }
build() { return this.belongsTo(Build, 'build_id'); }
job_runs() { return this.hasMany(JobRun, 'build_run_id'); }
}

export class Job extends Bookshelf.Model<any> {
@@ -130,6 +130,7 @@ export function startBuild(data: any): Promise<any> {
.then(build => {
data.build_id = build.id;
delete data.repositories_id;
delete data.pr;
insertBuildRun(data);
const jobsCommands = generateCommands(repository.clone_url, repoDetails.config);

@@ -140,7 +140,7 @@ <h1 class="bold">
<hr/>
<div class="columns list-item"
*ngFor="let run of build.runs; let i = index;"
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': true }">
[ngClass]="{ 'is-queued': run.status === 'queued', 'is-success': run.status === 'success', 'is-running': run.status === 'running', 'is-errored': run.status === 'failed' }">
<div class="column is-4">
<span>{{ run.start_time | date:'dd MM yyyy hh:mm:ss' }} - {{ run.end_time | date:'dd MM yyyy hh:mm:ss' }}</span>
</div>

0 comments on commit 79009b4

Please sign in to comment.