2121# Define which languages and query packs to consider
2222languages = [ "cpp" , "csharp" , "go" , "java" , "javascript" , "python" ]
2323
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
2625packs = ["lgtm" ]
2726
2827def prefix_repo_nwo (filename ):
@@ -110,7 +109,6 @@ def subprocess_run(cmd):
110109# (and assumes the codeql-go repo is in a similar location)
111110
112111codeql_search_path = "./codeql:./codeql-go" # will be extended further down
113-
114112# Extend CodeQL search path by detecting root of the current Git repo (if any). This means that you
115113# can run this script from any location within the CodeQL git repository.
116114try :
@@ -127,11 +125,18 @@ def subprocess_run(cmd):
127125# Iterate over all languages and packs, and resolve which queries are part of those packs
128126for lang in languages :
129127
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 ()
130134 # Define empty dictionary to store @name:filename pairs to generate alphabetically sorted Sphinx toctree
131135 index_file_dictionary = {}
132136 for pack in packs :
133137 # Get absolute paths to queries in this pack by using 'codeql resolve queries'
134138 try :
139+
135140 queries_subp = subprocess_run (
136141 ["codeql" , "resolve" , "queries" , "--search-path" , codeql_search_path , "%s-%s.qls" % (lang , pack )])
137142 except Exception as e :
@@ -189,18 +194,34 @@ def subprocess_run(cmd):
189194 "codeql" , "codeql/tree/main" ).replace (" " , "%20" ).replace ("\\ " , "/" )
190195 query_link = "[Click to see the query in the CodeQL repository](https://github.com/" + \
191196 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 = ""
192215
193216 # Join metadata into a literal block and add query link below
194217 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 "
196219
197220 # Insert metadata block into query help directly under title
198221 full_help = query_help .replace ("\n " , meta_string , 1 )
199222
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 ("/" , "-" )
204225
205226 # Populate index_file_dictionary with @name extracted from metadata and corresponding query filename
206227 index_file_dictionary [query_name_meta ] = lang + "/" + query_name
0 commit comments