How to use github.pulls.create method in Cypress

Best JavaScript code snippet using cypress

pull.test.js

Source:pull.test.js Github

copy

Full Screen

1/* eslint-env node, jest */2process.env.LOG_LEVEL = 'fatal'3const { Application } = require('probot')4const Pull = require('../lib/pull')5const helper = require('../lib/helper')6let app7let github8beforeEach(() => {9  app = new Application()10  // Mock out the GitHub API11  github = {12    repos: {13      compareCommits: jest.fn()14    },15    pulls: {16      create: jest.fn(),17      get: jest.fn(),18      createReviewRequest: jest.fn(),19      merge: jest.fn()20    },21    issues: {22      update: jest.fn(),23      listForRepo: jest.fn(),24      createLabel: jest.fn()25    },26    git: {27      updateRef: jest.fn()28    }29  }30  // Mock out GitHub client31  app.auth = () => Promise.resolve(github)32  // TODO33  // app.log = console34})35const goodConfig = {36  version: '1',37  rules: [38    {39      base: 'master',40      upstream: 'upstream:master',41      mergeMethod: 'none',42      assignees: [],43      reviewers: [],44      conflictReviewers: []45    },46    {47      base: 'feature/new-1',48      upstream: 'upstream:dev',49      mergeMethod: 'rebase',50      assignees: ['tom'],51      reviewers: ['jerry', 'org/team-1'],52      conflictReviewers: ['spike']53    },54    {55      base: 'hotfix/bug-1',56      upstream: 'upstream:dev',57      mergeMethod: 'hardreset',58      assignees: ['wei'],59      reviewers: ['wei'],60      conflictReviewers: ['saurabh702']61    }62  ],63  label: 'pull',64  conflictLabel: 'merge-conflict'65}66const getPull = () => new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, goodConfig)67describe('pull - routineCheck', () => {68  test('bad config', async () => {69    try {70      new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log })  // eslint-disable-line71      throw Error('Should throw error and go to catch')72    } catch (e) {73      expect(e.message).toEqual('Invalid config')74    }75  })76  test('logger fall back to console', async () => {77    const pull = new Pull(github, { owner: 'wei', repo: 'fork' }, goodConfig)78    expect(pull.logger).toBe(console)79  })80  test('same branch', async () => {81    const configs = [82      { version: '1', rules: [{ base: 'master', upstream: 'master' }] },83      { version: '1', rules: [{ base: 'master', upstream: 'wei:master' }] }84    ]85    for (let i = 0; i < configs.length; i++) {86      const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, configs[i])87      await pull.routineCheck()88      expect(github.repos.compareCommits).not.toHaveBeenCalled()89      expect(github.issues.listForRepo).not.toHaveBeenCalled()90      expect(github.pulls.create).not.toHaveBeenCalled()91      expect(github.issues.update).not.toHaveBeenCalled()92    }93  })94  test('no diff', async () => {95    github.repos.compareCommits.mockResolvedValue({ data: { total_commits: 0 } })96    const pull = getPull()97    await pull.routineCheck()98    expect(github.repos.compareCommits).nthCalledWith(1, {99      owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'100    })101    expect(github.repos.compareCommits).nthCalledWith(3, {102      owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'103    })104    expect(github.repos.compareCommits).nthCalledWith(2, {105      owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'106    })107    expect(github.issues.listForRepo).not.toHaveBeenCalled()108    expect(github.pulls.create).not.toHaveBeenCalled()109    expect(github.issues.update).not.toHaveBeenCalled()110  })111  test('diff too large', async () => {112    github.repos.compareCommits.mockImplementation(() => { throw Error('Server Error: Sorry, this diff is taking too long to generate.') })113    github.issues.listForRepo.mockResolvedValue({ data: [] })114    github.pulls.create.mockResolvedValue({115      data: {116        number: 12,117        base: { ref: 'master' },118        head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder-12' },119        state: 'open',120        user: { login: 'pull[bot]' },121        mergeable: true,122        mergeable_state: 'clean'123      }124    })125    const pull = getPull()126    await pull.routineCheck()127    expect(github.repos.compareCommits.mock.calls.length).toBe(3)128    expect(github.issues.listForRepo).toHaveBeenCalled()129    expect(github.pulls.create).toHaveBeenCalled()130    expect(github.issues.update).toHaveBeenCalled()131  })132  test('diff not found', async () => {133    github.repos.compareCommits.mockImplementation(() => { throw Error('Not Found') })134    const pull = getPull()135    await pull.routineCheck()136    expect(github.repos.compareCommits.mock.calls.length).toBe(3)137    expect(github.issues.listForRepo).not.toHaveBeenCalled()138    expect(github.pulls.create).not.toHaveBeenCalled()139    expect(github.issues.update).not.toHaveBeenCalled()140  })141  test('diff no common ancestor', async () => {142    github.repos.compareCommits.mockImplementation(() => { throw Error('No common ancestor between --- and ---:---') })143    const pull = getPull()144    await pull.routineCheck()145    expect(github.repos.compareCommits.mock.calls.length).toBe(3)146    expect(github.issues.listForRepo).not.toHaveBeenCalled()147    expect(github.pulls.create).not.toHaveBeenCalled()148    expect(github.issues.update).not.toHaveBeenCalled()149  })150  test('diff other error', async () => {151    github.repos.compareCommits.mockImplementation(() => { throw Error('Internal Server Error') })152    const pull = getPull()153    await pull.routineCheck()154    expect(github.repos.compareCommits.mock.calls.length).toBe(3)155    expect(github.issues.listForRepo).not.toHaveBeenCalled()156    expect(github.pulls.create).not.toHaveBeenCalled()157    expect(github.issues.update).not.toHaveBeenCalled()158  })159  test('yes diff, already has PR', async () => {160    github.repos.compareCommits.mockResolvedValue({ data: { total_commits: 1 } })161    github.issues.listForRepo.mockResolvedValue({ data: [{ number: 13 }, { number: 12 }, { number: 14 }] })162    github.pulls.get.mockImplementation(({ pull_number: number }) => {163      switch (number) {164        case 12:165          return {166            data: {167              number: 12,168              base: { ref: 'master', label: 'wei:master' },169              head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder-12' },170              state: 'open',171              user: { login: 'pull[bot]' },172              mergeable: true,173              rebaseable: true,174              mergeable_state: 'clean'175            }176          }177        case 13:178          return {179            data: {180              number: 13,181              base: { ref: 'feature/new-1', label: 'wei:feature/new-1' },182              head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder-13' },183              state: 'open',184              user: { login: 'pull[bot]' },185              mergeable: true,186              rebaseable: true,187              mergeable_state: 'clean'188            }189          }190        case 14:191          return {192            data: {193              number: 14,194              base: { ref: 'hotfix/bug-1', label: 'wei:hotfix/bug-1' },195              head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder-14' },196              state: 'open',197              user: { login: 'pull[bot]' },198              mergeable: true,199              rebaseable: true,200              mergeable_state: 'clean'201            }202          }203        default:204          return { data: null }205      }206    })207    const pull = getPull()208    await pull.routineCheck()209    expect(github.repos.compareCommits).nthCalledWith(1, {210      owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'211    })212    expect(github.issues.listForRepo).toHaveBeenCalled()213    expect(github.pulls.get).nthCalledWith(1, { owner: 'wei', repo: 'fork', pull_number: 13 })214    expect(github.pulls.get).nthCalledWith(2, { owner: 'wei', repo: 'fork', pull_number: 12 })215    expect(github.pulls.merge).not.toHaveBeenCalledWith()216    expect(github.repos.compareCommits).nthCalledWith(2, {217      owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'218    })219    expect(github.issues.listForRepo).toHaveBeenCalled()220    expect(github.pulls.get).nthCalledWith(3, { owner: 'wei', repo: 'fork', pull_number: 13 })221    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 13, merge_method: 'rebase' })222    expect(github.repos.compareCommits).nthCalledWith(3, {223      owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'224    })225    expect(github.issues.listForRepo).toHaveBeenCalled()226    expect(github.pulls.get).nthCalledWith(4, { owner: 'wei', repo: 'fork', pull_number: 13 })227    expect(github.pulls.get).nthCalledWith(5, { owner: 'wei', repo: 'fork', pull_number: 12 })228    expect(github.pulls.get).nthCalledWith(6, { owner: 'wei', repo: 'fork', pull_number: 14 })229    expect(github.git.updateRef).toHaveBeenCalledWith(230      { owner: 'wei', repo: 'fork', ref: 'heads/hotfix/bug-1', sha: 'sha1-placeholder-14', force: true }231    )232    expect(github.pulls.create).not.toHaveBeenCalled()233    expect(github.issues.update).not.toHaveBeenCalled()234  })235  test('yes diff, no PR, create PR', async () => {236    github.repos.compareCommits.mockResolvedValue({ data: { total_commits: 1 } })237    github.issues.listForRepo238      .mockResolvedValueOnce({ data: [{ number: 10 }] })239      .mockResolvedValueOnce({ data: [] })240      .mockResolvedValueOnce({ data: [] })241    github.pulls.get.mockResolvedValueOnce({242      data: {243        number: 10,244        base: { ref: 'master', label: 'wei:master' },245        head: { ref: 'master', label: 'upstream:master', sha: 'sha1-placeholder' },246        state: 'open',247        user: { login: 'pull[bot]' },248        mergeable: true,249        rebaseable: true,250        mergeable_state: 'clean'251      }252    })253    github.pulls.create254      .mockResolvedValueOnce({ data: { number: 12 } })255      .mockImplementationOnce(() => { throw Error({ code: 512 }) })256    const pull = getPull()257    await pull.routineCheck()258    expect(github.repos.compareCommits).nthCalledWith(1, {259      owner: 'wei', repo: 'fork', base: 'master', head: 'upstream%3Amaster'260    })261    expect(github.repos.compareCommits).nthCalledWith(2, {262      owner: 'wei', repo: 'fork', base: 'feature%2Fnew-1', head: 'upstream%3Adev'263    })264    expect(github.repos.compareCommits).nthCalledWith(3, {265      owner: 'wei', repo: 'fork', base: 'hotfix%2Fbug-1', head: 'upstream%3Adev'266    })267    expect(github.issues.listForRepo).toHaveBeenCalledTimes(3)268    expect(github.pulls.create).toHaveBeenCalledTimes(2)269    expect(github.pulls.create).nthCalledWith(1, {270      owner: 'wei', repo: 'fork', base: 'feature/new-1', head: 'upstream:dev', maintainer_can_modify: false, title: helper.getPRTitle('feature/new-1', 'upstream:dev'), body: helper.getPRBody('wei/fork')271    })272    expect(github.pulls.create).nthCalledWith(2, {273      owner: 'wei', repo: 'fork', base: 'hotfix/bug-1', head: 'upstream:dev', maintainer_can_modify: false, title: helper.getPRTitle('hotfix/bug-1', 'upstream:dev'), body: helper.getPRBody('wei/fork')274    })275    expect(github.issues.update).toHaveBeenCalledTimes(1)276    expect(github.issues.update).nthCalledWith(1, {277      owner: 'wei', repo: 'fork', issue_number: 12, assignees: ['tom'], labels: ['pull'], body: helper.getPRBody('wei/fork', 12)278    })279    expect(github.pulls.createReviewRequest).toHaveBeenCalledTimes(1)280    expect(github.pulls.createReviewRequest).nthCalledWith(1, {281      owner: 'wei', repo: 'fork', pull_number: 12, reviewers: ['jerry'], team_reviewers: ['team-1']282    })283  })284})285describe('pull - checkAutoMerge', () => {286  test('bad parameters', async () => {287    const pull = getPull()288    expect(await pull.checkAutoMerge()).toBeNull()289  })290  test('should honor autoMerge flag', async () => {291    const pull = getPull()292    await pull.checkAutoMerge({293      number: 10,294      base: { ref: 'master', label: 'wei:master' },295      head: { ref: 'master', label: 'upstream:master' },296      state: 'open',297      user: { login: 'pull[bot]' },298      mergeable: true,299      rebaseable: true,300      mergeable_state: 'clean'301    })302    expect(github.pulls.get).not.toHaveBeenCalled()303    expect(github.git.updateRef).not.toHaveBeenCalled()304    github.pulls.get305      .mockResolvedValueOnce({ data: { mergeable: null, mergeable_state: 'unknown' } })306      .mockResolvedValueOnce({ data: { mergeable: true, mergeable_state: 'clean' } })307    await pull.checkAutoMerge({308      number: 12,309      base: { ref: 'feature/new-1' },310      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },311      state: 'open',312      user: { login: 'pull[bot]' },313      mergeable: null,314      rebaseable: false,315      mergeable_state: 'unknown'316    })317    expect(github.pulls.get).toHaveBeenCalledTimes(2)318    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12 })319    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12, merge_method: 'merge' })320    expect(github.git.updateRef).not.toHaveBeenCalled()321  })322  test('should honor autoMerge flag with hardreset', async () => {323    const pull = getPull()324    github.pulls.get = jest.fn()325      .mockResolvedValueOnce({ data: { mergeable: null, mergeable_state: 'unknown' } })326      .mockResolvedValueOnce({ data: { mergeable: true, mergeable_state: 'clean' } })327    github.pulls.merge = jest.fn()328    await pull.checkAutoMerge({329      number: 16,330      base: { ref: 'hotfix/bug-1' },331      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },332      state: 'open',333      user: { login: 'pull[bot]' },334      mergeable: null,335      mergeable_state: 'unknown'336    })337    expect(github.pulls.get).toHaveBeenCalledTimes(2)338    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16 })339    expect(github.pulls.merge).not.toHaveBeenCalled()340    expect(github.git.updateRef).toHaveBeenCalledWith(341      { owner: 'wei', repo: 'fork', ref: 'heads/hotfix/bug-1', sha: 'sha1-placeholder', force: true }342    )343  })344  test('should not merge if mergeablity is null', async () => {345    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: null, mergeable_state: 'unknown' } })346    const pull = getPull()347    await pull.checkAutoMerge({348      number: 12,349      base: { ref: 'feature/new-1' },350      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },351      state: 'open',352      user: { login: 'pull[bot]' },353      mergeable: null,354      rebaseable: false,355      mergeable_state: 'unknown'356    }, { isMergeableMaxRetries: 1 })357    expect(github.pulls.get).toHaveBeenCalledTimes(1)358    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12 })359    expect(github.git.updateRef).not.toHaveBeenCalled()360  })361  test('should assign conflict reviewer if mergeablity is false', async () => {362    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: false } })363    const pull = getPull()364    await pull.checkAutoMerge({365      number: 12,366      base: { ref: 'feature/new-1' },367      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },368      state: 'open',369      user: { login: 'pull[bot]' },370      mergeable: false371    }, { conflictReviewers: ['wei', 'saurabh702'] })372    try {373      expect(github.issues.getLabel).toHaveBeenCalledTimes(1)374    } catch (e) {375      expect(pull.addLabel(pull.config.conflictLabel, 'ff0000', 'Resolve conflicts manually')).resolves.not.toBeNull()376    }377    expect(github.issues.update).toHaveBeenCalledTimes(1)378    expect(pull.addReviewers(12, ['wei', 'saurabh702'])).resolves.not.toBeNull()379  })380  test('should not merge if mergeable_status is dirty', async () => {381    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: null, rebaseable: false, mergeable_state: 'unknown' } })382    setTimeout(() => {383      github.pulls.get.mockResolvedValue({ data: { mergeable: false, rebaseable: false, mergeable_state: 'dirty' } })384    }, 500)385    const pull = getPull()386    await pull.checkAutoMerge({387      number: 12,388      base: { ref: 'feature/new-1' },389      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },390      state: 'open',391      user: { login: 'pull[bot]' },392      mergeable: null,393      mergeable_state: 'unknown'394    }, { isMergeableMaxRetries: 2 })395    expect(github.pulls.get).toHaveBeenCalledTimes(2)396    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12 })397    expect(github.git.updateRef).not.toHaveBeenCalled()398  })399  test('should merge if mergeable_status is unstable and mergeUnstable flag is set to true', async () => {400    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: false, mergeable_state: 'clean' } })401    const config = { version: '1', rules: [{ base: 'dev', upstream: 'master', mergeMethod: 'merge', mergeUnstable: true }] }402    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, config)403    await pull.checkAutoMerge({404      number: 12,405      base: { ref: 'dev' },406      head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },407      state: 'open',408      user: { login: 'pull[bot]' },409      mergeable: true,410      rebaseable: false,411      mergeable_state: 'unstable'412    })413    expect(github.pulls.get).toHaveBeenCalledTimes(0)414    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12, merge_method: 'merge' })415    expect(github.git.updateRef).not.toHaveBeenCalled()416  })417  test('hard reset failed', async () => {418    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })419    github.git.updateRef.mockRejectedValue(new Error('Update reference failed'))420    const pull = getPull()421    await pull.checkAutoMerge({422      number: 12,423      base: { ref: 'hotfix/bug-1' },424      head: { ref: 'dev', label: 'upstream:dev', sha: 'sha1-placeholder' },425      state: 'open',426      user: { login: 'pull[bot]' },427      mergeable: null,428      rebaseable: false,429      mergeable_state: 'unknown'430    })431    expect(github.pulls.get).toHaveBeenCalledTimes(1)432    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 12 })433    expect(github.git.updateRef).toHaveBeenCalledWith(434      { owner: 'wei', repo: 'fork', ref: 'heads/hotfix/bug-1', sha: 'sha1-placeholder', force: true }435    )436  })437  test('should handle same repo auto merge with method: merge', async () => {438    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })439    const config = { version: '1', rules: [{ base: 'dev', upstream: 'master', mergeMethod: 'merge' }] }440    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, config)441    await pull.checkAutoMerge({442      number: 16,443      base: { ref: 'dev' },444      head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },445      state: 'open',446      user: { login: 'pull[bot]' },447      mergeable: null,448      rebaseable: false,449      mergeable_state: 'unknown'450    })451    expect(github.pulls.get).toHaveBeenCalledTimes(1)452    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16 })453    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16, merge_method: 'merge' })454    expect(github.git.updateRef).not.toHaveBeenCalled()455  })456  test('should handle same repo auto merge with method: squash', async () => {457    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })458    const config = { version: '1', rules: [{ base: 'dev', upstream: 'master', mergeMethod: 'squash' }] }459    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, config)460    await pull.checkAutoMerge({461      number: 16,462      base: { ref: 'dev' },463      head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },464      state: 'open',465      user: { login: 'pull[bot]' },466      mergeable: null,467      rebaseable: false,468      mergeable_state: 'unknown'469    })470    expect(github.pulls.get).toHaveBeenCalledTimes(1)471    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16 })472    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16, merge_method: 'squash' })473    expect(github.git.updateRef).not.toHaveBeenCalled()474  })475  test('should handle same repo auto merge with method: rebase', async () => {476    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })477    const config = { version: '1', rules: [{ base: 'dev', upstream: 'master', mergeMethod: 'rebase' }] }478    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, config)479    await pull.checkAutoMerge({480      number: 16,481      base: { ref: 'dev' },482      head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },483      state: 'open',484      user: { login: 'pull[bot]' },485      mergeable: null,486      rebaseable: false,487      mergeable_state: 'unknown'488    })489    expect(github.pulls.get).toHaveBeenCalledTimes(1)490    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16 })491    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16, merge_method: 'rebase' })492    expect(github.git.updateRef).not.toHaveBeenCalled()493  })494  test('should handle same repo auto merge with method: rebase failover to merge', async () => {495    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: false, mergeable_state: 'clean' } })496    const config = { version: '1', rules: [{ base: 'dev', upstream: 'master', mergeMethod: 'rebase' }] }497    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, config)498    await pull.checkAutoMerge({499      number: 16,500      base: { ref: 'dev' },501      head: { ref: 'master', label: 'wei:master', sha: 'sha1-placeholder' },502      state: 'open',503      user: { login: 'pull[bot]' },504      mergeable: null,505      rebaseable: false,506      mergeable_state: 'unknown'507    })508    expect(github.pulls.get).toHaveBeenCalledTimes(1)509    expect(github.pulls.get).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16 })510    expect(github.pulls.merge).toHaveBeenCalledWith({ owner: 'wei', repo: 'fork', pull_number: 16, merge_method: 'merge' })511    expect(github.git.updateRef).not.toHaveBeenCalled()512  })513})514describe('pull - misc', () => {515  test('functions with bad parameters', async () => {516    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })517    const pull = getPull()518    await pull.isMergeable(12)519    expect(github.pulls.get).toHaveBeenCalledTimes(1)520    await expect(pull.addReviewers()).resolves.toBeNull()521    await expect(pull.addReviewers(12)).resolves.toBeNull()522    await expect(pull.addReviewers(12, [])).resolves.toBeNull()523    await expect(pull.addLabel()).resolves.toBeNull()524    await expect(pull.mergePR()).resolves.toBeNull()525    await expect(pull.mergePR(12)).resolves.not.toBeNull()526    await expect(pull.hardResetCommit()).resolves.toBeNull()527    await expect(pull.hardResetCommit('master')).resolves.toBeNull()528    await expect(pull.hardResetCommit('', 'sha1-placeholder')).resolves.toBeNull()529  })530  test('Deprecated config support: autoMerge and autoMergeHardReset', async () => {531    github.pulls.get.mockResolvedValueOnce({ data: { mergeable: true, rebaseable: true, mergeable_state: 'clean' } })532    const pull = new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }, {533      version: '1',534      rules: [535        {536          base: 'feature/new-1',537          upstream: 'upstream:dev',538          autoMerge: true,539          assignees: ['tom'],540          reviewers: ['jerry'],541          conflictReviewers: ['spike']542        },543        {544          base: 'hotfix/bug-1',545          upstream: 'upstream:dev',546          autoMerge: true,547          autoMergeHardReset: true,548          assignees: ['wei'],549          reviewers: ['wei'],550          conflictReviewers: ['saurabh702']551        }552      ],553      label: 'pull',554      conflictLabel: 'merge-conflict'555    })556    expect(pull.config.rules[0].mergeMethod).toBe('merge')557    expect(pull.config.rules[1].mergeMethod).toBe('hardreset')558  })...

Full Screen

Full Screen

github.test.js

Source:github.test.js Github

copy

Full Screen

...95    it('should deny a pull request to an adobe repo', async () => {96      const setup = createBranch(github, user, ADOBE_REPO, newBranch);97      await setup();98      console.log(`Creating pull request to adobe/${ADOBE_REPO}...`);99      const pr = await github.pulls.create({100        owner: 'adobe',101        repo: ADOBE_REPO,102        title: `testing build ${newBranch}`,103        head: `${user}:${newBranch}`,104        base: 'master'105      });106      const suite = await waitForCheck(github, 'adobe', ADOBE_REPO, pr.data.head.sha);107      expect(suite.conclusion).not.toEqual('success');108      const teardown = deleteBranch(github, user, ADOBE_REPO, newBranch);109      await teardown();110    });111    it('should deny a pull request to a magento repo', async () => {112      const setup = createBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);113      await setup();114      console.log(`Creating pull request to magento/${PUBLIC_MAGENTO_REPO}...`);115      const pr = await github.pulls.create({116        owner: 'magento',117        repo: PUBLIC_MAGENTO_REPO,118        title: `testing build ${newBranch}`,119        head: `${user}:${newBranch}`,120        base: 'master'121      });122      const suite = await waitForCheck(github, 'magento', PUBLIC_MAGENTO_REPO, pr.data.head.sha);123      expect(suite.conclusion).not.toEqual('success');124      const teardown = deleteBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);125      await teardown();126    });127  });128  describe('pull requests from user with a signed Adobe ICLA (account adobeiotest1)', () => {129    const user = 'adobeiotest1';130    const newBranch = '' + new Date().valueOf();131    const github = new Octokit({132      auth: process.env.TEST_ONE_PAC133    });134    it('should approve a pull request to an adobe repo', async () => {135      const setup = createBranch(github, user, ADOBE_REPO, newBranch);136      await setup();137      console.log(`Creating pull request to adobe/${ADOBE_REPO}...`);138      const pr = await github.pulls.create({139        owner: 'adobe',140        repo: ADOBE_REPO,141        title: `testing build ${newBranch}`,142        head: `${user}:${newBranch}`,143        base: 'master'144      });145      const suite = await waitForCheck(github, 'adobe', ADOBE_REPO, pr.data.head.sha);146      expect(suite.conclusion).toEqual('success');147      const teardown = deleteBranch(github, user, ADOBE_REPO, newBranch);148      await teardown();149    });150    it('should approve a pull request to a public magento repo', async () => {151      const setup = createBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);152      await setup();153      console.log(`Creating pull request to magento/${PUBLIC_MAGENTO_REPO}...`);154      const pr = await github.pulls.create({155        owner: 'magento',156        repo: PUBLIC_MAGENTO_REPO,157        title: `testing build ${newBranch}`,158        head: `${user}:${newBranch}`,159        base: 'master'160      });161      const suite = await waitForCheck(github, 'magento', PUBLIC_MAGENTO_REPO, pr.data.head.sha);162      expect(suite.conclusion).toEqual('success');163      const teardown = deleteBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);164      await teardown();165    });166  });167  describe('pull requests from user with a signed Adobe CCLA (account adobeiotest2)', () => {168    const user = 'adobeiotest2';169    const newBranch = '' + new Date().valueOf();170    const github = new Octokit({171      auth: process.env.TEST_TWO_PAC172    });173    it('should approve a pull request to an adobe repo', async () => {174      const setup = createBranch(github, user, ADOBE_REPO, newBranch);175      await setup();176      console.log(`Creating pull request to adobe/${ADOBE_REPO}...`);177      const pr = await github.pulls.create({178        owner: 'adobe',179        repo: ADOBE_REPO,180        title: `testing build ${newBranch}`,181        head: `${user}:${newBranch}`,182        base: 'master'183      });184      const suite = await waitForCheck(github, 'adobe', ADOBE_REPO, pr.data.head.sha);185      expect(suite.conclusion).toEqual('success');186      const teardown = deleteBranch(github, user, ADOBE_REPO, newBranch);187      await teardown();188    });189    it('should approve a pull request to a public magento repo', async () => {190      const setup = createBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);191      await setup();192      console.log(`Creating pull request to magento/${PUBLIC_MAGENTO_REPO}...`);193      const pr = await github.pulls.create({194        owner: 'magento',195        repo: PUBLIC_MAGENTO_REPO,196        title: `testing build ${newBranch}`,197        head: `${user}:${newBranch}`,198        base: 'master'199      });200      const suite = await waitForCheck(github, 'magento', PUBLIC_MAGENTO_REPO, pr.data.head.sha);201      expect(suite.conclusion).toEqual('success');202      const teardown = deleteBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);203      await teardown();204    });205  });206  describe('pull requests from a user who is a member of the magento org but not the magento-employees team and with no signed CLAs (account MajTest583)', () => {207    const user = 'MajTest583';208    const newBranch = '' + new Date().valueOf();209    const github = new Octokit({210      auth: process.env.TEST_MAJ583_PAC211    });212    it('should deny a pull request to a public magento repo', async () => {213      const setup = createBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);214      await setup();215      console.log(`Creating pull request to magento/${PUBLIC_MAGENTO_REPO}...`);216      const pr = await github.pulls.create({217        owner: 'magento',218        repo: PUBLIC_MAGENTO_REPO,219        title: `testing build ${newBranch}`,220        head: `${user}:${newBranch}`,221        base: 'master'222      });223      const suite = await waitForCheck(github, 'magento', PUBLIC_MAGENTO_REPO, pr.data.head.sha);224      expect(suite.conclusion).not.toEqual('success');225      const teardown = deleteBranch(github, user, PUBLIC_MAGENTO_REPO, newBranch);226      await teardown();227    });228    it('should deny a pull request to a private magento repo', async () => {229      const setup = createBranch(github, user, PRIVATE_MAGENTO_REPO, newBranch);230      await setup();231      console.log(`Creating pull request to magento/${PRIVATE_MAGENTO_REPO}...`);232      const pr = await github.pulls.create({233        owner: 'magento',234        repo: PRIVATE_MAGENTO_REPO,235        title: `testing build ${newBranch}`,236        head: `${user}:${newBranch}`,237        base: 'master'238      });239      const suite = await waitForCheck(github, 'magento', PRIVATE_MAGENTO_REPO, pr.data.head.sha);240      expect(suite.conclusion).not.toEqual('success');241      const teardown = deleteBranch(github, user, PRIVATE_MAGENTO_REPO, newBranch);242      await teardown();243    });244  });...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1const AutoAssigner = require('..');2describe('auto-assign', () => {3	let aa;4	beforeEach(() => (aa = new AutoAssigner()));5	it('should have a run method', () => {6		expect(typeof aa.run).toBe('function');7	});8	describe('run', () => {9		it('should resolve users and assign them', async () => {10			const users = new Set(['tero.testaaja']);11			aa.options.assign = true;12			jest.spyOn(aa, 'resolveUsers').mockResolvedValueOnce(users);13			const assignSpy = jest.spyOn(aa, 'assign').mockResolvedValueOnce({});14			await aa.run();15			expect(assignSpy).toHaveBeenCalledWith(users);16		});17		it('should resolve users and request revies from them', async () => {18			const users = new Set(['tero.testaaja']);19			aa.options.review = true;20			jest.spyOn(aa, 'resolveUsers').mockResolvedValueOnce(users);21			const assignSpy = jest.spyOn(aa, 'requestReview').mockResolvedValueOnce({});22			await aa.run();23			expect(assignSpy).toHaveBeenCalledWith(users);24		});25	});26	describe('requestReview', () => {27		it('should call github api with a reviewer', async () => {28			const reviewSpy = jest29				.spyOn(aa.tools.github.pulls, 'createReviewRequest')30				.mockResolvedValueOnce({});31			await aa.requestReview(new Set(['tero.testaaja']));32			expect(reviewSpy).toHaveBeenCalledWith({33				number: 2,34				owner: 'granodigital',35				repo: 'grano-github-actions',36				reviewers: ['tero.testaaja'],37				team_reviewers: undefined38			});39		});40		it('should call github api with a team', async () => {41			const reviewSpy = jest42				.spyOn(aa.tools.github.pulls, 'createReviewRequest')43				.mockResolvedValueOnce({});44			aa.options.team = 'ecommerce-developers';45			await aa.requestReview(new Set([]));46			expect(reviewSpy).toHaveBeenCalledWith({47				number: 2,48				owner: 'granodigital',49				repo: 'grano-github-actions',50				reviewers: [],51				team_reviewers: ['ecommerce-developers']52			});53		});54		it('should not call api if no reviewers', async () => {55			const reviewSpy = jest56				.spyOn(aa.tools.github.pulls, 'createReviewRequest')57				.mockResolvedValueOnce({});58			await aa.requestReview(new Set([]));59			expect(reviewSpy).not.toHaveBeenCalled();60		});61	});62	describe('assign', () => {63		it('should call github api with assignee', async () => {64			const assignSpy = jest65				.spyOn(aa.tools.github.issues, 'addAssignees')66				.mockResolvedValueOnce({});67			await aa.assign(new Set(['tero.testaaja']));68			expect(assignSpy).toHaveBeenCalledWith({69				assignees: ['tero.testaaja'],70				number: 2,71				owner: 'granodigital',72				repo: 'grano-github-actions'73			});74		});75		it('should not call api if no reviewers', async () => {76			const assignSpy = jest77				.spyOn(aa.tools.github.issues, 'addAssignees')78				.mockResolvedValueOnce({});79			await aa.assign(new Set([]));80			expect(assignSpy).not.toHaveBeenCalled();81		});82	});83	describe('resolveUsers', () => {84		it('should return users from the command line options', async () => {85			aa.options.user = 'test';86			let users = await aa.resolveUsers();87			expect(users).toEqual(new Set(['test']));88			aa.options.user = ['test', 'test2'];89			users = await aa.resolveUsers();90			expect(users).toEqual(new Set(['test', 'test2']));91		});92		it('should determine repo contributors', async () => {93			jest.spyOn(aa, 'getContributors').mockResolvedValueOnce(['test', 'test2']);94			aa.options.contributors = true;95			let users = await aa.resolveUsers();96			expect(users).toEqual(new Set(['test', 'test2']));97		});98		it('should get team members if not requesting review', async () => {99			aa.options.review = false;100			aa.options.team = 'test-team';101			jest.spyOn(aa, 'getTeamMembers').mockResolvedValueOnce(['test', 'test2']);102			let users = await aa.resolveUsers();103			expect(users).toEqual(new Set(['test', 'test2']));104		});105		it('should not get team members if requesting review', async () => {106			aa.options.review = true;107			aa.options.team = 'test-team';108			jest.spyOn(aa, 'getTeamMembers').mockResolvedValueOnce(['test', 'test2']);109			let users = await aa.resolveUsers();110			expect(users).toEqual(new Set([]));111		});112		it('should remove actor from the results (the person opening the PR/issue)', async () => {113			aa.options.user = ['test', 'granoecom'];114			let users = await aa.resolveUsers();115			expect(users).toEqual(new Set(['test']));116		});117	});118	describe('getTeamMembers', () => {119		it('should get a list of members from a team', async () => {120			aa.options.team = 'ecommerce-developers';121			const users = await aa.getTeamMembers();122			expect([...users]).toEqual(123				expect.arrayContaining([124					'villelahdenvuo',125					'laxu',126					'Hallian',127					'nicou',128					'juhosuominen'129				])130			);131		});132		it('should handle multiple teams', async () => {133			aa.options.team = ['ecommerce-developers', 'test'];134			jest.spyOn(aa.tools.github.teams, 'getByName')135				.mockResolvedValueOnce({ data: { id: 1 } })136				.mockResolvedValueOnce({ data: { id: 2 } });137			jest.spyOn(aa.tools.github.teams, 'listMembers')138				.mockResolvedValueOnce({ data: [{ login: 'foo' }, { login: 'bar' }] })139				.mockResolvedValueOnce({ data: [{ login: 'bar' }, { login: 'baz' }] });140			const users = await aa.getTeamMembers();141			expect([...users]).toEqual(expect.arrayContaining(['foo', 'bar', 'baz']));142		});143	});...

Full Screen

Full Screen

review.test.js

Source:review.test.js Github

copy

Full Screen

1const { askToReview } = require("../src/lib/review");2jest.mock("../src/lib/utils");3const { getChangedFiles: getChangedFilesMock } = require("../src/lib/utils");4const reviewers = {5  default: ["default1", "default2", "login"],6  review: [7    { paths: ["test/**", "cmd/**"], reviewers: ["rw-a", "rw-b"] },8    { paths: ["packg/**"], reviewers: ["rw-c", "rw-d"] },9    { paths: ["packg2/**"], reviewers: ["rw-e", "login"] }10  ]11};12test("askToReview default reviewers", async () => {13  // Arrange14  const context = createContext(reviewers);15  const diff_url = "whatever";16  getChangedFilesMock.mockImplementationOnce(diff =>17    diff === diff_url ? ["otherfolder/file-a"] : undefined18  );19  // Act20  await askToReview(context, diff_url, context.payload.pull_request.user.login);21  // Assert22  expect(context.issue.mock.calls.length).toBe(1);23  expect(context.issue.mock.calls[0][0]).toStrictEqual({24    reviewers: ["default1", "default2"]25  });26  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);27  expect(28    context.github.pulls.createReviewRequest.mock.calls[0][0]29  ).toStrictEqual("issue");30});31test("askToReview reviewer one file existing in path but the other", async () => {32  // Arrange33  const context = createContext(reviewers);34  const diff_url = "whatever";35  getChangedFilesMock.mockImplementationOnce(diff =>36    diff === diff_url ? ["test/file-a", "filex"] : undefined37  );38  // Act39  await askToReview(context, diff_url, context.payload.pull_request.user.login);40  // Assert41  expect(context.issue.mock.calls.length).toBe(1);42  expect(context.issue.mock.calls[0][0]).toStrictEqual({43    reviewers: ["rw-a", "rw-b"]44  });45  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);46  expect(47    context.github.pulls.createReviewRequest.mock.calls[0][0]48  ).toStrictEqual("issue");49});50test("askToReview reviewer both files existing in path ", async () => {51  // Arrange52  const context = createContext(reviewers);53  const diff_url = "whatever";54  getChangedFilesMock.mockImplementationOnce(diff =>55    diff === diff_url ? ["test/file-a", "cmd/filex"] : undefined56  );57  // Act58  await askToReview(context, diff_url, context.payload.pull_request.user.login);59  // Assert60  expect(context.issue.mock.calls.length).toBe(1);61  expect(context.issue.mock.calls[0][0]).toStrictEqual({62    reviewers: ["rw-a", "rw-b"]63  });64  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);65  expect(66    context.github.pulls.createReviewRequest.mock.calls[0][0]67  ).toStrictEqual("issue");68});69test("askToReview reviewer both files existing in different paths", async () => {70  // Arrange71  const context = createContext(reviewers);72  const diff_url = "whatever";73  getChangedFilesMock.mockImplementationOnce(diff =>74    diff === diff_url ? ["test/file-a", "packg/filex"] : undefined75  );76  // Act77  await askToReview(context, diff_url, context.payload.pull_request.user.login);78  // Assert79  expect(context.issue.mock.calls.length).toBe(1);80  expect(context.issue.mock.calls[0][0]).toStrictEqual({81    reviewers: ["rw-a", "rw-b", "rw-c", "rw-d"]82  });83  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);84  expect(85    context.github.pulls.createReviewRequest.mock.calls[0][0]86  ).toStrictEqual("issue");87});88test("askToReview reviewer login", async () => {89  // Arrange90  const context = createContext(reviewers);91  const diff_url = "whatever";92  getChangedFilesMock.mockImplementationOnce(diff =>93    diff === diff_url ? ["packg2/filex"] : undefined94  );95  // Act96  await askToReview(context, diff_url, context.payload.pull_request.user.login);97  // Assert98  expect(context.issue.mock.calls.length).toBe(1);99  expect(context.issue.mock.calls[0][0]).toStrictEqual({100    reviewers: ["rw-e"]101  });102  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);103  expect(104    context.github.pulls.createReviewRequest.mock.calls[0][0]105  ).toStrictEqual("issue");106});107test("askToReview only default reviewers are present", async () => {108  //arrange109  const reviewrs = {110    default: ["default1", "default2", "login"]111  };112  const context = createContext(reviewrs);113  const diff_url = "whatever";114  getChangedFilesMock.mockImplementationOnce(diff =>115    diff === diff_url ? ["anydir/anyfile"] : undefined116  );117  // Act118  await askToReview(context, diff_url, context.payload.pull_request.user.login);119  // Assert120  expect(context.issue.mock.calls.length).toBe(1);121  expect(context.issue.mock.calls[0][0]).toStrictEqual({122    reviewers: ["default1", "default2"]123  });124  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1);125  expect(126    context.github.pulls.createReviewRequest.mock.calls[0][0]127  ).toStrictEqual("issue");128});129function createContext(reviewers) {130  return {131    config: jest.fn(path =>132      path === "bot-files/reviewers.yml" ? reviewers : undefined133    ),134    github: { pulls: { createReviewRequest: jest.fn(() => "toreview") } },135    issue: jest.fn(() => "issue"),136    payload: { pull_request: { user: { login: "login" } } }137  };...

Full Screen

Full Screen

create-release-pull-request.js

Source:create-release-pull-request.js Github

copy

Full Screen

...70};71// PRをmaster, developに出す72const createPullRequest = async (github, {owner, repo, head, body, version}) => {73  // to master74  const resultPullsCreateToMaster = await github.pulls.create({75    owner,76    repo,77    head,78    base: 'master',79    title: `Merge release branch ${version} to master`,80    body,81    draft: true,82  });83  // to develop84  await github.pulls.create({85    owner,86    repo,87    head,88    base: 'develop',89    title: `Merge release branch ${version} to develop`,90    body: `## Relation\n#${resultPullsCreateToMaster.data.number}\n${body}`,91    draft: true,92  });...

Full Screen

Full Screen

github.js

Source:github.js Github

copy

Full Screen

...89      branch: head,90      file,91    });92  }93  const { data } = await github.pulls.create({94    owner,95    repo,96    title,97    body,98    head,99    base,100  });101  console.log('opened pull request', data.number);102  return data;103}104async function createReviewRequest(github, {105  owner, repo, pull_number, reviewers,106}) {107  console.log('createReviewRequest', owner, repo, pull_number, reviewers);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const getConfig = require('probot-config');2const cooltime = {};3const alerted = [];4module.exports = app => {5  app.on(6    [7      'pull_request.labeled',8      'pull_request.ready_for_review',9      'pull_request.synchronize',10      'pull_request.reopened'11    ],12    async context => {13      if (14        context.payload.pull_request.draft ||15        context.payload.pull_request.merged16      )17        return;18      const repo = context.repo();19      const name =20        repo.owner +21        '/' +22        repo.repo +23        '#' +24        context.payload.pull_request.number;25      // check all labels26      const labels = context.payload.pull_request.labels.map(27        label => label.name28      );29      // find the config30      const config = await getConfig(context, 'auto-merge-bot.config.yml');31      if (!config) {32        app.log('[CONFIG IS NOT FOUND]', name);33        return;34      }35      let isExist = false;36      config.labels.forEach(label => {37        if (Array.isArray(label)) {38          const result = label.every(value => labels.indexOf(value) !== -1);39          if (result) isExist = true;40        } else {41          if (labels.indexOf(label) !== -1) isExist = true;42        }43      });44      if (!isExist) return;45      if (context.payload.pull_request.mergeable === false) {46        if (alerted.indexOf(name) === -1) {47          alerted.push(name);48          const commentData = context.repo({49            pull_number: context.payload.pull_request.number,50            body:51              "This pull request is subject to auto-merge, but is not mergeable. I'll execute it when it is ready to merge.",52            event: 'COMMENT'53          });54          return await context.github.pulls.createReview(commentData);55        }56        return;57      }58      const timeStamp = Math.floor(new Date().getTime() / 1000);59      if (cooltime[name] && timeStamp - cooltime[name] < 10) {60        cooltime[name] = timeStamp;61        app.log('[COOL TIME]', name);62        return;63      }64      cooltime[name] = timeStamp;65      // Approve the pull request66      const reviewData = context.repo({67        pull_number: context.payload.pull_request.number,68        body: '*This review was created by auto-merge bot.*',69        event: 'APPROVE'70      });71      await context.github.pulls.createReview(reviewData);72      try {73        // Merge it74        await context.github.pulls.merge(75          context.repo({76            pull_number: context.payload.pull_request.number,77            merge_method: config.merge_type || 'merge'78          })79        );80      } catch (e) {81        app.log(e);82        if (alerted.indexOf(name) === -1) {83          alerted.push(name);84          const commentData = context.repo({85            pull_number: context.payload.pull_request.number,86            body:87              "Failed to merge this pull request. It's not be mergeable or there is something wrong. I'll merge when it becomes possible to merge.",88            event: 'COMMENT'89          });90          return await context.github.pulls.createReview(commentData);91        }92        return;93      }94      // Delete the branch95      if (!config.delete_branch || config.delete_branch !== 'delete') return;96      return await context.github.git.deleteRef(97        context.repo({98          ref: 'heads/' + context.payload.pull_request.head.ref99        })100      );101    }102  );...

Full Screen

Full Screen

request_review.test.js

Source:request_review.test.js Github

copy

Full Screen

1const RequestReview = require('../../../lib/actions/request_review')2const Helper = require('../../../__fixtures__/unit/helper')3const settings = {4  reviewers: ['shine2lay']5}6let result = {7  status: 'pass',8  validations: [{9    status: 'pass',10    name: 'Label'11  }]12}13test('check that user is requested a review if user is an collaborator', async () => {14  const requester = new RequestReview()15  const options = {16    collaborators: [{login: 'shine2lay'}]17  }18  const context = createMockContext(options)19  await requester.afterValidate(context, settings, result)20  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(1)21  expect(context.github.pulls.createReviewRequest.mock.calls[0][0].reviewers[0]).toBe('shine2lay')22})23test('that requested Reviewers are not requested again', async () => {24  const requester = new RequestReview()25  const options = {26    requestedReviewers: [{login: 'shine2lay'}]27  }28  const context = createMockContext(options)29  await requester.afterValidate(context, settings, result)30  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(0)31})32test('that non collaborator is not requested reviews', async () => {33  const requester = new RequestReview()34  const options = {35    collaborators: []36  }37  const context = createMockContext(options)38  await requester.afterValidate(context, settings, result)39  expect(context.github.pulls.createReviewRequest.mock.calls.length).toBe(0)40})41const createMockContext = (options) => {42  let context = Helper.mockContext(options)43  context.github.pulls.createReviewRequest = jest.fn()44  return context...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const github = require('@cypress/github')2const cypress = require('cypress')3const fs = require('fs')4const path = require('path')5const os = require('os')6const util = require('util')7const exec = util.promisify(require('child_process').exec)8const rimraf = util.promisify(require('rimraf'))9const mkdirp = util.promisify(require('mkdirp'))10const chalk = require('chalk')11const ora = require('ora')12const moment = require('moment')13const _ = require('lodash')14const inquirer = require('inquirer')15const dotenv = require('dotenv')16const dotenvExpand = require('dotenv-expand')17const axios = require('axios')18const fetch = require('node-fetch')19const yaml = require('js-yaml')

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful