Skip to content

Commit

Permalink
refactor: Tiny changes due to eslint warnings / errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbo2002 committed Aug 3, 2024
1 parent d5ef430 commit e675505
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/bin/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class AppServer {
result = await this.states.getState(req.params.projectId, req.params.branch);
}
catch(error) {
this.badges.sendError(res, label);
this.badges.sendError(res, label, error);
return;
}

if (['running', 'pending'].indexOf(result.status) > -1) {
this.badges.send(res, label, status, 'lightgrey');
this.badges.send(res, label, result.status, 'lightgrey');
}
else if (result.status === 'success') {
this.badges.send(res, label, 'passing', 'brightgreen');
Expand All @@ -80,7 +80,7 @@ class AppServer {
result = await this.states.getState(req.params.projectId, req.params.branch);
}
catch(error) {
this.badges.sendError(res, label);
this.badges.sendError(res, label, error);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/badge-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export default class BadgeResponse {
res.send(badge);
}

sendError (res: Response, label: string, error?: string): void {
sendError (res: Response, label: string, error?: string | unknown): void {
this.sendBadge(res, makeBadge({
label,
message: error || 'error',
message: String(error) || 'error',
color: 'red',
style: this.style
}));
Expand Down
8 changes: 7 additions & 1 deletion src/lib/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class GitLabStateHelper {
throw new Error('Unexpected answer from GitLab.');
}

let error: unknown;
let cacheDuration = 5;
const result: Record<string, StateCachePipeline> = {};
await Promise.all(body.map(async pipeline => {
Expand All @@ -66,7 +67,8 @@ export default class GitLabStateHelper {
status: pipeline.status,
coverage: extendedPipeline.coverage || undefined
};
} catch (error) {
} catch (err) {
error = err;
result[pipeline.ref] = {
status: pipeline.status,
coverage: undefined
Expand All @@ -84,6 +86,10 @@ export default class GitLabStateHelper {
if (this.timeout) {
this.refreshNextState();
}

if (error) {
throw error;
}
}

protected refreshNextState (): void {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('States', function () {
describe('getState()', function() {
this.timeout(30000);
it('should work', projectId ? async function() {
const states = await new GitLabStateHelper();
const states = new GitLabStateHelper();

const result1 = await states.getState(projectId, 'develop');
assert.strictEqual(typeof result1.status, 'string');
Expand Down

0 comments on commit e675505

Please sign in to comment.