<commit_before>
'use strict';

const Express = require('express');
const Github = require('octop');
const Semver = require('semver');
const Promisify = require('es6-promisify');
const BodyParser = require('body-parser');
const Moo = require('./moo');

const comp = require('./comp').comp;
const summary = require('./comp').summary;
const debug = require('debug')('moo:service');
const app = Express();
const token = process.env.GITHUB_ACCESS_TOKEN;
const github = new Github({'token': token});

app.use(BodyParser.json());
app.post('/hook/github/push', function (req, res) {
  let currVersion;
  let currBackwards;
  let currBranch;
  let tags;
  const compares = [];
  const body = req.body;
  if (body.action !== 'synchronize') {
    return res.end();
  }
  const repo = github.getRepo(
    body.repository.owner.login, body.repository.name);

  debug('getting tags...');
  Promisify(repo.getTags)()
  .then(function (data) {
    tags = data;
    currBranch = body.pull_request.head.ref;

    debug('getting package.json')
    return Promisify(repo.read)(currBranch, 'package.json');
  })
  .then(function (data) {
    data = JSON.parse(data);
    currVersion = data.version;
    currBackwards = data.backwards;
    tags = refineTags(tags);
    
    debug('comparing tree...');
    console.log(tags);
    return compare(0);
  })
  .then(function (idx) {
    res.end();

    let prog;
    let text = '> this message is generated by SeanBot\n\n';
    const num = body.number;
    const username = body.pull_request.user.login;
    const backwards = tags[idx].version;
    
    // check if current backwards equal to setup backwards value.
    if (currBackwards === backwards) {
      prog = Promisify(repo.removeLabel)(num, 'compatible');
    } else {
      if (currBackwards > backwards) {
        text += `Current backwards: ${currBackwards},` +
          `suggest to use backwards: ${backwards}. `;
      } else {
        // if current is less than backwards, should notify
        // pr-or update it
        // TODO(Yorkie): create a status for this case?
        text += `Backwards is expired at ${currBackwards}, ` +
          `please @${username} upgrade it to ${backwards}. `;
      }
      // build summary
      const latest = tags[0].ref;
      const r = comp(compares[0].value, compares[idx].value);
      console.log(r, idx, compares);
      text += summary(r, backwards, latest, body.repository.html_url);
      console.log(text);
      // connect to Github, then comment and label
      // prog = Promise.all([
      //   Promisify(repo.comment)(num, text),
      //   Promisify(repo.addLabels)(num, 'compatible')
      // ]);
    }
    // prog.then(function () {
    //   console.log('commented done');
    // });
  })
  .catch(function (err) {<commit_msg>should add idx<commit_after>
'use strict';

const Express = require('express');
const Github = require('octop');
const Semver = require('semver');
const Promisify = require('es6-promisify');
const BodyParser = require('body-parser');
const Moo = require('./moo');

const comp = require('./comp').comp;
const summary = require('./comp').summary;
const debug = require('debug')('moo:service');
const app = Express();
const token = process.env.GITHUB_ACCESS_TOKEN;
const github = new Github({'token': token});

app.use(BodyParser.json());
app.post('/hook/github/push', function (req, res) {
  let currVersion;
  let currBackwards;
  let currBranch;
  let tags;
  const compares = [];
  const body = req.body;
  if (body.action !== 'synchronize') {
    return res.end();
  }
  const repo = github.getRepo(
    body.repository.owner.login, body.repository.name);

  debug('getting tags...');
  Promisify(repo.getTags)()
  .then(function (data) {
    tags = data;
    currBranch = body.pull_request.head.ref;

    debug('getting package.json')
    return Promisify(repo.read)(currBranch, 'package.json');
  })
  .then(function (data) {
    data = JSON.parse(data);
    currVersion = data.version;
    currBackwards = data.backwards;
    tags = refineTags(tags);
    
    debug('comparing tree...');
    console.log(tags);
    return compare(0);
  })
  .then(function (idx) {
    res.end();

    let prog;
    let text = '> this message is generated by SeanBot\n\n';
    const num = body.number;
    const username = body.pull_request.user.login;
    const backwards = tags[idx].version;
    
    // check if current backwards equal to setup backwards value.
    if (currBackwards === backwards) {
      prog = Promisify(repo.removeLabel)(num, 'compatible');
    } else {
      if (currBackwards > backwards) {
        text += `Current backwards: ${currBackwards},` +
          `suggest to use backwards: ${backwards}. `;
      } else {
        // if current is less than backwards, should notify
        // pr-or update it
        // TODO(Yorkie): create a status for this case?
        text += `Backwards is expired at ${currBackwards}, ` +
          `please @${username} upgrade it to ${backwards}. `;
      }
      // build summary
      const latest = tags[0].ref;
      const r = comp(compares[0].value, compares[idx + 1].value);
      console.log(r, idx, compares);
      text += summary(r, backwards, latest, body.repository.html_url);
      console.log(text);
      // connect to Github, then comment and label
      // prog = Promise.all([
      //   Promisify(repo.comment)(num, text),
      //   Promisify(repo.addLabels)(num, 'compatible')
      // ]);
    }
    // prog.then(function () {
    //   console.log('commented done');
    // });
  })
  .catch(function (err) {
{'fraction_non_alphanumeric': 0.1562443683546585, 'fraction_numerical': 0.0016219138583528565, 'mean_word_length': 2.9389638041163946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1821321', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1710, 'n_words': 433}