forked from googleapis/release-please
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrapper.ts
86 lines (82 loc) · 2.68 KB
/
bootstrapper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {describe, it, beforeEach, afterEach} from 'mocha';
import * as sinon from 'sinon';
import {expect} from 'chai';
import {Bootstrapper} from '../src/bootstrapper';
import {GitHub} from '../src/github';
import {assertHasUpdate} from './helpers';
import {ReleasePleaseManifest} from '../src/updaters/release-please-manifest';
import {ReleasePleaseConfig} from '../src/updaters/release-please-config';
import * as snapshot from 'snap-shot-it';
const sandbox = sinon.createSandbox();
describe('Bootstrapper', () => {
let github: GitHub;
beforeEach(async () => {
github = await GitHub.create({
owner: 'fake-owner',
repo: 'fake-repo',
defaultBranch: 'main',
token: 'fake-token',
});
});
afterEach(() => {
sandbox.restore();
});
it('should open a PR', async () => {
const expectedTitle = 'chore: bootstrap releases for path: .';
const expectedHeadBranchName = 'release-please/bootstrap/default';
const createPullRequestStub = sinon
.stub(github, 'createPullRequest')
.resolves({
headBranchName: expectedHeadBranchName,
baseBranchName: 'main',
title: expectedTitle,
body: 'body',
files: [],
labels: [],
number: 123,
});
const bootstapper = new Bootstrapper(github, 'main');
const pullRequest = await bootstapper.bootstrap('.', {
releaseType: 'node',
});
expect(pullRequest.number).to.eql(123);
sinon.assert.calledOnceWithExactly(
createPullRequestStub,
sinon.match({
headBranchName: expectedHeadBranchName,
baseBranchName: 'main',
}),
'main',
expectedTitle,
sinon.match.array,
sinon.match.any
);
const updates = createPullRequestStub.firstCall.args[3];
assertHasUpdate(
updates,
'.release-please-manifest.json',
ReleasePleaseManifest
);
const update = assertHasUpdate(
updates,
'release-please-config.json',
ReleasePleaseConfig
);
expect(update.createIfMissing).to.be.true;
const newContent = update.updater.updateContent(undefined);
snapshot(newContent);
});
});