<commit_before>import Router from './router'

import { PullRequestEvent, PushEvent } from '../events'

export default class Bitbucket extends Router {
  constructor ({ token = '' }) {
    super(token, 'bitbucket')

    this.router.use('/:token/:appName', (req, res, next) => {
      if (token) {
        if (req.params.token && req.params.token === token) {
          next()
        } else {
          res.send(401)
        }
      } else {
        next()
      }
    })

    this.router.post('/:token/:appName', (req, res) => {
      // console.log(JSON.stringify(req.body, null, 4))
      if (req.body.repository) {
        if (req.body.push && req.body.push.changes && req.body.push.changes.length > 0 && req.body.push.changes[0].new.type === 'branch') {
          res.sendStatus(204)
          this.emit('push', new PushEvent(req.params.appName, req.body.repository.links.html.href, req.body.push.changes[0].new.name))
        } else if (req.body.pullrequest && req.body.pullrequest.title && req.body.pullrequest.description && req.body.pullrequest.source && req.body.pullrequest.destination) {
          res.sendStatus(204)
          this.emit('pull-request', new PullRequestEvent(req.params.appName, req.body.repository.links.html.href, req.body.pullrequest.source, req.body.pullrequest.destination, req.body.pullrequest.title, req.body.pullrequest.description))
        } else {
          res.sendStatus(400)
        }
      } else {
        res.sendStatus(400)
      }
    })

    this.router.post('*', (req, res) => {
      res.status(404).send('ko')
    })
  }
}<commit_msg>pull request<commit_after>import Router from './router'

import { PullRequestEvent, PushEvent } from '../events'

export default class Bitbucket extends Router {
  constructor ({ token = '' }) {
    super(token, 'bitbucket')

    this.router.use('/:token/:appName', (req, res, next) => {
      if (token) {
        if (req.params.token && req.params.token === token) {
          next()
        } else {
          res.send(401)
        }
      } else {
        next()
      }
    })

    this.router.post('/:token/:appName', (req, res) => {
      // console.log(JSON.stringify(req.body, null, 4))
      if (req.body.repository) {
        if (req.body.push && req.body.push.changes && req.body.push.changes.length > 0 && req.body.push.changes[0].new.type === 'branch') {
          res.sendStatus(204)
          this.emit('push', new PushEvent(req.params.appName, req.body.repository.links.html.href, req.body.push.changes[0].new.name))
        } else if (req.body.pullrequest && req.body.pullrequest.title && req.body.pullrequest.description && req.body.pullrequest.source && req.body.pullrequest.destination) {
          res.sendStatus(204)
          console.log('pull request')
          this.emit('pull-request', new PullRequestEvent(req.params.appName, req.body.repository.links.html.href, req.body.pullrequest.source, req.body.pullrequest.destination, req.body.pullrequest.title, req.body.pullrequest.description))
        } else {
          res.sendStatus(400)
        }
      } else {
        res.sendStatus(400)
      }
    })

    this.router.post('*', (req, res) => {
      res.status(404).send('ko')
    })
  }
}
{'fraction_non_alphanumeric': 0.16817472698907956, 'fraction_numerical': 0.013728549141965678, 'mean_word_length': 2.511500547645126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2456060', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1013, 'n_words': 161}