Skip to content

Commit b9cb74e

Browse files
wiegandmgreenbonebot
authored andcommitted
Fix: Correctly report header copyright year changes
Previously, when a header was changed from e.g. `2025` to `2025-2026`, this was reported as a change from `None` to `2026`. Similarly, a change from `2024-2025` to `2024-2026` was reported as a change from `2025` to `2026`.
1 parent d3ad273 commit b9cb74e

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

pontos/updateheader/updateheader.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,19 @@ def update_file(
258258
_substitute_license_text(
259259
fp, line, copyright_regex, copyright_term
260260
)
261-
print(
262-
f"{file}: Changed License Header Copyright Year "
263-
f"{copyright_match.modification_year} -> "
264-
f"{year}"
265-
)
261+
if with_multi_year:
262+
print(
263+
f"{file}: Changed License Header Copyright Year "
264+
f"{copyright_match.creation_year}-"
265+
f"{copyright_match.modification_year} -> "
266+
f"{copyright_match.creation_year}-{year}"
267+
)
268+
else:
269+
print(
270+
f"{file}: Changed License Header Copyright Year "
271+
f"{copyright_match.creation_year} -> "
272+
f"{copyright_match.creation_year}-{year}"
273+
)
266274
else:
267275
print(f"{file}: License Header is ok.")
268276

tests/updateheader/test_header.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_update_create_header_single_year(self, mock_stdout):
327327
)
328328

329329
@patch("sys.stdout", new_callable=StringIO)
330-
def test_update_header_in_file(self, mock_stdout):
330+
def test_update_header_in_file_from_single_year(self, mock_stdout):
331331
year = "2021"
332332
license_id = "AGPL-3.0-or-later"
333333

@@ -346,15 +346,42 @@ def test_update_header_in_file(self, mock_stdout):
346346
self.assertEqual(
347347
ret,
348348
f"{test_file}: Changed License Header "
349-
"Copyright Year None -> 2021\n",
349+
"Copyright Year 2020 -> 2020-2021\n",
350350
)
351351
self.assertIn(
352352
"# SPDX-FileCopyrightText: 2020-2021 Greenbone AG",
353353
test_file.read_text(encoding="utf-8"),
354354
)
355355

356356
@patch("sys.stdout", new_callable=StringIO)
357-
def test_update_header_in_file_single_year(self, mock_stdout):
357+
def test_update_header_in_file_from_multi_year(self, mock_stdout):
358+
year = "2021"
359+
license_id = "AGPL-3.0-or-later"
360+
361+
header = HEADER.format(date="2018-2020")
362+
with temp_file(
363+
content=header, name="test.py", change_into=True
364+
) as test_file:
365+
update_file(
366+
test_file,
367+
year,
368+
license_id,
369+
self.company,
370+
)
371+
372+
ret = mock_stdout.getvalue()
373+
self.assertEqual(
374+
ret,
375+
f"{test_file}: Changed License Header "
376+
"Copyright Year 2018-2020 -> 2018-2021\n",
377+
)
378+
self.assertIn(
379+
"# SPDX-FileCopyrightText: 2018-2021 Greenbone AG",
380+
test_file.read_text(encoding="utf-8"),
381+
)
382+
383+
@patch("sys.stdout", new_callable=StringIO)
384+
def test_update_header_in_file_to_single_year(self, mock_stdout):
358385
year = "2021"
359386
license_id = "AGPL-3.0-or-later"
360387

0 commit comments

Comments
 (0)