Permalink
Browse files

fix(process-manager): catch promises, fix unworking things in pm

  • Loading branch information...
jkuri committed Aug 17, 2017
1 parent d7b4380 commit a032e3559688b48770a33f683b5be3cf0067f4e0
Showing with 223 additions and 174 deletions.
  1. +11 −6 src/api/db/build-run.ts
  2. +1 −1 src/api/db/build.ts
  3. +44 −44 src/api/github-commit-status.ts
  4. +2 −2 src/api/logger.ts
  5. +165 −121 src/api/process-manager.ts
@@ -3,24 +3,29 @@ import { BuildRun } from './model';
export function getRun(runId: number): Promise<any> {
return new Promise((resolve, reject) => {
new BuildRun({ id: runId }).fetch()
.then(job => {
if (!job) {
.then(buildRun => {
if (!buildRun) {
reject();
}

resolve(job.toJSON());
resolve(buildRun.toJSON());
});
});
}

export function insertBuildRun(data: any): Promise<any> {
return new Promise((resolve, reject) => {
new BuildRun(data).save(null, { method: 'insert' }).then(job => {
if (!job) {
delete data.id;
delete data.repositories_id;
delete data.jobs;
delete data.pr;

new BuildRun().save(data, { method: 'insert' }).then(buildRun => {
if (!buildRun) {
reject();
}

resolve(job.toJSON());
resolve(buildRun.toJSON());
});
});
}
@@ -77,7 +77,7 @@ export function getBuild(id: number): Promise<any> {
})
.fetch()
.then(lastBuild => {
build.lastBuild = lastBuild;
build.lastBuild = lastBuild.toJSON();

resolve(build);
});
@@ -28,68 +28,68 @@ function sendRequest(url: string, data: any, headers: any): Promise<any> {

export function setGitHubStatusSuccess(
gitUrl: string, abstruseUrl: string, token: string): Promise<any> {
let data = {
'state': 'success',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};
let data = {
'state': 'success',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};

let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};
let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};

return sendRequest(gitUrl, data, header);
return sendRequest(gitUrl, data, header);
}

export function setGitHubStatusPending(
gitUrl: string, abstruseUrl: string, token: string): Promise<any> {
let data = {
'state': 'pending',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};
let data = {
'state': 'pending',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};

let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};
let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};

return sendRequest(gitUrl, data, header);
return sendRequest(gitUrl, data, header);
}

export function setGitHubStatusError(
gitUrl: string, abstruseUrl: string, token: string): Promise<any> {
let data = {
'state': 'error',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};
let data = {
'state': 'error',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};

let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};
let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};

return sendRequest(gitUrl, data, header);
return sendRequest(gitUrl, data, header);
}

export function setGitHubStatusFailure(
gitUrl: string, abstruseUrl: string, token: string): Promise<any> {
let data = {
'state': 'failure',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};
let data = {
'state': 'failure',
'target_url': abstruseUrl,
'description': 'The Abstruse CI build succeeded',
'context': 'continuous-integration/abstruse'
};

let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};
let header = {
'Authorization': `token ${token}`,
'User-Agent': 'Abstruse'
};

return sendRequest(gitUrl, data, header);
return sendRequest(gitUrl, data, header);
}
@@ -5,9 +5,9 @@ export function info(msg: string): void {
console.log(`${green('[' + time + ']')} ${white(msg)}`);
}

export function error(msg: string): void {
export function error(msg: string | any): void {
const time = getDateTime();
console.log(`${green('[' + time + ']')} ${red(msg)}`);
console.log(`${green('[' + time + ']')} ${red(msg.toString())}`);
}

export function warning(msg: string): void {
Oops, something went wrong.

0 comments on commit a032e35

Please sign in to comment.