Skip to content

Commit 63e4e60

Browse files
committed
fix changelog validation
1 parent 9681960 commit 63e4e60

3 files changed

Lines changed: 277 additions & 54 deletions

File tree

scripts/validate-changelog-tests.py

Lines changed: 230 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ def test_parse_contents_url_has_changelog_no_url(self):
8686
validate_changelog_utils.parse_contents_url([{ "filename": "CHANGELOG.md" }])
8787

8888
def test_parse_contents_url_has_changelog_and_url(self):
89+
filename = "CHANGELOG.md"
8990
url = "my url"
90-
actual = validate_changelog_utils.parse_contents_url([{ "filename": "CHANGELOG.md", "contents_url": url }])
91-
self.assertEqual(actual, url)
91+
actual = validate_changelog_utils.parse_contents_url([{ "filename": filename, "contents_url": url }])
92+
self.assertEqual(actual, { filename : url })
9293

9394
def test_extract_added_lines_only_changelog_nothing_added(self):
9495
diff = '''diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -103,10 +104,12 @@ def test_extract_added_lines_only_changelog_nothing_added(self):
103104
#### Bug fixes and improvements
104105
- Fixed first unreleased bug. [#6047](https://github.com/mapbox/mapbox-navigation-android/pull/6047)
105106
'''
106-
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), [])
107+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), { "CHANGELOG.md" : [] })
107108

108109
def test_extract_added_lines_only_changelog_has_added(self):
109-
expected = ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
110+
expected = {
111+
"CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
112+
}
110113
diff = '''diff --git a/CHANGELOG.md b/CHANGELOG.md
111114
--- a/CHANGELOG.md (revision fca6af9072a1b6cb7263460f7c3270e48bffed07)
112115
+++ b/CHANGELOG.md (date 1659101777554)
@@ -121,6 +124,150 @@ def test_extract_added_lines_only_changelog_has_added(self):
121124
'''
122125
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
123126

