Skip to content

Commit addef2f

Browse files
committed
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.
1 parent 7baaa23 commit addef2f

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

.vscode/tasks.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,58 @@
3838
"command": "${config:python.pythonPath}",
3939
},
4040
"problemMatcher": []
41+
},
42+
{
43+
"label": "Create change note",
44+
"type": "process",
45+
"command": "python3",
46+
"args": [
47+
"misc/scripts/create-change-note.py",
48+
"${input:language}",
49+
"${input:name}",
50+
"${input:category}"
51+
],
52+
"presentation": {
53+
"reveal": "never",
54+
"close": true
55+
},
56+
"problemMatcher": []
57+
}
58+
],
59+
"inputs": [
60+
{
61+
"type": "pickString",
62+
"id": "language",
63+
"description": "Language",
64+
"options":
65+
[
66+
"go",
67+
"java",
68+
"javascript",
69+
"cpp",
70+
"csharp",
71+
"python",
72+
"ruby",
73+
"swift",
74+
]
75+
},
76+
{
77+
"type": "promptString",
78+
"id": "name",
79+
"description": "Name"
80+
},
81+
{
82+
"type": "pickString",
83+
"id": "category",
84+
"description": "Category",
85+
"options":
86+
[
87+
"minorAnalysis",
88+
"newQuery",
89+
"fix",
90+
"majorAnalysis",
91+
"breaking",
92+
]
4193
}
4294
]
4395
}

misc/scripts/create-change-note.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
# - The name of the change note (in kebab-case)
8+
# - The category of the change.
9+
10+
# The change note will be created in the `{language}/ql/lib/change-notes` directory.
11+
12+
# The format of the change note filename is `{current_date}-{change_note_name}.md` with the date in
13+
# the format `YYYY-MM-DD`.
14+
15+
import sys
16+
import os
17+
18+
# Read the given arguments
19+
language = sys.argv[1]
20+
change_note_name = sys.argv[2]
21+
change_category = sys.argv[3]
22+
23+
# Find the root of the repository. The current script should be located in `misc/scripts`.
24+
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
25+
26+
# Go to the repo root
27+
os.chdir(root)
28+
29+
# Abort if the output directory doesn't exist
30+
if not os.path.exists(f"{language}/ql/lib/change-notes"):
31+
print(f"Output directory {language}/ql/lib/change-notes does not exist")
32+
sys.exit(1)
33+
34+
# Get the current date
35+
import datetime
36+
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
37+
38+
# Create the change note file
39+
change_note_file = f"{language}/ql/lib/change-notes/{current_date}-{change_note_name}.md"
40+
41+
change_note = f"""
42+
---
43+
category: {change_category}
44+
---
45+
* """.lstrip()
46+
47+
with open(change_note_file, "w") as f:
48+
f.write(change_note)
49+
50+
# Open the change note file in VSCode, reusing the existing window if possible
51+
os.system(f"code -r {change_note_file}")

0 commit comments

Comments
 (0)