Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
codeql/misc/scripts/create-change-note.py at codeql-cli/v2.27.1 · github/codeql · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
codeql
Repository navigation
Code
Issues
1k
(1k)
Pull requests
485
(485)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
codeql-cli/v2.27.1
Breadcrumbs
codeql
/
misc
/
scripts
/
create-change-note.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
159 lines (125 loc) · 4.32 KB
codeql-cli/v2.27.1
Breadcrumbs
codeql
/
misc
/
scripts
/
create-change-note.py
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
159 lines (125 loc) · 4.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python3
# Creates a change note and opens it in $EDITOR (or VSCode if the environment
# variable is not set) for editing.
# 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 (see https://github.com/github/codeql/blob/main/docs/change-notes.md#change-categories).
# Alternatively, run without arguments for interactive mode.
# 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`.
import
sys
import
os
LANGUAGES
=
[
"actions"
,
"cpp"
,
"csharp"
,
"go"
,
"java"
,
"javascript"
,
"python"
,
"ruby"
,
"rust"
,
"swift"
,
]
SUBDIRS
=
{
"src"
:
"query"
,
"lib"
:
"library"
,
}
CATEGORIES_QUERY
=
[
"breaking"
,
"deprecated"
,
"newQuery"
,
"queryMetadata"
,
"majorAnalysis"
,
"minorAnalysis"
,
"fix"
,
]
CATEGORIES_LIBRARY
=
[
"breaking"
,
"deprecated"
,
"feature"
,
"majorAnalysis"
,
"minorAnalysis"
,
"fix"
,
]
def
is_subsequence
(
needle
:
str
,
haystack
:
str
)
->
bool
:
"""Check if needle is a subsequence of haystack (case-insensitive)."""
it
=
iter
(
haystack
.
lower
())
return
all
(
c
in
it
for
c
in
needle
.
lower
())
def
pick_option
(
prompt
:
str
,
options
:
list
[
str
])
->
str
:
"""Display options and let the user pick by subsequence match."""
print
(
f"
\n
{
prompt
}
"
)
print
(
f" Options:
{
', '
.
join
(
options
)
}
"
)
while
True
:
choice
=
input
(
"Choice: "
).
strip
()
if
not
choice
:
continue
# Try exact match first
for
o
in
options
:
if
o
.
lower
()
==
choice
.
lower
():
return
o
# Try subsequence match
matches
=
[
o
for
o
in
options
if
is_subsequence
(
choice
,
o
)]
if
len
(
matches
)
==
1
:
return
matches
[
0
]
if
len
(
matches
)
>
1
:
print
(
f" Ambiguous:
{
', '
.
join
(
matches
)
}
"
)
continue
print
(
f" No match for '
{
choice
}
'. Try again."
)
def
prompt_string
(
prompt
:
str
)
->
str
:
"""Prompt the user for a string value."""
while
True
:
value
=
input
(
f"
\n
{
prompt
}
: "
).
strip
()
if
value
:
return
value
print
(
"Value cannot be empty."
)
def
interactive_mode
()
->
tuple
[
str
,
str
,
str
,
str
]:
"""Run interactive mode to gather all required inputs."""
print
(
"=== Create Change Note (Interactive Mode) ==="
)
language
=
pick_option
(
"Select language:"
,
LANGUAGES
)
subdir
=
pick_option
(
"Change type:"
,
list
(
SUBDIRS
.
keys
()))
change_note_name
=
prompt_string
(
"Short name (kebab-case)"
)
if
subdir
==
"src"
:
categories
=
CATEGORIES_QUERY
else
:
categories
=
CATEGORIES_LIBRARY
change_category
=
pick_option
(
"Select category:"
,
categories
)
return
language
,
subdir
,
change_note_name
,
change_category
# Check if running in interactive mode (no arguments) or with arguments
if
len
(
sys
.
argv
)
==
1
:
language
,
subdir
,
change_note_name
,
change_category
=
interactive_mode
()
elif
len
(
sys
.
argv
)
==
5
:
language
=
sys
.
argv
[
1
]
subdir
=
sys
.
argv
[
2
]
change_note_name
=
sys
.
argv
[
3
]
change_category
=
sys
.
argv
[
4
]
else
:
print
(
"Usage: create-change-note.py [language subdir name category]"
)
print
(
" Run without arguments for interactive mode."
)
sys
.
exit
(
1
)
# 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
)
output_dir
=
f"
{
language
}
/ql/
{
subdir
}
/change-notes"
# Abort if the output directory doesn't exist
if
not
os
.
path
.
exists
(
output_dir
):
print
(
f"Output directory
{
output_dir
}
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"
{
output_dir
}
/
{
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
)
editor
=
os
.
environ
.
get
(
'EDITOR'
,
'code -r'
)
os
.
system
(
f"
{
editor
}
{
change_note_file
}
"
)
You can’t perform that action at this time.