@@ -26,8 +26,16 @@ import {PyProjectToml} from '../../src/updaters/python/pyproject-toml';
26
26
import { SetupCfg } from '../../src/updaters/python/setup-cfg' ;
27
27
import { SetupPy } from '../../src/updaters/python/setup-py' ;
28
28
import { Changelog } from '../../src/updaters/changelog' ;
29
+ import { ChangelogJson } from '../../src/updaters/changelog-json' ;
30
+ import * as snapshot from 'snap-shot-it' ;
29
31
30
32
const sandbox = sinon . createSandbox ( ) ;
33
+ const fixturesPath = './test/fixtures/strategies/python' ;
34
+
35
+ const UUID_REGEX =
36
+ / [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } / g;
37
+ const ISO_DATE_REGEX =
38
+ / [ 0 - 9 ] { 4 } - [ 0 - 9 ] { 2 } - [ 0 - 9 ] { 2 } T [ 0 - 9 ] { 2 } : [ 0 - 9 ] { 2 } : [ 0 - 9 ] { 2 } \. [ 0 - 9 ] + Z / g; // 2023-01-05T16:42:33.446Z
31
39
32
40
const COMMITS = [
33
41
...buildMockConventionalCommit (
@@ -59,6 +67,9 @@ describe('Python', () => {
59
67
github,
60
68
component : 'google-cloud-automl' ,
61
69
} ) ;
70
+ sandbox
71
+ . stub ( github , 'getFileContentsOnBranch' )
72
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'setup.py' ) ) ;
62
73
sandbox . stub ( github , 'findFilesByFilenameAndRef' ) . resolves ( [ ] ) ;
63
74
const latestRelease = undefined ;
64
75
const release = await strategy . buildReleasePullRequest (
@@ -74,6 +85,9 @@ describe('Python', () => {
74
85
github,
75
86
component : 'google-cloud-automl' ,
76
87
} ) ;
88
+ sandbox
89
+ . stub ( github , 'getFileContentsOnBranch' )
90
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'setup.py' ) ) ;
77
91
sandbox . stub ( github , 'findFilesByFilenameAndRef' ) . resolves ( [ ] ) ;
78
92
const latestRelease = {
79
93
tag : new TagName ( Version . parse ( '0.123.4' ) , 'google-cloud-automl' ) ,
@@ -94,6 +108,9 @@ describe('Python', () => {
94
108
github,
95
109
component : 'google-cloud-automl' ,
96
110
} ) ;
111
+ sandbox
112
+ . stub ( github , 'getFileContentsOnBranch' )
113
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'setup.py' ) ) ;
97
114
sandbox . stub ( github , 'findFilesByFilenameAndRef' ) . resolves ( [ ] ) ;
98
115
const latestRelease = undefined ;
99
116
const release = await strategy . buildReleasePullRequest (
@@ -153,6 +170,9 @@ describe('Python', () => {
153
170
github,
154
171
component : 'google-cloud-automl' ,
155
172
} ) ;
173
+ sandbox
174
+ . stub ( github , 'getFileContentsOnBranch' )
175
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'setup.py' ) ) ;
156
176
sandbox
157
177
. stub ( github , 'findFilesByFilenameAndRef' )
158
178
. resolves ( [ 'src/version.py' ] ) ;
@@ -164,5 +184,52 @@ describe('Python', () => {
164
184
const updates = release ! . updates ;
165
185
assertHasUpdate ( updates , 'src/version.py' , PythonFileWithVersion ) ;
166
186
} ) ;
187
+
188
+ it ( 'updates changelog.json if present' , async ( ) => {
189
+ const COMMITS = [
190
+ ...buildMockConventionalCommit (
191
+ 'fix(deps): update dependency com.google.cloud:google-cloud-storage to v1.120.0'
192
+ ) ,
193
+ ...buildMockConventionalCommit ( 'chore: update deps' ) ,
194
+ ...buildMockConventionalCommit ( 'chore!: update a very important dep' ) ,
195
+ ...buildMockConventionalCommit (
196
+ 'fix(deps): update dependency com.google.cloud:google-cloud-spanner to v1.50.0'
197
+ ) ,
198
+ ...buildMockConventionalCommit ( 'chore: update common templates' ) ,
199
+ ] ;
200
+ const strategy = new Python ( {
201
+ targetBranch : 'main' ,
202
+ github,
203
+ component : 'google-cloud-automl' ,
204
+ } ) ;
205
+ sandbox . stub ( github , 'findFilesByFilenameAndRef' ) . resolves ( [ ] ) ;
206
+ const getFileContentsStub = sandbox . stub (
207
+ github ,
208
+ 'getFileContentsOnBranch'
209
+ ) ;
210
+ getFileContentsStub
211
+ . withArgs ( 'changelog.json' , 'main' )
212
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'changelog.json' ) ) ;
213
+ getFileContentsStub
214
+ . withArgs ( 'setup.py' , 'main' )
215
+ . resolves ( buildGitHubFileContent ( fixturesPath , 'setup.py' ) ) ;
216
+ const latestRelease = undefined ;
217
+ const release = await strategy . buildReleasePullRequest (
218
+ COMMITS ,
219
+ latestRelease
220
+ ) ;
221
+ const updates = release ! . updates ;
222
+ assertHasUpdate ( updates , 'CHANGELOG.md' , Changelog ) ;
223
+ const update = assertHasUpdate ( updates , 'changelog.json' , ChangelogJson ) ;
224
+ const newContent = update . updater . updateContent (
225
+ JSON . stringify ( { entries : [ ] } )
226
+ ) ;
227
+ snapshot (
228
+ newContent
229
+ . replace ( / \r \n / g, '\n' ) // make newline consistent regardless of OS.
230
+ . replace ( UUID_REGEX , 'abc-123-efd-qwerty' )
231
+ . replace ( ISO_DATE_REGEX , '2023-01-05T16:42:33.446Z' )
232
+ ) ;
233
+ } ) ;
167
234
} ) ;
168
235
} ) ;
0 commit comments