Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script and VSCode task for creating change notes #18086

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines +87 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the categories differ between library changes and query changes: https://github.com/github/codeql/blob/main/docs/change-notes.md

]
}
]
}
51 changes: 51 additions & 0 deletions misc/scripts/create-change-note.py
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about query changes? Which should go in {language}/ql/src/change-notes?


# 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}")