<commit_before>#!/usr/bin/env node

var http = require('http')
var request = require('request')
var onjson = require('receive-json')
var minimist = require('minimist')
var crypto = require('crypto')
var after = require('after-all')

var argv = minimist(process.argv, {
  alias: {
    secret: 's',
    token: 't',
    port: 'p'
  }
})

if (!argv.secret) {
  console.error('--secret={webhook-secret} is required')
  process.exit(1)
}

if (!argv.token) {
  console.error('--token={github-token} is required')
  process.exit(1)
}

var CHAPTER_ORGANIZERS = 1660004
var verify = argv.verify !== false

request = request.defaults({
  auth: {
    username: 'x-oauth',
    password: <PASSWORD>
  },
  headers: {
    'User-Agent': 'nodeschoolbot'
  }
})

var help = '' +
  'Here is what I can do for you:\n' +
  '\n' +
  '* `help` - shows this help\n' +
  '* `create-repo {name}` - creates a nodeschool repo\n' +
  '* `add-user {username}` - adds a user to the `chapter-organizers` team and the org\n' +
  '* `create-team {team}` - creates a new team\n' +
  '* `add-team-user {team} {username}` - add a user to a specific team\n'

var server = http.createServer(function (req, res) {
  if (req.method === 'GET') {
    res.end('hello, i am the nodeschoolbot\n')
    return
  }

  var hmac = crypto.createHmac('sha1', argv.secret)

  req.setEncoding('utf-8')
  req.on('data', function (data) {
    hmac.update(data, 'utf-8') // gah weird defaults
  })

  onjson(req, function (err, body) {
    if (err) return res.end()
    if (verify && 'sha1=' + hmac.digest('hex') !== req.headers['x-hub-signature']) return res.end()

    var cmds = parseCommand(body.comment && body.comment.body)
    if (!cmds) return res.end()

    var from = body.sender && body.sender.login
    if (from === 'nodeschoolbot') return res.end()

    var added = []
    var repos = []
    var newTeams = []
    var addedteam = {}
    var emptyOk = false

    authenticate(function () {
      var next = after(format)
      cmds.forEach(function (cmd) {
        if (cmd.name === 'barrel-roll') {
          emptyOk = true
          comment(body, '![barrel-roll](https://i.chzbgr.com/maxW500/5816682496/h83DFAE3F/)', next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'create-repo') {
          repos.push(cmd.args[0])
          createRepository(cmd.args[0], next())
          return
        }

        var user
        var team

        if (cmd.args.length >= 1 && cmd.name === 'add-user') {
          user = stripAtSign(cmd.args[0])
          added.push(user)
          addUser(user, next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'create-team') {
          team = stripAtSign(cmd.args[0])
          newTeams.push(team)
          createTeam(team, next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'add-team-user') {
          team = stripAtSign(cmd.args[0])
          user = stripAtSign(cmd.args[1])

          if (!addedteam[team]) addedteam[team] = []
          addedteam[team].push(user)
          addTeamUser(team, user, body, next())
          return
        }
      })
    })

    function format (err) {
      if (err) return done(err)

      var msg = ''

      if (repos.length) {<commit_msg>add version command (#7)<commit_after>#!/usr/bin/env node

var http = require('http')
var request = require('request')
var onjson = require('receive-json')
var minimist = require('minimist')
var crypto = require('crypto')
var after = require('after-all')

var argv = minimist(process.argv, {
  alias: {
    secret: 's',
    token: 't',
    port: 'p'
  }
})

if (!argv.secret) {
  console.error('--secret={webhook-secret} is required')
  process.exit(1)
}

if (!argv.token) {
  console.error('--token={github-token} is required')
  process.exit(1)
}

var CHAPTER_ORGANIZERS = 1660004
var verify = argv.verify !== false

request = request.defaults({
  auth: {
    username: 'x-oauth',
    password: argv.<PASSWORD>
  },
  headers: {
    'User-Agent': 'nodeschoolbot'
  }
})

var help = '' +
  'Here is what I can do for you:\n' +
  '\n' +
  '* `help` - shows this help\n' +
  '* `create-repo {name}` - creates a nodeschool repo\n' +
  '* `add-user {username}` - adds a user to the `chapter-organizers` team and the org\n' +
  '* `create-team {team}` - creates a new team\n' +
  '* `add-team-user {team} {username}` - add a user to a specific team\n'

var version = require('./package.json').version

var server = http.createServer(function (req, res) {
  if (req.method === 'GET') {
    res.end('hello, i am the nodeschoolbot\n')
    return
  }

  var hmac = crypto.createHmac('sha1', argv.secret)

  req.setEncoding('utf-8')
  req.on('data', function (data) {
    hmac.update(data, 'utf-8') // gah weird defaults
  })

  onjson(req, function (err, body) {
    if (err) return res.end()
    if (verify && 'sha1=' + hmac.digest('hex') !== req.headers['x-hub-signature']) return res.end()

    var cmds = parseCommand(body.comment && body.comment.body)
    if (!cmds) return res.end()

    var from = body.sender && body.sender.login
    if (from === 'nodeschoolbot') return res.end()

    var added = []
    var repos = []
    var newTeams = []
    var addedteam = {}
    var emptyOk = false

    authenticate(function () {
      var next = after(format)
      cmds.forEach(function (cmd) {
        if (cmd.name === 'barrel-roll') {
          emptyOk = true
          comment(body, '![barrel-roll](https://i.chzbgr.com/maxW500/5816682496/h83DFAE3F/)', next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'create-repo') {
          repos.push(cmd.args[0])
          createRepository(cmd.args[0], next())
          return
        }

        var user
        var team

        if (cmd.args.length >= 1 && cmd.name === 'add-user') {
          user = stripAtSign(cmd.args[0])
          added.push(user)
          addUser(user, next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'create-team') {
          team = stripAtSign(cmd.args[0])
          newTeams.push(team)
          createTeam(team, next())
          return
        }

        if (cmd.args.length >= 1 && cmd.name === 'add-team-user') {
          team = stripAtSign(cmd.args[0])
          user = stripAtSign(cmd.args[1])

          if (!addedteam[team]) addedteam[team] = []
          addedteam[team].push(user)
          addTeamUser(team, user, body, next())
          return
        }

        if (cmd.name === 'version') {
          comment(body, version, next())
          return
        }
      })
    })

    function format (err) {
      if (err) return done(err)

      var msg = ''

      if (repos.length) {
{'fraction_non_alphanumeric': 0.16875559534467324, 'fraction_numerical': 0.011787526111608475, 'mean_word_length': 2.3515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '2568810', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2249, 'n_words': 527}