Skip to content

Commit

Permalink
feat: raise PR
Browse files Browse the repository at this point in the history
test that the parent branch exists or not in the dependent.

If the dependency parent branch exists in the dependent use that
branch and raise a PR of wiby-feature-x into feature-x rather than into the default branch.
  • Loading branch information
ghinks committed May 22, 2021
1 parent 0a980e9 commit 4bf337b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
16 changes: 14 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,20 @@ const createPR = module.exports.createPR = async function createPR (dependentOwn
`
const head = context.getTestingBranchName(parentBranchName)
const draft = true
const defaultBranch = await github.getDefaultBranch(dependentOwner, dependentRepo)
const result = await github.createPR(dependentOwner, dependentRepo, title, head, defaultBranch, draft, body)
/*
from the conversation on wiby PR 93 https://github.com/pkgjs/wiby/pull/93#discussion_r615362448
it was seen that the raising of a PR from head to main was in general ok but in the case where the
dependency feature branch does exist in the dependent then maybe detection and handle would offer a
better experience.
*/
const preExistingOnDependent = await github.getBranch(dependentOwner, dependentRepo, parentBranchName)
let result
if (preExistingOnDependent) {
result = await github.createPR(dependentOwner, dependentRepo, title, head, parentBranchName, draft, body)
} else {
const defaultBranch = await github.getDefaultBranch(dependentOwner, dependentRepo)
result = await github.createPR(dependentOwner, dependentRepo, title, head, defaultBranch, draft, body)
}
debug(`PR raised upon ${result.data.html_url}`)
return result
}
4 changes: 2 additions & 2 deletions test/cli/closePR.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const path = require('path')
const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby')
const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures'))

tap.only('closePRs command', async (t) => {
tap.test('closePRs command', async (t) => {
t.beforeEach(async () => {
nock.disableNetConnect()
gitFixture.init()
Expand All @@ -31,7 +31,7 @@ tap.only('closePRs command', async (t) => {
}).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) => {
t.test('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,
Expand Down
4 changes: 2 additions & 2 deletions test/cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const gitFixture = require('../fixtures/git')
const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby')
const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures'))

tap.only('test command', async (tap) => {
tap.test('test command', async (tap) => {
tap.test('test command should fail when config and dependent provided', async (tap) => {
gitFixture.init()

Expand All @@ -34,7 +34,7 @@ tap.only('test command', async (tap) => {
tap.match(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-running-unit-tests/package.json')
})

tap.only('test command should call test module with all deps from .wiby.json', async (tap) => {
tap.test('test command should call test module with all deps from .wiby.json', async (tap) => {
gitFixture.init()

const result = childProcess.execSync(`${wibyCommand} test`, {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/http/test-command-positive.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function nockPkgjsWiby (nockInstance) {
}
}
])
.get('/repos/wiby-test/pass/branches/wiby-running-unit-tests')
.reply(404, {})
}

function nockRepo (nockInstance, repo) {
Expand Down Expand Up @@ -87,6 +89,10 @@ function nockRepo (nockInstance, repo) {
.reply(201, {
html_url: 'https://github.com/pkgjs/wiby/pull/1'
})
.get('/repos/wiby-test/pass/branches/running-unit-tests')
.reply(200, {
name: 'running-unit-tests'
})
}

function buildNock () {
Expand Down
76 changes: 53 additions & 23 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const gitFixture = require('./fixtures/git')

const wiby = require('..')

tap.only('wiby.test()', async (tap) => {
tap.test('wiby.test()', async (tap) => {
tap.beforeEach(async () => {
nock.disableNetConnect()
gitFixture.init()
Expand Down Expand Up @@ -97,31 +97,61 @@ tap.only('wiby.test()', async (tap) => {
)
tap.end()
})
tap.only('test create PR', (t) => {
tap.test('Create PR', (tap) => {
tap.plan(2)
const htmlURL = `https://github.com/${CONFIG.PKG_ORG}/${CONFIG.DEP_REPO}/pull/1`
nock('https://api.github.com')
.post(/graphql/)
.reply(200, {
data: {
repository: {
defaultBranchRef: {
name: 'main'
}
}
}
})
nock('https://api.github.com')
.post('/repos/pkgjs/wiby/pulls')
.reply(201, {
html_url: htmlURL
})
const dependentOwner = 'pkgjs'
const dependentRepo = 'wiby'
const parentBranchName = 'main'
wiby.test.createPR(dependentOwner, dependentRepo, parentBranchName)
.then((result) => {
t.equal(result.data.html_url, htmlURL)
t.end()
})
tap.test('test create PR when dependency feature branch does not exist in dependent repo', (t) => {
nock('https://api.github.com')
.post('/repos/pkgjs/wiby/pulls')
.reply(201, {
html_url: htmlURL
})
.post(/graphql/)
.reply(200, {
data: {
repository: {
defaultBranchRef: {
name: 'main'
}
}
}
})
.get(/repos/)
.reply(404, {})
wiby.test.createPR(dependentOwner, dependentRepo, parentBranchName)
.then((result) => {
t.equal(result.data.html_url, htmlURL)
t.end()
})
})
tap.test('test create PR when dependency feature branch exists in dependent repo', (t) => {
nock('https://api.github.com')
.post('/repos/pkgjs/wiby/pulls')
.reply(201, {
html_url: htmlURL
})
.post(/graphql/)
.reply(200, {
data: {
repository: {
defaultBranchRef: {
name: 'main'
}
}
}
})
.get(/repos/)
.reply(200, {
name: parentBranchName
})
wiby.test.createPR(dependentOwner, dependentRepo, parentBranchName)
.then((result) => {
t.equal(result.data.html_url, htmlURL)
t.end()
})
})
})
})

0 comments on commit 4bf337b

Please sign in to comment.