Skip to content

Commit 047e974

Browse files
authored
Merge pull request github#18086 from github/tausbn/add-vscode-task-for-creating-change-notes
Add script and VSCode task for creating change notes
2 parents 9f09454 + 5279857 commit 047e974

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

.vscode/tasks.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,93 @@
3838
"command": "${config:python.pythonPath}",
3939
},
4040
"problemMatcher": []
41+
},
42+
{
43+
"label": "Create query change note",
44+
"type": "process",
45+
"command": "python3",
46+
"args": [
47+
"misc/scripts/create-change-note.py",
48+
"${input:language}",
49+
"src",
50+
"${input:name}",
51+
"${input:categoryQuery}"
52+
],
53+
"presentation": {
54+
"reveal": "never",
55+
"close": true
56+
},
57+
"problemMatcher": []
58+
},
59+
{
60+
"label": "Create library change note",
61+
"type": "process",
62+
"command": "python3",
63+
"args": [
64+
"misc/scripts/create-change-note.py",
65+
"${input:language}",
66+
"lib",
67+
"${input:name}",
68+
"${input:categoryLibrary}"
69+
],
70+
"presentation": {
71+
"reveal": "never",
72+
"close": true
73+
},
74+
"problemMatcher": []
75+
}
76+
],
77+
"inputs": [
78+
{
79+
"type": "pickString",
80+
"id": "language",
81+
"description": "Language",
82+
"options":
83+
[
84+
"go",
85+
"java",
86+
"javascript",
87+
"cpp",
88+
"csharp",
89+
"python",
90+
"ruby",
91+
"rust",
92+
"swift",
93+
]
94+
},
95+
{
96+
"type": "promptString",
97+
"id": "name",
98+
"description": "Short name (kebab-case)"
99+
},
100+
{
101+
"type": "pickString",
102+
"id": "categoryQuery",
103+
"description": "Category (query change)",
104+
"options":
105+
[
106+
"breaking",
107+
"deprecated",
108+
"newQuery",
109+
"queryMetadata",
110+
"majorAnalysis",
111+
"minorAnalysis",
112+
"fix",
113+
]
114+
},
115+
{
116+
"type": "pickString",
117+
"id": "categoryLibrary",
118+
"description": "Category (library change)",
119+
"options":
120+
[
121+
"breaking",
122+
"deprecated",
123+
"feature",
124+
"majorAnalysis",
125+
"minorAnalysis",
126+
"fix",
127+
]
41128
}
42129
]
43130
}

misc/scripts/create-change-note.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)