Skip to content

Commit f2035a5

Browse files
mcasimiraddaleax
andauthored
chore: check for release ticket on release start (#3473)
* chore: check for release ticket on release start * Update packages/compass/release/jira.js Co-authored-by: Anna Henningsen <[email protected]> * update function call * fix tests * Update packages/compass/release/commands.js Co-authored-by: Anna Henningsen <[email protected]> Co-authored-by: Anna Henningsen <[email protected]>
1 parent ea37533 commit f2035a5

File tree

4 files changed

+193
-70
lines changed

4 files changed

+193
-70
lines changed

packages/compass/release/commands.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const git = require('./git');
99
const npm = require('./npm');
1010

1111
const ux = require('./ux');
12+
const { checkReleaseTicketInProgress } = require('./jira');
1213

1314
async function getPackageJsonVersion() {
1415
return require(await pkgUp()).version;
@@ -18,7 +19,9 @@ async function getValidReleaseBranch() {
1819
const currentBranch = await git.getCurrentBranch();
1920

2021
if (!branch.isReleaseBranch(currentBranch)) {
21-
throw new Error(`The current branch (${currentBranch}) is not a release branch.`);
22+
throw new Error(
23+
`The current branch (${currentBranch}) is not a release branch.`
24+
);
2225
}
2326

2427
return currentBranch;
@@ -55,19 +58,23 @@ async function startRelease(bumpFn, evergreenProject) {
5558
const newSemver = bumpFn(packageJsonVersion, currentBranch);
5659

5760
const answer = await cli.confirm(
58-
`Are you sure you want to bump from ${chalk.bold(packageJsonVersion)} `
59-
+ `to ${chalk.bold(newSemver)} and release?`
61+
`Are you sure you want to bump from ${chalk.bold(packageJsonVersion)} ` +
62+
`to ${chalk.bold(newSemver)} and release?`
6063
);
6164

6265
if (!answer) {
6366
cli.info('cancelled.');
6467
return;
6568
}
6669

70+
await checkReleaseTicketInProgress(newSemver);
71+
6772
cli.info(
6873
'\n\n',
6974
ux.manualAction(
70-
`Make sure that ${chalk.bold(evergreenProject)} is building from ${chalk.bold(currentBranch)}:\n`,
75+
`Make sure that ${chalk.bold(
76+
evergreenProject
77+
)} is building from ${chalk.bold(currentBranch)}:\n`,
7178
ux.link(`https://evergreen.mongodb.com/projects##${evergreenProject}`)
7279
),
7380
'\n'
@@ -76,10 +83,7 @@ async function startRelease(bumpFn, evergreenProject) {
7683
cli.info('Press enter to continue or Ctrl+C to abort....');
7784
ux.waitForEnter();
7885

79-
await commitAndPushNewVersion(
80-
newSemver,
81-
currentBranch
82-
);
86+
await commitAndPushNewVersion(newSemver, currentBranch);
8387

8488
cli.info(
8589
'\n',
@@ -124,7 +128,8 @@ async function releaseCheckout(versionLike) {
124128
'\n',
125129
ux.manualAction(
126130
'You just checked out a new release branch that does not exist in the remote. Run:\n',
127-
ux.command(`git push -u origin ${releaseBranchName}`), '\n',
131+
ux.command(`git push -u origin ${releaseBranchName}`),
132+
'\n',
128133
'to create the remote branch before proceeding with the release.'
129134
),
130135
'\n'
@@ -137,5 +142,5 @@ async function releaseCheckout(versionLike) {
137142
module.exports = {
138143
releaseBeta,
139144
releaseGa,
140-
releaseCheckout
145+
releaseCheckout,
141146
};

packages/compass/release/index.intercept.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,31 @@ const path = require('path');
88

99
nock('https://info-mongodb-com.s3.amazonaws.com')
1010
.get('/com-download-center/compass.json')
11-
.replyWithFile(
12-
200, path.resolve(__dirname, 'fixtures', 'config.json'));
11+
.replyWithFile(200, path.resolve(__dirname, 'fixtures', 'config.json'));
1312

1413
nock('https://info-mongodb-com.s3.amazonaws.com')
1514
.put('/com-download-center/compass.json')
1615
.reply(200);
1716

18-
nock('https://downloads.mongodb.com')
19-
.head(/.*/)
17+
nock('https://downloads.mongodb.com').head(/.*/).times(9999).reply(200);
18+
19+
nock('https://jira.mongodb.org')
20+
.get(/.*/)
2021
.times(9999)
21-
.reply(200);
22+
.reply(
23+
200,
24+
JSON.stringify({
25+
issues: [
26+
{
27+
key: 'COMPASS-6087',
28+
fields: {
29+
status: {
30+
name: 'In Progress',
31+
},
32+
},
33+
},
34+
],
35+
})
36+
);
2237

2338
require('./index');
24-

packages/compass/release/index.spec.js

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ async function runReleaseCommand(args, options = {}) {
1414
...options,
1515
env: {
1616
...options.env,
17-
MONGODB_COMPASS_RELEASE_MAX_WAIT_TIME: '0'
18-
}
17+
MONGODB_COMPASS_RELEASE_MAX_WAIT_TIME: '0',
18+
},
1919
};
2020

2121
const proc = execa(
@@ -40,7 +40,7 @@ async function checkoutBranch(branchName, options) {
4040
}
4141
}
4242

43-
describe('release', function() {
43+
describe('release', function () {
4444
if (!!process.env.EVERGREEN && process.platform === 'darwin') {
4545
// These tests are not working well on Evergreen macOS machines and we will
4646
// skip them for now (they will run in GitHub CI)
@@ -49,7 +49,7 @@ describe('release', function() {
4949
return;
5050
}
5151

52-
afterEach(function() {
52+
afterEach(function () {
5353
while (running.length) {
5454
running.shift().kill('SIGTERM', { forceKillAfterTimeout: 100 });
5555
}
@@ -59,7 +59,7 @@ describe('release', function() {
5959
let remote;
6060
let repoPath;
6161

62-
beforeEach(async function() {
62+
beforeEach(async function () {
6363
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'compass-release-tests-'));
6464

6565
// create fake git remote:
@@ -89,7 +89,7 @@ describe('release', function() {
8989
});
9090

9191
// eslint-disable-next-line mocha/no-sibling-hooks
92-
afterEach(function() {
92+
afterEach(function () {
9393
try {
9494
fs.removeSync(tempDir);
9595
} catch (e) {
@@ -98,134 +98,172 @@ describe('release', function() {
9898
}
9999
});
100100

101-
it('prints usage if no argument is passed', async function() {
102-
const { stdout, failed } = await (runReleaseCommand(['']).catch(e => e));
101+
it('prints usage if no argument is passed', async function () {
102+
const { stdout, failed } = await runReleaseCommand(['']).catch((e) => e);
103103
expect(failed).to.be.true;
104104
expect(stdout).to.contain('USAGE');
105105
});
106106

107-
describe('checkout', function() {
108-
it('creates a new branch if not exists', async function() {
107+
describe('checkout', function () {
108+
it('creates a new branch if not exists', async function () {
109109
await runReleaseCommand(['checkout', '1.12']);
110-
const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
110+
const { stdout } = await execa('git', [
111+
'rev-parse',
112+
'--abbrev-ref',
113+
'HEAD',
114+
]);
111115
expect(stdout).to.equal('1.12-releases');
112116
});
113117

114-
it('checks out an existing branch', async function() {
118+
it('checks out an existing branch', async function () {
115119
await checkoutBranch('1.12-releases');
116120
await checkoutBranch(MAIN_BRANCH);
117121
await runReleaseCommand(['checkout', '1.12']);
118-
const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
122+
const { stdout } = await execa('git', [
123+
'rev-parse',
124+
'--abbrev-ref',
125+
'HEAD',
126+
]);
119127
expect(stdout).to.equal('1.12-releases');
120128
});
121129

122-
it('prints usage if no version is passed', async function() {
123-
const { stdout, failed } = await (runReleaseCommand(['checkout']).catch(e => e));
130+
it('prints usage if no version is passed', async function () {
131+
const { stdout, failed } = await runReleaseCommand(['checkout']).catch(
132+
(e) => e
133+
);
124134
expect(failed).to.be.true;
125135
expect(stdout).to.contain('USAGE');
126136
});
127137

128-
it(`fails if branch is not ${MAIN_BRANCH}`, async function() {
138+
it(`fails if branch is not ${MAIN_BRANCH}`, async function () {
129139
await checkoutBranch('some-branch');
130-
const { stderr, failed } = await (runReleaseCommand(['checkout', '1.12']).catch(e => e));
140+
const { stderr, failed } = await runReleaseCommand([
141+
'checkout',
142+
'1.12',
143+
]).catch((e) => e);
131144
expect(failed).to.be.true;
132-
expect(stderr).to.contain(`The current branch is not the ${MAIN_BRANCH} branch`);
145+
expect(stderr).to.contain(
146+
`The current branch is not the ${MAIN_BRANCH} branch`
147+
);
133148
});
134149
});
135150

136151
[
137152
['beta', '1.12.0-beta.0'],
138-
['ga', '1.12.0']
139-
].forEach(([ command, expectedVersion ]) => {
140-
describe(command, function() {
141-
it(`fails from ${MAIN_BRANCH}`, async function() {
153+
['ga', '1.12.0'],
154+
].forEach(([command, expectedVersion]) => {
155+
describe(command, function () {
156+
it(`fails from ${MAIN_BRANCH}`, async function () {
142157
await checkoutBranch(MAIN_BRANCH);
143-
const { stderr, failed } = await (runReleaseCommand([command]).catch(e => e));
158+
const { stderr, failed } = await runReleaseCommand([command]).catch(
159+
(e) => e
160+
);
144161
expect(failed).to.be.true;
145-
expect(stderr).to.contain(`The current branch (${MAIN_BRANCH}) is not a release branch`);
162+
expect(stderr).to.contain(
163+
`The current branch (${MAIN_BRANCH}) is not a release branch`
164+
);
146165
});
147166

148-
it('fails if branch is not a release branch', async function() {
167+
it('fails if branch is not a release branch', async function () {
149168
await checkoutBranch('some-branch');
150-
const { stderr, failed } = await (runReleaseCommand([command]).catch(e => e));
169+
const { stderr, failed } = await runReleaseCommand([command]).catch(
170+
(e) => e
171+
);
151172
expect(failed).to.be.true;
152-
expect(stderr).to.contain('The current branch (some-branch) is not a release branch');
173+
expect(stderr).to.contain(
174+
'The current branch (some-branch) is not a release branch'
175+
);
153176
});
154177

155-
it('fails with untracked files', async function() {
178+
it('fails with untracked files', async function () {
156179
fs.writeFileSync('README.md', '');
157180
await checkoutBranch('1.12-releases');
158-
const { stderr, failed } = await (runReleaseCommand([command]).catch(e => e));
181+
const { stderr, failed } = await runReleaseCommand([command]).catch(
182+
(e) => e
183+
);
159184
expect(failed).to.be.true;
160185
expect(stderr).to.contain('You have untracked or staged changes');
161186
});
162187

163-
it('fails with staged files', async function() {
188+
it('fails with staged files', async function () {
164189
fs.writeFileSync('README.md', '');
165190
await checkoutBranch('1.12-releases');
166191
await execa('git', ['add', '.']);
167-
const { stderr, failed } = await (runReleaseCommand([command]).catch(e => e));
192+
const { stderr, failed } = await runReleaseCommand([command]).catch(
193+
(e) => e
194+
);
168195
expect(failed).to.be.true;
169196
expect(stderr).to.contain('You have untracked or staged changes');
170197
});
171198

172-
it('works with committed files', async function() {
199+
it('works with committed files', async function () {
173200
fs.writeFileSync('README.md', '');
174201
await checkoutBranch('1.12-releases');
175202
await execa('git', ['add', '.']);
176203
await execa('git', ['commit', '-am', 'test']);
177-
await runReleaseCommand([command], {input: 'N\n'});
204+
await runReleaseCommand([command], { input: 'N\n' });
178205
});
179206

180-
it('asks for confirmation and skips if not confirmed', async function() {
181-
expect(readPackageJsonVersion(
182-
path.resolve(repoPath, './package.json')
183-
)).to.equal('1.0.0');
207+
it('asks for confirmation and skips if not confirmed', async function () {
208+
expect(
209+
readPackageJsonVersion(path.resolve(repoPath, './package.json'))
210+
).to.equal('1.0.0');
184211

185212
await checkoutBranch('1.12-releases');
186213
const { stderr } = await runReleaseCommand([command], {
187-
input: 'N\n'
214+
input: 'N\n',
188215
});
189216

190217
expect(stderr).to.contain(
191-
`Are you sure you want to bump from 1.0.0 to ${expectedVersion} and release?`);
218+
`Are you sure you want to bump from 1.0.0 to ${expectedVersion} and release?`
219+
);
192220

193-
expect(readPackageJsonVersion(
194-
path.resolve(repoPath, './package.json')
195-
)).to.equal('1.0.0');
221+
expect(
222+
readPackageJsonVersion(path.resolve(repoPath, './package.json'))
223+
).to.equal('1.0.0');
196224
});
197225

198-
describe('from a release branch', function() {
226+
describe('from a release branch', function () {
199227
let clonePath;
200228

201-
beforeEach(async function() {
229+
beforeEach(async function () {
202230
await checkoutBranch('1.12-releases');
203231
await runReleaseCommand([command], {
204232
input: 'Y\n',
205233
stdout: 'inherit',
206-
stderr: 'inherit'
234+
stderr: 'inherit',
207235
});
208236

209237
clonePath = path.resolve(tempDir, command);
210-
await execa('git', ['clone', '--branch', MAIN_BRANCH, remote, clonePath]);
238+
await execa('git', [
239+
'clone',
240+
'--branch',
241+
MAIN_BRANCH,
242+
remote,
243+
clonePath,
244+
]);
211245
});
212246

213-
it(`does not affect ${MAIN_BRANCH}`, function() {
214-
const version = readPackageJsonVersion(path.resolve(clonePath, 'package.json'));
247+
it(`does not affect ${MAIN_BRANCH}`, function () {
248+
const version = readPackageJsonVersion(
249+
path.resolve(clonePath, 'package.json')
250+
);
215251
expect(version).to.equal('1.0.0');
216252
});
217253

218-
it('bumps the package version', async function() {
219-
await checkoutBranch('1.12-releases', {cwd: clonePath});
220-
const version = readPackageJsonVersion(path.resolve(clonePath, 'package.json'));
254+
it('bumps the package version', async function () {
255+
await checkoutBranch('1.12-releases', { cwd: clonePath });
256+
const version = readPackageJsonVersion(
257+
path.resolve(clonePath, 'package.json')
258+
);
221259
expect(version).to.equal(expectedVersion);
222260
});
223261

224-
it('pushes tags', async function() {
225-
await checkoutBranch('1.12-releases', {cwd: clonePath});
262+
it('pushes tags', async function () {
263+
await checkoutBranch('1.12-releases', { cwd: clonePath });
226264
await execa('git', ['fetch', '--all', '--tags']);
227265

228-
const { stdout } = await execa('git', ['tag'], {cwd: clonePath});
266+
const { stdout } = await execa('git', ['tag'], { cwd: clonePath });
229267
expect(stdout.split('\n')).to.deep.equal([`v${expectedVersion}`]);
230268
});
231269
});

0 commit comments

Comments
 (0)