Skip to content

Commit

Permalink
fix(controller/github): include details of missing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Sep 16, 2020
1 parent 9e42b36 commit c9906e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 9 additions & 1 deletion docs/controller/github/approve-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ data:
- owner: ssube
project: isolex
authors:
# renovate-bot
- 'renovate[bot]'
- ssube
checks:
- app: codeclimate
conclusion: success
name: codeclimate
status: success
- app: codecov/patch
conclusion: success
name: codecov/patch
status: success
- app: codecov/project
conclusion: success
name: codecov/project
status: success
- app: gitlab/build
conclusion: success
name: gitlab/build
Expand Down
10 changes: 6 additions & 4 deletions src/controller/github/ApproveController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mustExist, mustFind } from '@apextoaster/js-utils';
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { isNil } from 'lodash';
import { Container } from 'noicejs';

Expand Down Expand Up @@ -79,7 +79,9 @@ export class GithubApproveController extends BaseController<GithubApproveControl
name: it.context,
status: it.state,
}));

const results = [...checks, ...statuses];
this.logger.debug({ results, options }, 'collected request results');

const projectData = this.data.projects.find((it) => it.owner === owner && it.project === project);
if (isNil(projectData)) {
Expand All @@ -92,18 +94,18 @@ export class GithubApproveController extends BaseController<GithubApproveControl
}

const checkStatus = projectData.checks.map((check) => {
const result = mustFind(results, (r) => r.app === check.app && r.name === check.name);
const result = results.find((r) => r.app === check.app && r.name === check.name);
return {
name: check.name,
status: check.conclusion === result.conclusion && check.status === result.status,
status: doesExist(result) && check.conclusion === result.conclusion && check.status === result.status,
};
});

if (checkStatus.every((cr) => cr.status)) {
return this.reply(ctx, 'all checks passed!');
} else {
const errors = checkStatus.filter((cr) => !cr.status);
return this.reply(ctx, `some checks failed:\n${JSON.stringify(errors)}`);
return this.reply(ctx, `some checks failed:\n\`${JSON.stringify(errors)}\``);
}
}
}

0 comments on commit c9906e6

Please sign in to comment.