127+
def test_extract_added_lines_only_changelog_with_path_has_added(self):
128+
expected = {
129+
"libnavui-androidauto/CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
130+
}
131+
diff = '''diff --git a/libnavui-androidauto/CHANGELOG.md b/libnavui-androidauto/CHANGELOG.md
132+
--- a/libnavui-androidauto/CHANGELOG.md (revision ee5039502306c1ea6449f57615a2ad0f7f23fd83)
133+
+++ b/libnavui-androidauto/CHANGELOG.md (date 1661336275515)
134+
@@ -6,6 +6,7 @@
135+
#### Features
136+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
137+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
138+
+- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
139+
140+
#### Bug fixes and improvements
141+
- Added. [#6165](https://github.com/mapbox/mapbox-navigation-android/pull/6165)
142+
'''
143+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
144+
145+
def test_extract_added_lines_several_changelogs_in_a_row_has_added(self):
146+
expected = {
147+
"libnavui-androidauto/CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)'],
148+
"CHANGELOG.md" : ['- Added fourth unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
149+
}
150+
diff = '''diff --git a/CHANGELOG.md b/CHANGELOG.md
151+
--- a/CHANGELOG.md (revision e53b37ad3a4540bdb0878b4679a174f9518134b0)
152+
+++ b/CHANGELOG.md (date 1661336645379)
153+
@@ -6,6 +6,7 @@
154+
#### Features
155+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
156+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
157+
+- Added fourth unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
158+
159+
#### Bug fixes and improvements
160+
- Added2. [#6145](https://github.com/mapbox/mapbox-navigation-android/pull/6145)
161+
Index: libnavui-androidauto/CHANGELOG.md
162+
IDEA additional info:
163+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
164+
<+>UTF-8
165+
===================================================================
166+
diff --git a/libnavui-androidauto/CHANGELOG.md b/libnavui-androidauto/CHANGELOG.md
167+
--- a/libnavui-androidauto/CHANGELOG.md (revision 9307f85eaea82470de6f3111ff0218f76e1d9779)
168+
+++ b/libnavui-androidauto/CHANGELOG.md (date 1661336328085)
169+
@@ -6,6 +6,7 @@
170+
#### Features
171+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
172+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
173+
+- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
174+
175+
#### Bug fixes and improvements
176+
- Added. [#6165](https://github.com/mapbox/mapbox-navigation-android/pull/6165)
177+
'''
178+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
179+
180+
def test_extract_added_lines_several_changelogs_divided_has_added(self):
181+
expected = {
182+
"libnavui-androidauto/CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)'],
183+
"CHANGELOG.md" : ['- Added fourth unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
184+
}
185+
diff = '''diff --git a/CHANGELOG.md b/CHANGELOG.md
186+
--- a/CHANGELOG.md (revision e53b37ad3a4540bdb0878b4679a174f9518134b0)
187+
+++ b/CHANGELOG.md (date 1661336645379)
188+
@@ -6,6 +6,7 @@
189+
#### Features
190+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
191+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
192+
+- Added fourth unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
193+
194+
#### Bug fixes and improvements
195+
- Added2. [#6145](https://github.com/mapbox/mapbox-navigation-android/pull/6145)
196+
Index: libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt
197+
IDEA additional info:
198+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
199+
<+>UTF-8
200+
===================================================================
201+
diff --git a/libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt b/libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt
202+
--- a/libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt (revision 85db37c032b85d89c65f909c65dbf4e36130bc95)
203+
+++ b/libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt (date 1659101643213)
204+
@@ -4,5 +4,5 @@
205+
206+
fun testMethod1() {}
207+
208+
- fun testMethod2(a: Int) = a * 10
209+
+ fun testMethod2(a: Int, b: Int) = a * 10 + b
210+
}
211+
Index: libnavui-androidauto/CHANGELOG.md
212+
IDEA additional info:
213+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
214+
<+>UTF-8
215+
===================================================================
216+
diff --git a/libnavui-androidauto/CHANGELOG.md b/libnavui-androidauto/CHANGELOG.md
217+
--- a/libnavui-androidauto/CHANGELOG.md (revision 9307f85eaea82470de6f3111ff0218f76e1d9779)
218+
+++ b/libnavui-androidauto/CHANGELOG.md (date 1661336328085)
219+
@@ -6,6 +6,7 @@
220+
#### Features
221+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
222+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
223+
+- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
224+
225+
#### Bug fixes and improvements
226+
- Added. [#6165](https://github.com/mapbox/mapbox-navigation-android/pull/6165)
227+
'''
228+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
229+
230+
def test_extract_added_lines_several_changelogs_only_one_has_added(self):
231+
expected = {
232+
"CHANGELOG.md" : [],
233+
"libnavui-androidauto/CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
234+
}
235+
diff = '''
236+
Index: CHANGELOG.md
237+
IDEA additional info:
238+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
239+
<+>UTF-8
240+
===================================================================
241+
diff --git a/CHANGELOG.md b/CHANGELOG.md
242+
--- a/CHANGELOG.md (revision 2fed9e01ca0f2e15ce15f104a2175b12f48f15d4)
243+
+++ b/CHANGELOG.md (date 1661341839927)
244+
@@ -5,7 +5,6 @@
245+
## Unreleased
246+
#### Features
247+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
248+
-- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
249+
250+
#### Bug fixes and improvements
251+
- Added2. [#6145](https://github.com/mapbox/mapbox-navigation-android/pull/6145)
252+
Index: libnavui-androidauto/CHANGELOG.md
253+
IDEA additional info:
254+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
255+
<+>UTF-8
256+
===================================================================
257+
diff --git a/libnavui-androidauto/CHANGELOG.md b/libnavui-androidauto/CHANGELOG.md
258+
--- a/libnavui-androidauto/CHANGELOG.md (revision 4710fa5f28a132f6db42d1d580650a4b14987368)
259+
+++ b/libnavui-androidauto/CHANGELOG.md (date 1661336328085)
260+
@@ -6,6 +6,7 @@
261+
#### Features
262+
- Added first unreleased feature. [#6049](https://github.com/mapbox/mapbox-navigation-android/pull/6049)
263+
- Added second unreleased feature. [#6048](https://github.com/mapbox/mapbox-navigation-android/pull/6048)
264+
+- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)
265+
266+
#### Bug fixes and improvements
267+
- Added. [#6165](https://github.com/mapbox/mapbox-navigation-android/pull/6165)
268+
'''
269+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
270+
124271
def test_extract_added_lines_changelog_in_the_beginning_nothing_added(self):
125272
diff = '''
126273
Index: CHANGELOG.md
@@ -155,13 +302,15 @@ def test_extract_added_lines_changelog_in_the_beginning_nothing_added(self):
155302
+ fun testMethod2(a: Int, b: Int) = a * 10 + b
156303
}
157304
'''
158-
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), [])
305+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), { "CHANGELOG.md" : [] })
159306

