-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathgo-yoshi.ts
More file actions
217 lines (212 loc) · 7.43 KB
/
go-yoshi.ts
File metadata and controls
217 lines (212 loc) · 7.43 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// 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, afterEach, beforeEach} from 'mocha';
import {expect} from 'chai';
import {GitHub} from '../../src/github';
import {GoYoshi} from '../../src/strategies/go-yoshi';
import * as sinon from 'sinon';
import {assertHasUpdate, dateSafe} from '../helpers';
import {buildMockCommit} from '../helpers';
import {TagName} from '../../src/util/tag-name';
import {Version} from '../../src/version';
import {Changelog} from '../../src/updaters/changelog';
import snapshot = require('snap-shot-it');
import {VersionGo} from '../../src/updaters/go/version-go';
const sandbox = sinon.createSandbox();
const COMMITS = [
buildMockCommit(
'fix(iam): update dependency com.google.cloud:google-cloud-storage to v1.120.0',
['iam/foo.go']
),
buildMockCommit('chore: update common templates'),
];
describe('GoYoshi', () => {
let github: GitHub;
beforeEach(async () => {
github = await GitHub.create({
owner: 'googleapis',
repo: 'google-cloud-go',
defaultBranch: 'main',
});
});
afterEach(() => {
sandbox.restore();
});
describe('buildReleasePullRequest', () => {
it('returns release PR changes with defaultInitialVersion', async () => {
const expectedVersion = '0.1.0';
const strategy = new GoYoshi({
targetBranch: 'main',
github,
component: 'iam',
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
expect(release?.version?.toString()).to.eql(expectedVersion);
});
it('returns release PR changes with semver patch bump', async () => {
const expectedVersion = '0.123.5';
const strategy = new GoYoshi({
targetBranch: 'main',
github,
component: 'iam',
});
const latestRelease = {
tag: new TagName(Version.parse('0.123.4'), 'iam'),
sha: 'abc123',
notes: 'some notes',
};
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
expect(release?.version?.toString()).to.eql(expectedVersion);
});
});
describe('buildUpdates', () => {
it('builds common files', async () => {
const strategy = new GoYoshi({
targetBranch: 'main',
github,
component: 'iam',
});
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
latestRelease
);
const updates = release!.updates;
assertHasUpdate(updates, 'CHANGES.md', Changelog);
assertHasUpdate(updates, 'internal/version.go', VersionGo);
});
});
describe('buildReleasePullRequest', () => {
it('filters out submodule commits', async () => {
sandbox
.stub(github, 'findFilesByFilenameAndRef')
.withArgs('go.mod', 'main')
.resolves(['go.mod', 'internal/go.mod', 'logging/go.mod']);
const strategy = new GoYoshi({
targetBranch: 'main',
github,
includeComponentInTag: false,
});
const commits = [
buildMockCommit('fix: some generic fix'),
buildMockCommit('fix(translate): some translate fix'),
buildMockCommit('fix(logging): some logging fix'),
buildMockCommit('feat: some generic feature'),
];
const pullRequest = await strategy.buildReleasePullRequest(commits);
const pullRequestBody = pullRequest!.body.toString();
expect(pullRequestBody).to.not.include('logging');
snapshot(dateSafe(pullRequestBody));
});
it('filters out touched files not matching submodule commits', async () => {
sandbox
.stub(github, 'findFilesByFilenameAndRef')
.withArgs('go.mod', 'main')
.resolves(['go.mod', 'internal/go.mod', 'logging/go.mod']);
const strategy = new GoYoshi({
targetBranch: 'main',
github,
includeComponentInTag: false,
});
const commits = [
buildMockCommit('fix: some generic fix'),
buildMockCommit('fix(iam/apiv1): some firestore fix', [
'accessapproval/apiv1/access_approval_client.go',
'iam/apiv1/admin/firestore_admin_client.go',
]),
buildMockCommit('feat: some generic feature'),
];
const pullRequest = await strategy.buildReleasePullRequest(commits);
const pullRequestBody = pullRequest!.body.toString();
expect(pullRequestBody).to.not.include('access');
expect(pullRequestBody).to.include('iam');
snapshot(dateSafe(pullRequestBody));
});
it('combines google-api-go-client autogenerated PR', async () => {
github = await GitHub.create({
owner: 'googleapis',
repo: 'google-api-go-client',
defaultBranch: 'main',
});
const strategy = new GoYoshi({
targetBranch: 'main',
github,
});
const commits = [
buildMockCommit('feat(all): auto-regenerate discovery clients (#1281)'),
buildMockCommit('feat(all): auto-regenerate discovery clients (#1280)'),
buildMockCommit('feat(all): auto-regenerate discovery clients (#1279)'),
buildMockCommit('feat(all): auto-regenerate discovery clients (#1278)'),
];
const pullRequest = await strategy.buildReleasePullRequest(commits);
const pullRequestBody = pullRequest!.body.toString();
snapshot(dateSafe(pullRequestBody));
});
});
describe('getIgnoredSubModules', () => {
it('ignores non-google-cloud-go repos', async () => {
github = await GitHub.create({
owner: 'googleapis',
repo: 'google-cloud-foo',
defaultBranch: 'main',
});
const strategy = new GoYoshi({
targetBranch: 'main',
github,
includeComponentInTag: false,
});
const ignoredSubModules = await strategy.getIgnoredSubModules();
expect(ignoredSubModules.size).to.eql(0);
});
it('ignores submodule configurations', async () => {
const strategy = new GoYoshi({
targetBranch: 'main',
github,
component: 'storage',
includeComponentInTag: true,
});
const ignoredSubModules = await strategy.getIgnoredSubModules();
expect(ignoredSubModules.size).to.eql(0);
});
it('fetches the list of submodules', async () => {
sandbox
.stub(github, 'findFilesByFilenameAndRef')
.withArgs('go.mod', 'main')
.resolves([
'storage/go.mod',
'go.mod',
'internal/foo/go.mod',
'internal/go.mod',
'pubsub/go.mod',
]);
const strategy = new GoYoshi({
targetBranch: 'main',
github,
component: 'main',
includeComponentInTag: false,
});
const ignoredSubModules = await strategy.getIgnoredSubModules();
expect(ignoredSubModules.size).to.eql(2);
expect(ignoredSubModules.has('storage')).to.be.true;
expect(ignoredSubModules.has('pubsub')).to.be.true;
});
});
});