Skip to content

Commit

Permalink
fix(process-manager): catch promises, fix unworking things in pm
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Aug 18, 2017
1 parent d7b4380 commit a032e35
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 174 deletions.
17 changes: 11 additions & 6 deletions src/api/db/build-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/db/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function getBuild(id: number): Promise<any> {
})
.fetch()
.then(lastBuild => {
build.lastBuild = lastBuild;
build.lastBuild = lastBuild.toJSON();

resolve(build);
});
Expand Down
88 changes: 44 additions & 44 deletions src/api/github-commit-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/api/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit a032e35

Please sign in to comment.