Permalink
Browse files

feat(): list of previous build and job runs

  • Loading branch information...
Izak88 committed Aug 16, 2017
1 parent 82857e6 commit fd87f07ab341710c3e3a40bf5750bbbd29246eec
@@ -17,23 +17,23 @@ describe('Job Details', () => {

it('should see console log and then collapse last command output', () => {
return browser.get('/job/15')
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 5;
});
}))
.then((): any => element.all(by.css('.terminal .command-line')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 4;
});
}));
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 5;
});
}))
.then((): any => element.all(by.css('.terminal .command-line')).first().click())
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .command')).count().then(cnt => cnt === 6);
}))
.then((): any => browser.wait(() => {
return element.all(by.css('.terminal .output.is-hidden')).count().then(cnt => {
return cnt === 4;
});
}));
});

it('should restart job watch console log until it matches expected output', () => {
@@ -30,20 +30,21 @@ 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'] }).then(build => {
if (!build) {
reject();
}
new Build({ id: id }).fetch({ withRelated: ['repository', 'jobs.runs', 'runs'] })
.then(build => {
if (!build) {
reject();
}

build = build.toJSON();
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;
return job;
});
build = build.toJSON();
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;
return job;
});

return build;
return build;
})
.then(build => {
new BuildRun()
@@ -96,6 +97,7 @@ export function updateBuild(data: any): Promise<boolean> {
delete data.jobs;
delete data.repository;
delete data.lastBuild;
delete data.runs;

new Build({ id: data.id }).save(data, { method: 'update', require: false }).then(build => {
if (!build) {
@@ -31,17 +31,3 @@ export function updateJobRun(data: any): Promise<any> {
.then(job => resolve(job.toJSON()));
});
}

export function resetJobRun(runId: number): Promise<any> {
return new Promise((resolve, reject) => {
const data = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
id: runId
};

updateJobRun(data);
});
}
@@ -116,6 +116,8 @@ export function create(): Promise<null> {
t.text('log');
t.integer('job_id').notNullable();
t.foreign('job_id').references('job.id');
t.integer('build_run_id').notNullable();
t.foreign('build_run_id').references('build_run.id');
t.timestamps();
}))
.then(() => schema.createTableIfNotExists('permissions', (t: knex.TableBuilder) => {
@@ -37,4 +37,5 @@ export class JobRun extends Bookshelf.Model<any> {
get tableName() { return 'job_runs'; }
get hasTimestamps() { return true; }
job() { return this.belongsTo(Job, 'job_id'); }
build_run() { return this.belongsTo(BuildRun, 'build_run_id'); }
}
@@ -147,25 +147,30 @@ export function startBuild(data: any): Promise<any> {
builds_id: build.id
};

return dbJob.insertJob(jobData).then(job => {
const jobRunData = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
job_id: job.id
};
return dbJobRuns.insertJobRun(jobRunData).then(() => {
jobEvents.next({
type: 'process',
build_id: build.id,
job_id: job.id,
data: 'jobAdded'
return dbJob.insertJob(jobData)
.then(job => {
getLastRunId(build.id).then(buildRunId => {
const jobRunData = {
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: buildRunId,
job_id: job.id
};

return dbJobRuns.insertJobRun(jobRunData).then(() => {
jobEvents.next({
type: 'process',
build_id: build.id,
job_id: job.id,
data: 'jobAdded'
});

return queueJob(build.id, job.id);
});
});

return queueJob(build.id, job.id);
});
});
});
}, Promise.resolve());
});
@@ -356,10 +361,22 @@ export function restartBuild(buildId: number): Promise<any> {

return updateBuild(build)
.then(() => {
jobs.forEach(job => {
dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: job.id }
);
build.build_id = buildId;
delete build.repositories_id;
delete build.jobs;
insertBuildRun(build);
})
.then(() => getLastRunId(build.id))
.then(buildRunId => {
return jobs.forEach(job => {
dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: buildRunId,
job_id: job.id
});
});
})
.then(() => {
@@ -382,8 +399,14 @@ export function stopBuild(buildId: number): Promise<any> {
export function restartJob(jobId: number): Promise<void> {
let jobData = null;
return stopJob(jobId)
.then(() => dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: jobId }))
.then(() => dbJob.getLastRun(jobId))
.then(lastRun => dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: lastRun.build_run_id,
job_id: jobId }))
.then(job => jobData = job)
.then(() => queueJob(jobData.builds_id, jobId))
.then(() => {
@@ -399,8 +422,14 @@ export function restartJob(jobId: number): Promise<void> {
export function restartJobWithSshAndVnc(jobId: number): Promise<void> {
let jobData = null;
return stopJob(jobId)
.then(() => dbJobRuns.insertJobRun(
{ start_time: new Date(), end_time: null, status: 'queued', log: '', job_id: jobId }))
.then(() => dbJob.getLastRun(jobId))
.then(lastRun => dbJobRuns.insertJobRun({
start_time: new Date(),
end_time: null,
status: 'queued',
log: '',
build_run_id: lastRun.build_run_id,
job_id: jobId }))
.then(job => jobData = job)
.then(() => queueJob(jobData.builds_id, jobId, true))
.then(() => {
@@ -131,6 +131,26 @@ <h2>{{ build?.message }}</h2>
</div>
</div>
</div>
<div class="column is-12" *ngIf="build.runs && build.runs.length > 1">
<div class="build-top-container">
<div class="build-top-content">
<h1 class="bold">
<span>Previous Runs:</span>
</h1>
<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 }">
<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>
<div class="column is-8">
<span>{{ run.message }} ({{ run.sha}})</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -104,6 +104,23 @@ <h2>{{ job?.build?.message }}</h2>
<div class="column is-12">
<app-terminal [data]="terminalInput" (outputData)="terminalOutput($event)" [options]="terminalOptions"></app-terminal>
</div>
<div class="column is-12" *ngIf="job.runs && job.runs.length > 1">
<div class="build-top-container">
<div class="build-top-content">
<h1 class="bold">
<span>Previous Runs:</span>
</h1>
<hr/>
<div class="columns list-item"
*ngFor="let run of job.runs; let i = index;"
[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-8">
<span>{{ run.start_time | date:'dd MM yyyy hh:mm:ss' }} - {{ run.end_time | date:'dd MM yyyy hh:mm:ss' }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

0 comments on commit fd87f07

Please sign in to comment.