Skip to content

Commit f5ae008

Browse files
author
james
committed
rebase on rc/1.26 branch
1 parent f2b1774 commit f5ae008

13 files changed

Lines changed: 93 additions & 86 deletions

File tree

.github/workflows/generate-query-help-docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- 'lgtm.com'
99
pull_request:
1010
paths:
11-
- 'docs/language/query-help/**'
11+
- 'docs/codeql/query-help/**'
1212

1313
jobs:
1414
build:
@@ -38,10 +38,10 @@ jobs:
3838
run: unzip -d codeql-cli codeql-linux64.zip
3939
- name: Set up query help docs folder
4040
run: |
41-
cp -r codeql/docs/language/query-help/ . ; cp -r codeql/docs/language/global-sphinx-files/ .
41+
cp -r codeql/docs/codeql/** .
4242
- name: Query help to markdown
4343
run: |
44-
PATH="$PATH:codeql-cli/codeql" python codeql/docs/language/query-help-markdown.py
44+
PATH="$PATH:codeql-cli/codeql" python codeql/docs/codeql/query-help-markdown.py
4545
- name: Run Sphinx for query help
4646
uses: ammaraskar/sphinx-action@master
4747
with:

docs/codeql/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@ def setup(sphinx):
109109
# so a file named "default.css" will overwrite the builtin "default.css".
110110
html_static_path = ['_static']
111111

112-
exclude_patterns = ['vale*', '_static', '_templates', 'codeql', 'learn-ql', 'reusables', 'images', 'support', 'ql-training', '_build', '*.py*', 'README.rst']
112+
exclude_patterns = ['vale*', '_static', '_templates', 'reusables', 'images', 'support', 'ql-training', 'query-help','_build', '*.py*', 'README.rst']
113113
##############################################################################
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
# Define which languages and query packs to consider
2222
languages = [ "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
2625
packs = ["lgtm"]
2726

2827
def 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

112111
codeql_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.
116114
try:
@@ -127,11 +125,18 @@ def subprocess_run(cmd):
127125
# Iterate over all languages and packs, and resolve which queries are part of those packs
128126
for 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

docs/codeql/query-help/conf.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# CodeQL query help configuration file
4+
#
5+
# This file is execfile()d with the current directory set to its
6+
# containing dir.
7+
#
8+
# Note that not all possible configuration values are present in this
9+
# autogenerated file.
10+
#
11+
# All configuration values have a default; values that are commented out
12+
# serve to show the default.
13+
14+
# For details of all possible config values,
15+
# see https://www.sphinx-doc.org/en/master/usage/configuration.html
16+
17+
# -- Project-specific configuration -----------------------------------
18+
19+
# The master toctree document.
20+
master_doc = 'index'
21+
22+
# General information about the project.
23+
project = u'CodeQL query help'
24+
25+
# Add md parser to process query help markdown files
26+
extensions =['recommonmark']
27+
28+
source_suffix = {
29+
'.rst': 'restructuredtext',
30+
'.md': 'markdown',
31+
}
32+
33+
# -- Project-specifc options for HTML output ----------------------------------------------
34+
35+
# Theme options are theme-specific and customize the look and feel of a theme
36+
# further. For a list of options available for each theme, see the
37+
# documentation.
38+
html_theme_options = {'font_size': '16px',
39+
'body_text': '#333',
40+
'link': '#2F1695',
41+
'link_hover': '#2F1695',
42+
'show_powered_by': False,
43+
'nosidebar':True,
44+
'head_font_family': '-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"',
45+
}
46+
47+
highlight_language = "none"
48+
49+
# Add any paths that contain templates here, relative to this directory.
50+
templates_path = ['../_templates']
51+
52+
# Add any paths that contain custom static files (such as style sheets) here,
53+
# relative to this directory. They are copied after the builtin static files,
54+
# so a file named "default.css" will overwrite the builtin "default.css".
55+
html_static_path = ['../_static']
56+
57+
# List of patterns, relative to source directory, that match files and
58+
# directories to ignore when looking for source files.
59+
60+
exclude_patterns = ['toc-*'] # ignore toc-<lang>.rst files as they are 'included' in index pages
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)