From addef2f1713ed270a56855304e46599e2c2b9d03 Mon Sep 17 00:00:00 2001 From: Taus Date: Fri, 22 Nov 2024 22:32:15 +0000 Subject: [PATCH 1/3] Add script and VSCode task for creating change notes Adds a VSCode Task (accessible from the "Run Task" menu) for creating change notes, prompting the user for the language, name, and category of the change. The language options presented are based on the existing occurrences of `change-notes` folders in the repo. There are more such files (in particular every shared library has a `change-notes` directory), but it seemed to me that the language change notes are the ones that are most common, and so in an effort to not clutter the list too much, I only included the languages. The selection of categories is based on existing usage -- more specifically the result of grepping for occurrences of '^category: ' in the repo. It's possible there are more change categories that could be added. Hopefully this should make it more convenient to create change notes from within VSCode. --- .vscode/tasks.json | 52 ++++++++++++++++++++++++++++++ misc/scripts/create-change-note.py | 51 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 misc/scripts/create-change-note.py diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 68df2f6f498b..9737e18c6927 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -38,6 +38,58 @@ "command": "${config:python.pythonPath}", }, "problemMatcher": [] + }, + { + "label": "Create change note", + "type": "process", + "command": "python3", + "args": [ + "misc/scripts/create-change-note.py", + "${input:language}", + "${input:name}", + "${input:category}" + ], + "presentation": { + "reveal": "never", + "close": true + }, + "problemMatcher": [] + } + ], + "inputs": [ + { + "type": "pickString", + "id": "language", + "description": "Language", + "options": + [ + "go", + "java", + "javascript", + "cpp", + "csharp", + "python", + "ruby", + "swift", + ] + }, + { + "type": "promptString", + "id": "name", + "description": "Name" + }, + { + "type": "pickString", + "id": "category", + "description": "Category", + "options": + [ + "minorAnalysis", + "newQuery", + "fix", + "majorAnalysis", + "breaking", + ] } ] } diff --git a/misc/scripts/create-change-note.py b/misc/scripts/create-change-note.py new file mode 100644 index 000000000000..bf82b76a18ad --- /dev/null +++ b/misc/scripts/create-change-note.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +# Creates a change note and opens it in VSCode for editing. + +# Expects to receive the following arguments: +# - What language the change note is for +# - The name of the change note (in kebab-case) +# - The category of the change. + +# The change note will be created in the `{language}/ql/lib/change-notes` directory. + +# The format of the change note filename is `{current_date}-{change_note_name}.md` with the date in +# the format `YYYY-MM-DD`. + +import sys +import os + +# Read the given arguments +language = sys.argv[1] +change_note_name = sys.argv[2] +change_category = sys.argv[3] + +# Find the root of the repository. The current script should be located in `misc/scripts`. +root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +# Go to the repo root +os.chdir(root) + +# Abort if the output directory doesn't exist +if not os.path.exists(f"{language}/ql/lib/change-notes"): + print(f"Output directory {language}/ql/lib/change-notes does not exist") + sys.exit(1) + +# Get the current date +import datetime +current_date = datetime.datetime.now().strftime("%Y-%m-%d") + +# Create the change note file +change_note_file = f"{language}/ql/lib/change-notes/{current_date}-{change_note_name}.md" + +change_note = f""" +--- +category: {change_category} +--- +* """.lstrip() + +with open(change_note_file, "w") as f: + f.write(change_note) + +# Open the change note file in VSCode, reusing the existing window if possible +os.system(f"code -r {change_note_file}") From adbd4d35edcc1e953432f96e0e1a50556d6bb32c Mon Sep 17 00:00:00 2001 From: Taus Date: Tue, 26 Nov 2024 12:38:16 +0000 Subject: [PATCH 2/3] Add support for both query and library change notes --- .vscode/tasks.json | 49 +++++++++++++++++++++++++----- misc/scripts/create-change-note.py | 14 ++++++--- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9737e18c6927..5d9a735d379f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -40,14 +40,32 @@ "problemMatcher": [] }, { - "label": "Create change note", + "label": "Create query change note", "type": "process", "command": "python3", "args": [ "misc/scripts/create-change-note.py", "${input:language}", + "src", "${input:name}", - "${input:category}" + "${input:categoryQuery}" + ], + "presentation": { + "reveal": "never", + "close": true + }, + "problemMatcher": [] + }, + { + "label": "Create library change note", + "type": "process", + "command": "python3", + "args": [ + "misc/scripts/create-change-note.py", + "${input:language}", + "lib", + "${input:name}", + "${input:categoryLibrary}" ], "presentation": { "reveal": "never", @@ -70,25 +88,42 @@ "csharp", "python", "ruby", + "rust", "swift", ] }, { "type": "promptString", "id": "name", - "description": "Name" + "description": "Short name (kebab-case)" }, { "type": "pickString", - "id": "category", - "description": "Category", + "id": "categoryQuery", + "description": "Category (query change)", "options": [ - "minorAnalysis", + "breaking", + "deprecated", "newQuery", - "fix", + "queryMetadata", "majorAnalysis", + "minorAnalysis", + "fix", + ] + }, + { + "type": "pickString", + "id": "categoryLibrary", + "description": "Category (library change)", + "options": + [ "breaking", + "deprecated", + "feature", + "majorAnalysis", + "minorAnalysis", + "fix", ] } ] diff --git a/misc/scripts/create-change-note.py b/misc/scripts/create-change-note.py index bf82b76a18ad..a7a64e76f4ce 100644 --- a/misc/scripts/create-change-note.py +++ b/misc/scripts/create-change-note.py @@ -4,6 +4,7 @@ # Expects to receive the following arguments: # - What language the change note is for +# - Whether it's a query or library change (the string `src` or `lib`) # - The name of the change note (in kebab-case) # - The category of the change. @@ -17,8 +18,9 @@ # Read the given arguments language = sys.argv[1] -change_note_name = sys.argv[2] -change_category = sys.argv[3] +subdir = sys.argv[2] +change_note_name = sys.argv[3] +change_category = sys.argv[4] # Find the root of the repository. The current script should be located in `misc/scripts`. root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -26,9 +28,11 @@ # Go to the repo root os.chdir(root) +output_dir = f"{language}/ql/{subdir}/change-notes" + # Abort if the output directory doesn't exist -if not os.path.exists(f"{language}/ql/lib/change-notes"): - print(f"Output directory {language}/ql/lib/change-notes does not exist") +if not os.path.exists(output_dir): + print(f"Output directory {output_dir} does not exist") sys.exit(1) # Get the current date @@ -36,7 +40,7 @@ current_date = datetime.datetime.now().strftime("%Y-%m-%d") # Create the change note file -change_note_file = f"{language}/ql/lib/change-notes/{current_date}-{change_note_name}.md" +change_note_file = f"{output_dir}/{current_date}-{change_note_name}.md" change_note = f""" --- From 5279857d060ade6146b984cf0738162cb2114229 Mon Sep 17 00:00:00 2001 From: Taus Date: Tue, 26 Nov 2024 12:48:20 +0000 Subject: [PATCH 3/3] Fix comment --- misc/scripts/create-change-note.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/scripts/create-change-note.py b/misc/scripts/create-change-note.py index a7a64e76f4ce..548fa4e87fb0 100644 --- a/misc/scripts/create-change-note.py +++ b/misc/scripts/create-change-note.py @@ -8,7 +8,7 @@ # - The name of the change note (in kebab-case) # - The category of the change. -# The change note will be created in the `{language}/ql/lib/change-notes` directory. +# The change note will be created in the `{language}/ql/{subdir}/change-notes` directory, where `subdir` is either `src` or `lib`. # The format of the change note filename is `{current_date}-{change_note_name}.md` with the date in # the format `YYYY-MM-DD`.