Skip to content

Improve changelog sorting #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<!--- Begin changes - Do not remove -->

- Change [#935]: Remove support for migrating from fixed into flexible database (introduced in 2.0.0)
- Enhancement [#1009]: Adding an animation to the workday waiver holidays table when the contents switch
- Enhancement [#646]: Title bar color now follows Windows mode (dark or light)
- Enhancement [#891]: Add button to reset to default preferences on preferences dialog
- Enhancement [#914]: Enable more formats to input time in preferences
- Enhancement [#946]: Included formal json scheme validator
- Enhancement [#948]: Allow vertical scroll when horizontal scroll reaches edges on month view
- Enhancement [#1009]: Adding an animation to the workday waiver holidays table when the contents switch
- Fix [#1008]: Sourced conflicting holidays being imported by default
- Fix [#1028]: Make images and icons not draggable
- Fix [#1034]: Preserving TTL font when offline
Expand Down
30 changes: 29 additions & 1 deletion scripts/update-changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,38 @@ def remove_prefix(text: str, prefix: str) -> str:
"""Remove the prefix from the string"""
return re.sub(r'^{0}'.format(re.escape(prefix)), '', text)

ENTRY_TYPE_RE = re.compile(r'(.*) ?\[')
ENTRY_NUMBER_RE = re.compile(r'\#(\d+)')

def changelog_entry_compare(entry_a, entry_b):
"""Sort the changelog lexicographically and consider PR numbers as integers"""
entry_a_number_match = ENTRY_NUMBER_RE.search(entry_a)
entry_b_number_match = ENTRY_NUMBER_RE.search(entry_b)
# If both have issue/PR numbers, compare text first and then numbers
if entry_a_number_match and entry_b_number_match:
entry_a_type = ENTRY_TYPE_RE.search(entry_a)
entry_b_type = ENTRY_TYPE_RE.search(entry_b)
if entry_a_type.group(1) != entry_b_type.group(1):
return -1 if entry_a < entry_b else 1
else:
entry_a_number = int(entry_a_number_match.group(1))
entry_b_number = int(entry_b_number_match.group(1))
if entry_a_number < entry_b_number:
return -1
elif entry_a_number > entry_b_number:
return 1
else:
return 0
# If there is no PR number, might as well just sort by text
else:
return -1 if entry_a < entry_b else 1

def get_sorted_unique_entries(entries) -> list:
"""Return a sorted list of unique entries"""
from functools import cmp_to_key
letter_cmp_key = cmp_to_key(changelog_entry_compare)
entries = list(set(entries))
entries.sort()
entries.sort(key=letter_cmp_key)
return [('{}{}'.format(g_prefix_line, entry) if entry else '') for entry in entries]

def get_updated_file_content(current_changelog_lines: str, new_change: any, new_user: any) -> list:
Expand Down