160307
def test_extract_added_lines_changelog_in_the_beginning_has_added(self):
161-
expected = [
162-
'- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)',
163-
'- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)'
164-
]
308+
expected = {
309+
"CHANGELOG.md" : [
310+
'- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)',
311+
'- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)'
312+
]
313+
}
165314
diff = '''
166315
Index: CHANGELOG.md
167316
IDEA additional info:
@@ -231,10 +380,12 @@ def test_extract_added_lines_changelog_in_the_end_nothing_added(self):
231380
## Mapbox Navigation SDK 2.7.0-beta.1 - 14 July, 2022
232381
### Changelog
233382
'''
234-
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), [])
383+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), { "CHANGELOG.md" : [] })
235384

236385
def test_extract_added_lines_changelog_in_the_end_has_added(self):
237-
expected = ['- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)']
386+
expected = {
387+
"CHANGELOG.md" : ['- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)']
388+
}
238389
diff = '''
239390
Index: .circleci/config2.yml
240391
IDEA additional info:
@@ -309,10 +460,12 @@ def test_extract_added_lines_changelog_in_the_middle_nothing_added(self):
309460
@@ -1,0 +1,1 @@
310461
+Added line
311462
'''
312-
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), [])
463+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), { "CHANGELOG.md" : [] })
313464

