Skip to content

Commit

Permalink
fix(): show correct status of previous build run
Browse files Browse the repository at this point in the history
  • Loading branch information
Izak88 committed Aug 16, 2017
1 parent 633b030 commit 79009b4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
29 changes: 24 additions & 5 deletions src/api/db/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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();
Expand All @@ -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 => {
Expand Down Expand Up @@ -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);
});
});
}
Expand Down
11 changes: 2 additions & 9 deletions src/api/db/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -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()));
});
}

Expand Down
1 change: 1 addition & 0 deletions src/api/db/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
1 change: 1 addition & 0 deletions src/api/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 79009b4

Please sign in to comment.