Skip to content

Commit 8bb3136

Browse files
authored
Merge pull request #94 from pkgjs/branch-naming
2 parents 5e7f6d6 + 5da4f8c commit 8bb3136

15 files changed

+279
-18
lines changed

Diff for: lib/context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.getParentBranchName = async function getParentBranchName () {
1010
}
1111

1212
exports.getTestingBranchName = function getTestingBranchName (parentBranchName) {
13-
return `wiby-${parentBranchName}`
13+
return parentBranchName.startsWith('wiby-') ? parentBranchName : `wiby-${parentBranchName}`
1414
}
1515

1616
exports.getDependencyLink = async function getDependencyLink (owner, repo, commitish) {

Diff for: lib/result.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ const debug = logger('wiby:result')
99

1010
// enum containing possible pipeline checks statuses
1111
const pipelineStatusesEnum = module.exports.pipelineStatusesEnum = Object.freeze({
12+
// statuses returned by github
1213
FAILED: 'failure',
1314
QUEUED: 'queued',
1415
PENDING: 'pending',
15-
SUCCEED: 'success'
16+
SUCCEED: 'success',
17+
18+
// custom statuses
19+
MISSING: 'test branch missing'
1620
})
1721

1822
const PENDING_RESULT_EXIT_CODE = 64
@@ -36,6 +40,16 @@ module.exports = async function ({ dependents }) {
3640

3741
const parentBranchName = await context.getParentBranchName()
3842
const branch = await context.getTestingBranchName(parentBranchName)
43+
const exists = await github.getBranch(dependentPkgInfo.owner, dependentPkgInfo.name, branch)
44+
if (!exists) {
45+
output.results.push({
46+
dependent: `${dependentPkgInfo.owner}/${dependentPkgInfo.name}`,
47+
status: pipelineStatusesEnum.MISSING,
48+
runs: []
49+
})
50+
allDependentsChecks.push([undefined, pipelineStatusesEnum.MISSING])
51+
continue
52+
}
3953
let resp = await github.getChecks(dependentPkgInfo.owner, dependentPkgInfo.name, branch)
4054
if (resp.data.check_runs.length === 0) {
4155
resp = await github.getCommitStatusesForRef(dependentPkgInfo.owner, dependentPkgInfo.name, branch)
@@ -106,7 +120,8 @@ const getOverallStatusForAllRuns = module.exports.getOverallStatusForAllRuns = f
106120
// if includes null or pending or queued - overall status is pending
107121
if (statuses.includes(null) ||
108122
statuses.includes(pipelineStatusesEnum.PENDING) ||
109-
statuses.includes(pipelineStatusesEnum.QUEUED)
123+
statuses.includes(pipelineStatusesEnum.QUEUED) ||
124+
statuses.includes(pipelineStatusesEnum.MISSING)
110125
) {
111126
return pipelineStatusesEnum.PENDING
112127
}

Diff for: test/cli/result.js

+51-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const gitFixture = require('../fixtures/git')
1010
const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby')
1111
const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures'))
1212

13+
const SUCCESS_RESULT_EXIT_CODE = 0
14+
const FAIL_RESULT_EXIT_CODE = 1
1315
const PENDING_RESULT_EXIT_CODE = 64
1416

1517
tap.test('result command', async (tap) => {
@@ -37,20 +39,64 @@ tap.test('result command', async (tap) => {
3739
childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, {
3840
env: {
3941
...process.env,
40-
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js`
42+
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive-pass.js`
4143
}
4244
})
4345
} catch (e) {
4446
const result = e.output[1].toString().trim()
4547

4648
tap.equal(result, expected)
47-
tap.equal(e.status, PENDING_RESULT_EXIT_CODE)
49+
tap.equal(e.status, SUCCESS_RESULT_EXIT_CODE)
4850
}
4951
})
5052

5153
tap.test('result command should call result module with all deps from .wiby.json', async (tap) => {
5254
const expected = fs.readFileSync(
53-
path.join(__dirname, '..', 'fixtures', 'expected-outputs', 'result', 'result-output-multiple-dependant.md'),
55+
path.join(__dirname, '..', 'fixtures', 'expected-outputs', 'result', 'result-output-multiple-pass.md'),
56+
'utf-8'
57+
)
58+
.trim()
59+
60+
try {
61+
childProcess.execSync(`${wibyCommand} result`, {
62+
env: {
63+
...process.env,
64+
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive-pass.js`
65+
}
66+
})
67+
} catch (e) {
68+
const result = e.output[1].toString().trim()
69+
70+
tap.equal(result, expected)
71+
tap.equal(e.status, SUCCESS_RESULT_EXIT_CODE)
72+
}
73+
})
74+
75+
tap.test('result command should call result module with all deps from .wiby.json (pending result)', async (tap) => {
76+
const expected = fs.readFileSync(
77+
path.join(__dirname, '..', 'fixtures', 'expected-outputs', 'result', 'result-output-multiple-pending.md'),
78+
'utf-8'
79+
)
80+
.trim()
81+
82+
try {
83+
childProcess.execSync(`${wibyCommand} result`, {
84+
env: {
85+
...process.env,
86+
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive-pending.js`
87+
}
88+
})
89+
} catch (e) {
90+
const result = e.output[1].toString().trim()
91+
92+
tap.equal(result, expected)
93+
tap.equal(e.status, PENDING_RESULT_EXIT_CODE)
94+
}
95+
})
96+
97+
tap.test('result command should call result module with all deps from .wiby.json (missing branch result)', async (tap) => {
98+
const expected = fs.readFileSync(
99+
path.join(__dirname, '..', 'fixtures', 'expected-outputs', 'result', 'result-output-missing-branch.md'),
54100
'utf-8'
55101
)
56102
.trim()
@@ -59,7 +105,7 @@ tap.test('result command', async (tap) => {
59105
childProcess.execSync(`${wibyCommand} result`, {
60106
env: {
61107
...process.env,
62-
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js`
108+
NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-missing-branch.js`
63109
}
64110
})
65111
} catch (e) {
@@ -136,7 +182,7 @@ tap.test('result command', async (tap) => {
136182
const result = e.output[1].toString().trim()
137183

138184
tap.equal(result, expected)
139-
tap.equal(e.status, 1)
185+
tap.equal(e.status, FAIL_RESULT_EXIT_CODE)
140186
}
141187
})
142188
})

Diff for: test/cli/test.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby')
1010
const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures'))
1111

1212
tap.test('test command', async (tap) => {
13-
tap.beforeEach(async () => {
13+
tap.test('test command should fail when config and dependent provided', async (tap) => {
1414
gitFixture.init()
15-
})
1615

17-
tap.test('test command should fail when config and dependent provided', async (tap) => {
1816
try {
1917
childProcess.execSync(`${wibyCommand} test --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`).toString()
2018
tap.fail()
@@ -24,6 +22,8 @@ tap.test('test command', async (tap) => {
2422
})
2523

2624
tap.test('test command should call test module with dependent URI', async (tap) => {
25+
gitFixture.init()
26+
2727
const result = childProcess.execSync(`${wibyCommand} test --dependent="https://github.com/wiby-test/fakeRepo"`, {
2828
env: {
2929
...process.env,
@@ -35,6 +35,23 @@ tap.test('test command', async (tap) => {
3535
})
3636

3737
tap.test('test command should call test module with all deps from .wiby.json', async (tap) => {
38+
gitFixture.init()
39+
40+
const result = childProcess.execSync(`${wibyCommand} test`, {
41+
env: {
42+
...process.env,
43+
NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js`
44+
}
45+
}).toString()
46+
47+
tap.match(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-running-unit-tests/package.json')
48+
tap.match(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-running-unit-tests/package.json')
49+
tap.match(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-running-unit-tests/package.json')
50+
})
51+
52+
tap.test('test command should not add `wiby-` prefix when branch already has it', async (tap) => {
53+
gitFixture.init('wiby-running-unit-tests')
54+
3855
const result = childProcess.execSync(`${wibyCommand} test`, {
3956
env: {
4057
...process.env,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# wiby result command
2+
3+
Overall status - pending
4+
5+
## wiby-test/partial - success
6+
7+
Checks:
8+
9+
- partial_run - success
10+
- partial_run_2 - success
11+
12+
## wiby-test/fail - test branch missing
13+
14+
Checks:
15+
16+
## wiby-test/pass - success
17+
18+
Checks:
19+
20+
- pass_run - success
21+
- pass_run_2 - success
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# wiby result command
2+
3+
Overall status - success
4+
5+
## wiby-test/partial - success
6+
7+
Checks:
8+
9+
- partial_run - success
10+
- partial_run_2 - success
11+
12+
## wiby-test/fail - success
13+
14+
Checks:
15+
16+
- fail_run - success
17+
- fail_run_2 - success
18+
19+
## wiby-test/pass - success
20+
21+
Checks:
22+
23+
- pass_run - success
24+
- pass_run_2 - success

Diff for: test/fixtures/git.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ const fs = require('fs')
55
const path = require('path')
66
const tmp = require('tmp')
77

8-
exports.TEST_BRANCH_NAME = 'running-unit-tests'
9-
10-
exports.init = function () {
8+
exports.init = function (initialBranch = 'running-unit-tests') {
119
const gitRepoPath = path.join(__dirname, '..', '..')
1210

1311
const { name: tmpDir } = tmp.dirSync()
1412
process.chdir(tmpDir)
1513

16-
childProcess.execSync('git init --initial-branch=running-unit-tests')
14+
childProcess.execSync(`git init --initial-branch=${initialBranch}`)
1715
childProcess.execSync('git config user.email "wiby@example.com"')
1816
childProcess.execSync('git config user.name "Wiby Bot"')
1917

Diff for: test/fixtures/http/result-command-empty-branch-checks-flat.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ nock('https://api.github.com')
2323
}
2424
}
2525
})
26+
.get('/repos/wiby-test/fakeRepo/branches/wiby-running-unit-tests')
27+
.reply(200, {})
2628
// get check results
2729
.get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs')
2830
.reply(200, {

Diff for: test/fixtures/http/result-command-empty-branch-checks.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ nock('https://api.github.com')
2323
}
2424
}
2525
})
26+
.get('/repos/wiby-test/fakeRepo/branches/wiby-running-unit-tests')
27+
.reply(200, {})
2628
// get check results
2729
.get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs')
2830
.reply(200, {

Diff for: test/fixtures/http/result-command-missing-branch.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict'
2+
3+
/**
4+
* Mocks of HTTP calls for "wiby result" command positive flow
5+
*/
6+
const nock = require('nock')
7+
8+
nock.disableNetConnect()
9+
10+
nock('https://api.github.com')
11+
// get package json
12+
.post('/graphql')
13+
.times(3)
14+
.reply(200, {
15+
data: {
16+
repository: {
17+
object: {
18+
text: JSON.stringify({
19+
dependencies: {
20+
wiby: '*'
21+
}
22+
})
23+
}
24+
}
25+
}
26+
})
27+
.get('/repos/wiby-test/fakeRepo/branches/wiby-running-unit-tests')
28+
.reply(200, {})
29+
.get('/repos/wiby-test/partial/branches/wiby-running-unit-tests')
30+
.reply(200, {})
31+
.get('/repos/wiby-test/pass/branches/wiby-running-unit-tests')
32+
.reply(200, {})
33+
.get('/repos/wiby-test/fail/branches/wiby-running-unit-tests')
34+
.reply(404, {})
35+
// get check results
36+
.get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs')
37+
.reply(200, {
38+
check_runs: [
39+
{ status: 'done', name: 'fake_run', conclusion: 'success' },
40+
{ status: 'done', name: 'fake_run_2', conclusion: 'success' }
41+
]
42+
})
43+
.get('/repos/wiby-test/fail/commits/wiby-running-unit-tests/check-runs')
44+
.reply(200, {
45+
check_runs: [
46+
{ status: 'done', name: 'fail_run', conclusion: 'success' },
47+
{ status: 'done', name: 'fail_run_2', conclusion: 'success' }
48+
]
49+
})
50+
.get('/repos/wiby-test/pass/commits/wiby-running-unit-tests/check-runs')
51+
.reply(200, {
52+
check_runs: [
53+
{ status: 'done', name: 'pass_run', conclusion: 'success' },
54+
{ status: 'done', name: 'pass_run_2', conclusion: 'success' }
55+
]
56+
})
57+
.get('/repos/wiby-test/partial/commits/wiby-running-unit-tests/check-runs')
58+
.reply(200, {
59+
check_runs: [
60+
{ status: 'done', name: 'partial_run', conclusion: 'success' },
61+
{ status: 'done', name: 'partial_run_2', conclusion: 'success' }
62+
]
63+
})

Diff for: test/fixtures/http/result-command-positive-checks-failed.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ nock('https://api.github.com')
2525
}
2626
}
2727
})
28+
.get('/repos/wiby-test/fakeRepo/branches/wiby-running-unit-tests')
29+
.reply(200, {})
2830
// get check results
2931
.get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs')
3032
.reply(200, {

0 commit comments

Comments
 (0)