<commit_before>/* global describe before it */
var assert = require('power-assert')
var nock = require('nock')

var GithubClient = require('../lib/github-client.js')

describe('GithubClient', function () {
  before(function () {
    this.client = new GithubClient({
      owner: 'uiureo',
      repo: 'awesome-app',
      token: 'token',
      head: 'master',
      base: 'production'
    })
  })

  it('works', function () {
    assert(this.client.token === 'token')
  })

  describe('#prepareReleasePR()', function () {
    describe('when pr doesn\'t exist', function () {
      nock('https://api.github.com/')
        .post('/repos/uiureo/awesome-app/pulls')
        .reply(201, {
          number: 42
        })

      it('creates pr', function (done) {
        this.client.prepareReleasePR().then(function (pr) {
          assert(pr.number === 42)
          done()
        }).catch(done)
      })
    })

    describe('when pr already exists', function () {
      nock('https://api.github.com/')
        .post('/repos/uiureo/awesome-app/pulls')
        .reply(422)

      nock('https://api.github.com/')
        .get('/repos/uiureo/awesome-app/pulls')
        .query(true)
        .reply(200, [
          { number: 3, title: 'super big release' }
        ])

      it('returns the pr', function (done) {
        this.client.prepareReleasePR().then(function (pr) {
          assert(pr.number === 3)
          done()
        }).catch(done)
      })
    })
  })

  describe('#getPRCommits()', function () {
    var commitsEndpoint = '/repos/uiureo/awesome-app/pulls/42/commits?per_page=100'

    nock('https://api.github.com')
      .get(commitsEndpoint + '&page=1')
      .reply(200, [
        { sha: 'sha0' },
        { sha: 'sha1' }
      ], {
        Link: '<https://api.github.com/resource?page=2>; rel="next", <https://api.github.com/resource?page=2>; rel="last"'
      })
      .get(commitsEndpoint + '&page=2')
      .reply(200, [
        { sha: 'sha2' },
        { sha: 'sha3' }
      ])

    it('returns pr', function (done) {
      this.client.getPRCommits({ number: 42 }).then(function (commits) {
        assert(commits.length === 4)
        assert(commits[0].sha === 'sha0')

        done()
      }).catch(done)
    })
  })

  describe('#collectReleasePRs()', function () {
    nock('https://api.github.com')
      .get('/repos/uiureo/awesome-app/pulls/42/commits')
      .query(true)
      .reply(200, [
        { sha: '0' },
        { sha: '1' },
        { sha: '2' }
      ])
      .get('/repos/uiureo/awesome-app/pulls?state=closed&base=master&per_page=100')
      .reply(200, [
        { number: 10, head: { sha: '0' }, merged_at: null },
        { number: 1, head: { sha: '1' }, merged_at: 'a' },
        { number: 2, head: { sha: '2' }, merged_at: 'b' },
        { number: 100, head: { sha: '100' }, merged_at: 'c' }
      ])

    it('returns prs that is going to be released', function (done) {
      this.client.collectReleasePRs({ number: 42 })
        .then(function (prs) {
          assert(prs.length === 2)

          done()
        }).catch(done)
    })
  })
})<commit_msg>Add test for updatePR()<commit_after>/* global describe before it */
var assert = require('power-assert')
var nock = require('nock')

var GithubClient = require('../lib/github-client.js')

describe('GithubClient', function () {
  before(function () {
    this.client = new GithubClient({
      owner: 'uiureo',
      repo: 'awesome-app',
      token: 'token',
      head: 'master',
      base: 'production'
    })
  })

  it('works', function () {
    assert(this.client.token === 'token')
  })

  describe('#prepareReleasePR()', function () {
    describe('when pr doesn\'t exist', function () {
      nock('https://api.github.com/')
        .post('/repos/uiureo/awesome-app/pulls')
        .reply(201, {
          number: 42
        })

      it('creates pr', function (done) {
        this.client.prepareReleasePR().then(function (pr) {
          assert(pr.number === 42)
          done()
        }).catch(done)
      })
    })

    describe('when pr already exists', function () {
      nock('https://api.github.com/')
        .post('/repos/uiureo/awesome-app/pulls')
        .reply(422)

      nock('https://api.github.com/')
        .get('/repos/uiureo/awesome-app/pulls')
        .query(true)
        .reply(200, [
          { number: 3, title: 'super big release' }
        ])

      it('returns the pr', function (done) {
        this.client.prepareReleasePR().then(function (pr) {
          assert(pr.number === 3)
          done()
        }).catch(done)
      })
    })
  })

  describe('#getPRCommits()', function () {
    var commitsEndpoint = '/repos/uiureo/awesome-app/pulls/42/commits?per_page=100'

    nock('https://api.github.com')
      .get(commitsEndpoint + '&page=1')
      .reply(200, [
        { sha: 'sha0' },
        { sha: 'sha1' }
      ], {
        Link: '<https://api.github.com/resource?page=2>; rel="next", <https://api.github.com/resource?page=2>; rel="last"'
      })
      .get(commitsEndpoint + '&page=2')
      .reply(200, [
        { sha: 'sha2' },
        { sha: 'sha3' }
      ])

    it('returns pr', function (done) {
      this.client.getPRCommits({ number: 42 }).then(function (commits) {
        assert(commits.length === 4)
        assert(commits[0].sha === 'sha0')

        done()
      }).catch(done)
    })
  })

  describe('#collectReleasePRs()', function () {
    nock('https://api.github.com')
      .get('/repos/uiureo/awesome-app/pulls/42/commits')
      .query(true)
      .reply(200, [
        { sha: '0' },
        { sha: '1' },
        { sha: '2' }
      ])
      .get('/repos/uiureo/awesome-app/pulls?state=closed&base=master&per_page=100')
      .reply(200, [
        { number: 10, head: { sha: '0' }, merged_at: null },
        { number: 1, head: { sha: '1' }, merged_at: 'a' },
        { number: 2, head: { sha: '2' }, merged_at: 'b' },
        { number: 100, head: { sha: '100' }, merged_at: 'c' }
      ])

    it('returns prs that is going to be released', function (done) {
      this.client.collectReleasePRs({ number: 42 })
        .then(function (prs) {
          assert(prs.length === 2)

          done()
        }).catch(done)
    })
  })

  describe('#updatePR()', function () {
    nock('https://api.github.com/')
      .patch('/repos/uiureo/awesome-app/pulls/42')
      .reply(200, {
        title: 'updated',
        number: 42
      })

    it('updates a PR', function (done) {
      var pr = { number: 42 }
      this.client.updatePR(pr, { title: 'updated' }).then(function (pr) {
        assert(pr.title === 'updated')
        done()
      })
    })
  })
})
{'fraction_non_alphanumeric': 0.19424785423881946, 'fraction_numerical': 0.022135220599307334, 'mean_word_length': 2.134497404436055, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 15, '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': '6574225', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2235, 'n_words': 401}