Skip to content

Commit

Permalink
Make changelog script able to manage admin changelogs (#24033)
Browse files Browse the repository at this point in the history
* Make changelog script able to manage admin changelogs

* I forgot to remove the comment

* Yeah that should probably just be an exclusion instead.

(cherry picked from commit 8302240)
  • Loading branch information
PJB3005 authored and DebugOk committed Jan 26, 2024
1 parent 27626cf commit c377ccf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Resources/Changelog/Parts/parts_here.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The part YAML takes the following format:

author: Your_Name_Here
category: Admin # if left out, falls under the main changelog
changes:
- type: Fix # One of the following: Add, Remove, Tweak, Fix
message: Your change here!

21 changes: 18 additions & 3 deletions Tools/update_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
HEADER_RE = r"(?::cl:|🆑) *\r?\n(.+)$"
ENTRY_RE = r"^ *[*-]? *(\S[^\n\r]+)\r?$"

CATEGORY_MAIN = "Main"

# From https://stackoverflow.com/a/37958106/4678631
class NoDatesSafeLoader(yaml.SafeLoader):
Expand All @@ -33,9 +34,12 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("changelog_file")
parser.add_argument("parts_dir")
parser.add_argument("--category", default=CATEGORY_MAIN)

args = parser.parse_args()

category = args.category

with open(args.changelog_file, "r", encoding="utf-8-sig") as f:
current_data = yaml.load(f, Loader=NoDatesSafeLoader)

Expand All @@ -54,7 +58,13 @@ def main():
partpath = os.path.join(args.parts_dir, partname)
print(partpath)

partyaml = yaml.load(open(partpath, "r", encoding="utf-8-sig"), Loader=NoDatesSafeLoader)
with open(partpath, "r", encoding="utf-8-sig") as f:
partyaml = yaml.load(f, Loader=NoDatesSafeLoader)

part_category = partyaml.get("category", CATEGORY_MAIN)
if part_category != category:
print(f"Skipping: wrong category ({part_category} vs {category})")
continue

author = partyaml["author"]
time = partyaml.get(
Expand Down Expand Up @@ -86,8 +96,13 @@ def main():
print(f"Removing {overflow} old entries.")
entries_list = entries_list[overflow:]

with open(args.changelog_file, "w") as f:
yaml.safe_dump({"Entries": entries_list}, f)
new_data = {"Entries": entries_list}
for key, value in current_data.items():
if key != "Entries":
new_data[key] = value

with open(args.changelog_file, "w", encoding="utf-8-sig") as f:
yaml.safe_dump(new_data, f)


main()

0 comments on commit c377ccf

Please sign in to comment.