Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
chore(logs): added logging for reasons that the PR isnt correct
Browse files Browse the repository at this point in the history
another step toward better responses for #12
  • Loading branch information
travi committed Sep 21, 2018
1 parent 43ac56e commit d7cedf3
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@ import openedByGreenkeeperBot from './greenkeeper';
import createActions from './github/actions';
import process from './process';

function successfulStatusCouldBeForGreenkeeperPR(event, state, branches) {
return 'status' === event && 'success' === state && 1 === branches.length && 'master' !== branches[0].name;
function successfulStatusCouldBeForGreenkeeperPR(event, state, branches, log) {
if ('status' !== event) {
log(['PR', 'event was not `status`']);
return false;
}

if ('success' !== state) {
log(['PR', 'state was not `success`']);
return false;
}

if (1 !== branches.length) {
log(['PR', `expected 1 branch, but found ${branches.length}`]);
return false;
}

if ('master' === branches[0].name) {
log(['PR', 'branch name should not be `master`']);
return false;
}

return true;
}

export default async function (request, responseToolkit, settings) {
Expand All @@ -22,7 +42,7 @@ export default async function (request, responseToolkit, settings) {
return responseToolkit.response('successfully configured the webhook for greenkeeper-keeper').code(NO_CONTENT);
}

if (successfulStatusCouldBeForGreenkeeperPR(event, state, branches)) {
if (successfulStatusCouldBeForGreenkeeperPR(event, state, branches, (...args) => request.log(...args))) {
const {getPullRequestsForCommit, getPullRequest} = createActions(settings.github);

return getPullRequestsForCommit({ref: sha})
Expand Down

0 comments on commit d7cedf3

Please sign in to comment.