314465
def test_extract_added_lines_changelog_in_the_middle_has_added(self):
315-
expected = ['- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)']
466+
expected = {
467+
"CHANGELOG.md" : ['- Fixed third unreleased bug. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)']
468+
}
316469
diff = '''
317470
Index: libnavigation-core/src/main/java/com/mapbox/navigation/core/TestClass.kt
318471
IDEA additional info:
@@ -359,27 +512,78 @@ def test_extract_added_lines_changelog_in_the_middle_has_added(self):
359512
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
360513

361514
def test_check_contains_pr_link_empty(self):
362-
added_lines = []
515+
added_lines = {}
363516
validate_changelog_utils.check_contains_pr_link(added_lines)
364517

365518
def test_check_contains_pr_link_none_contain(self):
366-
added_lines = ['- Added 1.', '- Added 2.']
519+
added_lines = {
520+
"CHANGELOG.md" : ['- Added 1.', '- Added 2.']
521+
}
367522
with self.assertRaises(Exception):
368523
validate_changelog_utils.check_contains_pr_link(added_lines)
369524

370525
def test_check_contains_pr_link_only_one_contains(self):
371-
added_lines = [
372-
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
373-
'- Added 2.'
374-
]
526+
added_lines = {
527+
"CHANGELOG.md" : [
528+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
529+
'- Added 2.'
530+
]
531+
}
375532
with self.assertRaises(Exception):
376533
validate_changelog_utils.check_contains_pr_link(added_lines)
377534

378535
def test_check_contains_pr_link_all_contain(self):
379-
added_lines = [
380-
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
381-
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)'
382-
]
536+
added_lines = {
537+
"CHANGELOG.md" : [
538+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
539+
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)'
540+
]
541+
}
542+
validate_changelog_utils.check_contains_pr_link(added_lines)
543+
544+
def test_check_contains_pr_link_not_all_files_contain(self):
545+
added_lines = {
546+
"CHANGELOG.md" : [
547+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
548+
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)'
549+
],
550+
"path/CHANGELOG.md" : [
551+
'- Added 3.'
552+
]
553+
}
554+
with self.assertRaises(Exception):
555+
validate_changelog_utils.check_contains_pr_link(added_lines)
556+
557+
def test_check_contains_pr_link_multiple_files(self):
558+
added_lines = {
559+
"CHANGELOG.md" : [
560+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
561+
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)'
562+
],
563+
"path/CHANGELOG.md" : [
564+
'- Added 3. [#6052](https://github.com/mapbox/mapbox-navigation-android/pull/6052)'
565+
]
566+
}
567+
validate_changelog_utils.check_contains_pr_link(added_lines)
568+
569+
def test_check_contains_pr_link_all_contain_except_empty_line(self):
570+
added_lines = {
571+
"CHANGELOG.md" : [
572+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
573+
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)',
574+
''
575+
]
576+
}
577+
validate_changelog_utils.check_contains_pr_link(added_lines)
578+
579+
def test_check_contains_pr_link_all_contain_except_blank_line(self):
580+
added_lines = {
581+
"CHANGELOG.md" : [
582+
'- Added 1. [#6053](https://github.com/mapbox/mapbox-navigation-android/pull/6053)',
583+
'- Added 2. [#6012](https://github.com/mapbox/mapbox-navigation-android/pull/6012)',
584+
' '
585+
]
586+
}
383587
validate_changelog_utils.check_contains_pr_link(added_lines)
384588

385589
def test_check_version_section_empty_lines(self):
@@ -442,7 +646,9 @@ def read_test_changelog(self, filename):
442646
script_dir = os.path.dirname(__file__)
443647
rel_path = "test_resources/" + filename
444648
abs_file_path = os.path.join(script_dir, rel_path)
445-
return open(abs_file_path, "r").read()
649+
with open(abs_file_path, 'r') as f:
650+
data = f.read()
651+
return data
446652

447653
if __name__ == "__main__":
448654
unittest.main()

scripts/validate-changelog.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
pr_diff_url = response_json["diff_url"]
2424
with requests.get(pr_diff_url, headers) as diff_response:
2525
diff = diff_response.text
26-
print("[ddlog] diff: " + diff)
2726
validate_changelog_utils.check_has_changelog_diff(diff)
28-
added_lines = validate_changelog_utils.extract_added_lines(diff)
29-
validate_changelog_utils.check_contains_pr_link(added_lines)
27+
added_lines_by_file = validate_changelog_utils.extract_added_lines(diff)
28+
validate_changelog_utils.check_contains_pr_link(added_lines_by_file)
3029
with requests.get(files_url, headers) as files_response:
31-
contents_url = validate_changelog_utils.parse_contents_url(files_response.json())
32-
with requests.get(contents_url, headers) as contents_response:
33-
content = base64.b64decode(contents_response.json()["content"]).decode("utf-8")
34-
validate_changelog_utils.check_version_section(content, added_lines)
30+
contents_urls_by_file = validate_changelog_utils.parse_contents_url(files_response.json())
31+
for (filename, contents_url) in contents_urls_by_file.items():
32+
with requests.get(contents_url, headers) as contents_response:
33+
content = base64.b64decode(contents_response.json()["content"]).decode("utf-8")
34+
validate_changelog_utils.check_version_section(content, added_lines_by_file[filename])
3535
print("Changelog entry validation successful.")
3636
else:
3737
print("`skip changelog` label present, exiting.")

0 commit comments

Comments
 (0)