Skip to content

Commit

Permalink
Improve changelog sorting (TTLApp#1115)
Browse files Browse the repository at this point in the history
* Improve changelog sorting

* Update scripts/update-changelog.py
  • Loading branch information
tupaschoal authored Jan 12, 2025
1 parent a36015b commit 528d1dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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
31 changes: 30 additions & 1 deletion scripts/update-changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,39 @@ def remove_prefix(text: str, prefix: str) -> str:
"""Remove the prefix from the string"""
return re.sub(r'^{0}'.format(re.escape(prefix)), '', text)

# Looking for any of the entries with an ID, like "Enhancement [#948]..."
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

0 comments on commit 528d1dd

Please sign in to comment.