Skip to content

Commit

Permalink
feat: raise PR
Browse files Browse the repository at this point in the history
PR should be raised against the default branch

this could be main. Next handle the case that the

feature branch is already there.
  • Loading branch information
ghinks committed May 19, 2021
1 parent 7cb66cb commit ff793cd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ module.exports.getWibyBranches = async function (owner, repo) {
return edges.map(({ node: { branchName } }) => branchName)
}

module.exports.getDefaultBranch = async function (owner, repo) {
const resp = await graphqlWithAuth({
query: queries.getDefaultBranch,
owner: owner,
repo: repo
})
return resp.repository.defaultBranchRef.name
}

module.exports.getShas = async function getShas (owner, repo) {
const resp = await octokit.repos.listCommits({
owner,
Expand Down
7 changes: 7 additions & 0 deletions lib/graphql/getDefaultBranch.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query getExistingRepoBranches($owner: String!, $repo: String!) {
repository(name: $repo, owner: $owner) {
defaultBranchRef {
name
}
}
}
2 changes: 2 additions & 0 deletions lib/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ const path = require('path')
exports.getPackageJson = fs.readFileSync(path.join(__dirname, 'getPackageJson.graphql')).toString()

exports.getWibyBranches = fs.readFileSync(path.join(__dirname, 'getWibyBranches.graphql')).toString()

exports.getDefaultBranch = fs.readFileSync(path.join(__dirname, 'getDefaultBranch.graphql')).toString()
3 changes: 2 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const createPR = module.exports.createPR = async function createPR (dependentOwn
`
const head = context.getTestingBranchName(parentBranchName)
const draft = true
const result = await github.createPR(dependentOwner, dependentRepo, title, head, parentBranchName, draft, body)
const defaultBranch = await github.getDefaultBranch(dependentOwner, dependentRepo)
const 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/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.test('test command', async (tap) => {
tap.only('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.test('test command', async (tap) => {
tap.match(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-running-unit-tests/package.json')
})

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

const result = childProcess.execSync(`${wibyCommand} test`, {
Expand Down
13 changes: 12 additions & 1 deletion test/fixtures/http/test-command-positive.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nock.disableNetConnect()
function nockPkgjsWiby (nockInstance) {
return nockInstance
// get package json
.post('/graphql')
.post('/graphql', body => !!body.query.match(/HEAD/g))
.times(3)
.reply(200, {
data: {
Expand All @@ -25,6 +25,17 @@ function nockPkgjsWiby (nockInstance) {
}
}
})
.post(/graphql/, body => !!body.query.match(/defaultBranchRef/g))
.times(3)
.reply(200, {
data: {
repository: {
defaultBranchRef: {
name: 'main'
}
}
}
})
// get commit sha
.get('/repos/pkgjs/wiby/commits?per_page=1')
.reply(200, [
Expand Down
15 changes: 13 additions & 2 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.test('wiby.test()', async (tap) => {
tap.only('wiby.test()', async (tap) => {
tap.beforeEach(async () => {
nock.disableNetConnect()
gitFixture.init()
Expand Down Expand Up @@ -97,8 +97,19 @@ tap.test('wiby.test()', async (tap) => {
)
tap.end()
})
tap.test('test create PR', (t) => {
tap.only('test create PR', (t) => {
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, {
Expand Down

0 comments on commit ff793cd

Please sign in to comment.