<commit_before>import {ACCEPTED, NO_CONTENT, BAD_REQUEST, UNSUPPORTED_MEDIA_TYPE} from 'http-status-codes';
import boom from 'boom';
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;
}

export default async function (request, responseToolkit, settings) {
  const {state, repository, branches, sha} = request.payload;
  const event = request.headers['x-github-event'];

  if ('ping' === event) {
    if ('json' !== request.payload.hook.config.content_type) {
      return responseToolkit
        .response('please update your webhook configuration to send application/json')
        .code(UNSUPPORTED_MEDIA_TYPE);
    }

    return responseToolkit.response('successfully configured the webhook for greenkeeper-keeper').code(NO_CONTENT);
  }

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

    return getPullRequestsForCommit({ref: sha})
      .then(async pullRequests => {
        if (!pullRequests.length) return responseToolkit.response('no PRs for this commit').code(BAD_REQUEST);

        if (1 < pullRequests.length) {
          return responseToolkit.response(boom.internal('too many PRs exist for this commit'));
        }
<commit_msg>chore(logs): added logging for reasons that the PR isnt correct<commit_after>import {ACCEPTED, NO_CONTENT, BAD_REQUEST, UNSUPPORTED_MEDIA_TYPE} from 'http-status-codes';
import boom from 'boom';
import openedByGreenkeeperBot from './greenkeeper';
import createActions from './github/actions';
import process from './process';

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) {
  const {state, repository, branches, sha} = request.payload;
  const event = request.headers['x-github-event'];

  if ('ping' === event) {
    if ('json' !== request.payload.hook.config.content_type) {
      return responseToolkit
        .response('please update your webhook configuration to send application/json')
        .code(UNSUPPORTED_MEDIA_TYPE);
    }

    return responseToolkit.response('successfully configured the webhook for greenkeeper-keeper').code(NO_CONTENT);
  }

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

    return getPullRequestsForCommit({ref: sha})
      .then(async pullRequests => {
        if (!pullRequests.length) return responseToolkit.response('no PRs for this commit').code(BAD_REQUEST);

        if (1 < pullRequests.length) {
          return responseToolkit.response(boom.internal('too many PRs exist for this commit'));
        }

{'fraction_non_alphanumeric': 0.13004613610149943, 'fraction_numerical': 0.002018454440599769, 'mean_word_length': 4.336923076923077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1250005', 'n_tokens_mistral': 996, 'n_tokens_neox': 988, 'n_words': 265}