Skip to content

Commit 43cdcf5

Browse files
committed
added duplications checks for CHANGELOG
1 parent 1aa17f3 commit 43cdcf5

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

scripts/validate-changelog-tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ def test_extract_added_lines_only_changelog_has_added(self):
124124
'''
125125
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
126126

127+
def test_extract_added_lines_only_changelog_has_added_with_blank_lines(self):
128+
expected = {
129+
"CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
130+
}
131+
diff = '''diff --git a/CHANGELOG.md b/CHANGELOG.md
132+
--- a/CHANGELOG.md (revision fca6af9072a1b6cb7263460f7c3270e48bffed07)
133+
+++ b/CHANGELOG.md (date 1659101777554)
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+
+
141+
142+
#### Bug fixes and improvements
143+
- Fixed first unreleased bug. [#6047](https://github.com/mapbox/mapbox-navigation-android/pull/6047)
144+
'''
145+
self.assertEqual(validate_changelog_utils.extract_added_lines(diff), expected)
146+
127147
def test_extract_added_lines_only_changelog_with_path_has_added(self):
128148
expected = {
129149
"libnavui-androidauto/CHANGELOG.md" : ['- Added third unreleased feature. [#6050](https://github.com/mapbox/mapbox-navigation-android/pull/6050)']
@@ -642,6 +662,27 @@ def test_check_version_section_single_line_repeats_unstable_version(self):
642662
added_lines = ['- Added first feature to 2.7.0-beta1. [#6045](https://github.com/mapbox/mapbox-navigation-android/pull/6045)']
643663
validate_changelog_utils.check_version_section(content, added_lines)
644664

665+
def test_check_for_duplications_empty_list(self):
666+
validate_changelog_utils.check_for_duplications([])
667+
668+
def test_check_for_duplications_single_unique_element(self):
669+
added_lines = ['- Line 1']
670+
validate_changelog_utils.check_for_duplications(added_lines)
671+
672+
def test_check_for_duplications_single_repeated_element(self):
673+
added_lines = ['- Line 1', '- Line 1']
674+
with self.assertRaises(Exception):
675+
validate_changelog_utils.check_for_duplications(added_lines)
676+
677+
def test_check_for_duplications_multiple_unique_elements(self):
678+
added_lines = ['- Line 1', '- Line 2', '- Line 3']
679+
validate_changelog_utils.check_for_duplications(added_lines)
680+
681+
def test_check_for_duplications_multiple_elements_with_repeated(self):
682+
added_lines = ['- Line 1', '- Line 2', '- Line 3', '- Line 2']
683+
with self.assertRaises(Exception):
684+
validate_changelog_utils.check_for_duplications(added_lines)
685+
645686
def read_test_changelog(self, filename):
646687
script_dir = os.path.dirname(__file__)
647688
rel_path = "test_resources/" + filename

scripts/validate-changelog.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
with requests.get(files_url, headers) as files_response:
3030
contents_urls_by_file = validate_changelog_utils.parse_contents_url(files_response.json())
3131
for (filename, contents_url) in contents_urls_by_file.items():
32+
validate_changelog_utils.check_for_duplications(added_lines_by_file[filename])
3233
with requests.get(contents_url, headers) as contents_response:
3334
content = base64.b64decode(contents_response.json()["content"]).decode("utf-8")
3435
validate_changelog_utils.check_version_section(content, added_lines_by_file[filename])

scripts/validate_changelog_utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
def is_line_added(line):
1111
return line.strip().startswith('+')
1212

13+
def is_line_not_blank(line):
14+
return len(line.strip()) > 0
15+
1316
def remove_plus(line):
1417
return line.strip()[1:]
1518

@@ -24,7 +27,7 @@ def group_by_versions(lines):
2427
groups[group_name] = group
2528
group = []
2629
group_name = line
27-
elif len(line.strip()) > 0:
30+
elif is_line_not_blank(line):
2831
group.append(line)
2932
if len(group) > 0 and len(group_name.strip()) > 0:
3033
groups[group_name] = group
@@ -98,7 +101,7 @@ def extract_added_lines(whole_diff):
98101
diff_searchable = diff_starting_at_changelog[first_changelog_diff_index:last_reachable_index]
99102

100103
diff_lines = diff_searchable.split('\n')
101-
added_lines[filename] = list(map(remove_plus, list(filter(is_line_added, diff_lines))))
104+
added_lines[filename] = list(filter(is_line_not_blank, map(remove_plus, list(filter(is_line_added, diff_lines)))))
102105
diff = diff[last_reachable_index:]
103106
return added_lines
104107

@@ -118,8 +121,16 @@ def check_version_section(content, added_lines):
118121

119122
for added_line in added_lines:
120123
if added_line not in unreleased_group:
121-
raise Exception(added_line + " should be placed in 'Unreleased' section")
124+
raise Exception("\"" + added_line + "\" should be placed in 'Unreleased' section")
122125

123126
for stable_version in stable_versions:
124127
if added_line in stable_versions[stable_version]:
125-
raise Exception("The changelog entry \"" + added_line + "\" is already contained in " + stable_version + " changelog.")
128+
raise Exception("The changelog entry \"" + added_line + "\" is already contained in " + stable_version + " changelog.")
129+
130+
def check_for_duplications(added_lines):
131+
unique_added_lines = set()
132+
for added_line in added_lines:
133+
if added_line in unique_added_lines:
134+
raise Exception("\"" + added_line + "\" is added more than once" )
135+
else:
136+
unique_added_lines.add(added_line)

0 commit comments

Comments
 (0)