21
21
# Define which languages and query packs to consider
22
22
languages = [ "cpp" , "csharp" , "go" , "java" , "javascript" , "python" ]
23
23
24
- # Query suites to generate help for
25
- # lgtm-full suites covers all queries used in code scanning and on lgtm.com plus a few more
24
+ # Query suites to generate help for - lgtm suite should cover the queries that users are interested in
26
25
packs = ["lgtm" ]
27
26
28
27
def prefix_repo_nwo (filename ):
@@ -110,7 +109,6 @@ def subprocess_run(cmd):
110
109
# (and assumes the codeql-go repo is in a similar location)
111
110
112
111
codeql_search_path = "./codeql:./codeql-go" # will be extended further down
113
-
114
112
# Extend CodeQL search path by detecting root of the current Git repo (if any). This means that you
115
113
# can run this script from any location within the CodeQL git repository.
116
114
try :
@@ -127,11 +125,18 @@ def subprocess_run(cmd):
127
125
# Iterate over all languages and packs, and resolve which queries are part of those packs
128
126
for lang in languages :
129
127
128
+ code_scanning_queries = subprocess_run (
129
+ ["codeql" , "resolve" , "queries" , "--search-path" , codeql_search_path , "%s-code-scanning.qls" % (lang )]).stdout .strip ()
130
+ security_extended_queries = subprocess_run (
131
+ ["codeql" , "resolve" , "queries" , "--search-path" , codeql_search_path , "%s-security-extended.qls" % (lang )]).stdout .strip ()
132
+ security_and_quality_queries = subprocess_run (
133
+ ["codeql" , "resolve" , "queries" , "--search-path" , codeql_search_path , "%s-security-and-quality.qls" % (lang )]).stdout .strip ()
130
134
# Define empty dictionary to store @name:filename pairs to generate alphabetically sorted Sphinx toctree
131
135
index_file_dictionary = {}
132
136
for pack in packs :
133
137
# Get absolute paths to queries in this pack by using 'codeql resolve queries'
134
138
try :
139
+
135
140
queries_subp = subprocess_run (
136
141
["codeql" , "resolve" , "queries" , "--search-path" , codeql_search_path , "%s-%s.qls" % (lang , pack )])
137
142
except Exception as e :
@@ -189,18 +194,34 @@ def subprocess_run(cmd):
189
194
"codeql" , "codeql/tree/main" ).replace (" " , "%20" ).replace ("\\ " , "/" )
190
195
query_link = "[Click to see the query in the CodeQL repository](https://github.com/" + \
191
196
transform_link + ")\n "
197
+
198
+ if queryfile in code_scanning_queries :
199
+ cs_suites = lang + '-code-scanning.qls '
200
+ else :
201
+ cs_suites = ""
202
+ if queryfile in security_extended_queries :
203
+ se_suites = lang + '-security-extended.qls '
204
+ else :
205
+ se_suites = ""
206
+ if queryfile in security_and_quality_queries :
207
+ sq_suites = lang + '-security-and-quality.qls '
208
+ else :
209
+ sq_Suites = ""
210
+
211
+ if queryfile in code_scanning_queries or queryfile in security_extended_queries or queryfile in security_and_quality_queries :
212
+ suites_list = "Query suites: " + cs_suites + se_suites + sq_suites + "\n "
213
+ else :
214
+ suites_list = ""
192
215
193
216
# Join metadata into a literal block and add query link below
194
217
meta_string = "\n " * 2 + "```\n " + query_id + query_kind + query_severity + \
195
- query_precision + query_tags + "```\n \n " + query_link + "\n "
218
+ query_precision + query_tags + suites_list + "```\n \n " + query_link + "\n "
196
219
197
220
# Insert metadata block into query help directly under title
198
221
full_help = query_help .replace ("\n " , meta_string , 1 )
199
222
200
- # Use id property (without language code) to make name for markdown file
201
- s = query_id .index ("/" )
202
- # replace "/" with "-"
203
- query_name = query_id [s + 1 :- 1 ].replace ("/" , "-" )
223
+ # Use id property to make name for markdown file, replacing any "/" characters with "-"
224
+ query_name = query_id [4 :- 1 ].replace ("/" , "-" )
204
225
205
226
# Populate index_file_dictionary with @name extracted from metadata and corresponding query filename
206
227
index_file_dictionary [query_name_meta ] = lang + "/" + query_name
0 commit comments