|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Creates a change note and opens it in VSCode for editing. |
| 4 | + |
| 5 | +# Expects to receive the following arguments: |
| 6 | +# - What language the change note is for |
| 7 | +# - Whether it's a query or library change (the string `src` or `lib`) |
| 8 | +# - The name of the change note (in kebab-case) |
| 9 | +# - The category of the change. |
| 10 | + |
| 11 | +# The change note will be created in the `{language}/ql/{subdir}/change-notes` directory, where `subdir` is either `src` or `lib`. |
| 12 | + |
| 13 | +# The format of the change note filename is `{current_date}-{change_note_name}.md` with the date in |
| 14 | +# the format `YYYY-MM-DD`. |
| 15 | + |
| 16 | +import sys |
| 17 | +import os |
| 18 | + |
| 19 | +# Read the given arguments |
| 20 | +language = sys.argv[1] |
| 21 | +subdir = sys.argv[2] |
| 22 | +change_note_name = sys.argv[3] |
| 23 | +change_category = sys.argv[4] |
| 24 | + |
| 25 | +# Find the root of the repository. The current script should be located in `misc/scripts`. |
| 26 | +root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 27 | + |
| 28 | +# Go to the repo root |
| 29 | +os.chdir(root) |
| 30 | + |
| 31 | +output_dir = f"{language}/ql/{subdir}/change-notes" |
| 32 | + |
| 33 | +# Abort if the output directory doesn't exist |
| 34 | +if not os.path.exists(output_dir): |
| 35 | + print(f"Output directory {output_dir} does not exist") |
| 36 | + sys.exit(1) |
| 37 | + |
| 38 | +# Get the current date |
| 39 | +import datetime |
| 40 | +current_date = datetime.datetime.now().strftime("%Y-%m-%d") |
| 41 | + |
| 42 | +# Create the change note file |
| 43 | +change_note_file = f"{output_dir}/{current_date}-{change_note_name}.md" |
| 44 | + |
| 45 | +change_note = f""" |
| 46 | +--- |
| 47 | +category: {change_category} |
| 48 | +--- |
| 49 | +* """.lstrip() |
| 50 | + |
| 51 | +with open(change_note_file, "w") as f: |
| 52 | + f.write(change_note) |
| 53 | + |
| 54 | +# Open the change note file in VSCode, reusing the existing window if possible |
| 55 | +os.system(f"code -r {change_note_file}") |
0 commit comments