Skip to content

Commit

Permalink
feat: clean PR
Browse files Browse the repository at this point in the history
add small amount of text output for success case with the intent of adding proper processing next.
  • Loading branch information
ghinks committed Apr 18, 2021
1 parent c6138ce commit b07d4a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
13 changes: 8 additions & 5 deletions bin/commands/close-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ exports.builder = (yargs) => yargs
type: 'string',
conflicts: 'config'
})
.option('pull-request', {
desc: 'Raise a draft PR in addition to creating a branch',
.option('close-pr', {
desc: 'Close a PR of a dependent raised in test',
alias: 'pr',
type: 'boolean',
conflicts: 'config'
Expand All @@ -21,12 +21,15 @@ exports.builder = (yargs) => yargs
type: 'string'
})

exports.handler = (params) => {
exports.handler = async (params) => {
const config = params.dependent
? {
dependents: [{ repository: params.dependent, pullRequest: !!params['pull-request'] }]
dependents: [{ repository: params.dependent, pullRequest: true }]
}
: wiby.validate({ config: params.config })

return wiby.closePR(config)
const result = await wiby.closePR(config)
const output = `${result.length} PRs closed`
console.log(output)
return output
}
37 changes: 27 additions & 10 deletions test/cli/closePR.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict'
/*
const tap = require('tap')
const gitFixture = require('../fixtures/git')
const childProcess = require('child_process')
Expand All @@ -10,18 +9,36 @@ const fs = require('fs')
const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby')
const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures'))

tap.test('closePRs command', async (tap) => {
tap.beforeEach(async () => {
tap.only('closePRs command', async (t) => {
t.beforeEach(async () => {
nock.disableNetConnect()
gitFixture.init()
})
tap.afterEach(async () => {
nock.cleanAll()
nock.enableNetConnect()
})
tap.test('close PRs should result in a successful outcome', async (t) => {

t.test('close-pr should fail if config and dependent provided', async (t) => {
try {
childProcess.execSync(`${wibyCommand} close-pr --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`)
tap.fail()
} catch (err) {
tap.equal(true, err.message.includes('Arguments dependent and config are mutually exclusive'))
}
})
t.test('close-pr should call and close the PR on command with dependent argument', async (t) => {
const result = childProcess.execSync(`${wibyCommand} close-pr --dependent="https://github.com/wiby-test/fakeRepo"`, {
env: {
...process.env,
NODE_OPTIONS: `-r ${fixturesPath}/http/close-pr-command-positive.js`
}
}).toString()
t.match(result, '1 PRs closed\n')
})
t.only('close-pr should call and close the PR on command using wiby.json settings', async (t) => {
const result = childProcess.execSync(`${wibyCommand} close-pr`, {
env: {
...process.env,
NODE_OPTIONS: `-r ${fixturesPath}/http/close-pr-command-positive.js`
}
}).toString()
t.match(result, '1 PRs closed\n')
})
tap.end()
})
*/
9 changes: 5 additions & 4 deletions test/fixtures/http/close-pr-command-positive.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nock.disableNetConnect()
function nockRepo (nockInstance, owner, repo, branch) {
return nockInstance
// /repos/{owner}/{repo}/commits/{ref}/check-runs
.get(`repos/${owner}/${repo}/commits/${branch}/check-runs`)
.get(`/repos/${owner}/${repo}/commits/${branch}/check-runs`)
.reply(200, {
check_runs: [
{
Expand All @@ -32,7 +32,8 @@ function nockRepo (nockInstance, owner, repo, branch) {
}
]
})
.patch(/repos.*pulls\/1/)
// /repos/{owner}/{repo}/pulls/{pull_number}
.patch(`/repos/${owner}/${repo}/pulls/1`)
.reply(200, {
state: 'closed',
title: 'wiby test pr'
Expand All @@ -42,8 +43,8 @@ function nockRepo (nockInstance, owner, repo, branch) {
function buildNock () {
let nockInstance = nock('https://api.github.com')

nockInstance = nockRepo(nockInstance, 'fakeRepo')

nockInstance = nockRepo(nockInstance, 'wiby-test', 'fakeRepo', 'wiby-running-unit-tests')
nockInstance = nockRepo(nockInstance, 'wiby-test', 'pass', 'wiby-running-unit-tests')
return nockInstance
}

Expand Down

0 comments on commit b07d4a7

Please sign in to comment.