Skip to content

Commit 1bacce4

Browse files
authored
Merge pull request #7056 from jf205/sarif-query-help
Add new option to database analyze tutorial
2 parents 954fd8d + 96ff2f5 commit 1bacce4

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ You can also specify:
6363
language to the GitHub code scanning API. For more information about this use case,
6464
see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system>`__ in the GitHub documentation.
6565

66+
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
67+
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
68+
converted to ``.md`` before running the analysis. For further information,
69+
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
70+
6671
- .. include:: ../reusables/threads-query-execution.rst
6772

6873

@@ -201,6 +206,29 @@ A SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
201206
that the results are formatted according to the most recent SARIF specification
202207
supported by CodeQL.
203208

209+
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
210+
211+
Including query help for custom CodeQL queries in SARIF files
212+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213+
214+
If you use the CodeQL CLI to to run code scanning analyses on third party CI/CD systems,
215+
you can include the query help for your custom queries in SARIF files generated during an analysis.
216+
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
217+
alerts generated by the custom queries.
218+
219+
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
220+
by providing the ``--sarif-add-query-help`` option when running
221+
``codeql database analyze``.
222+
For more information, see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#analyzing-a-codeql-database>`
223+
in the GitHub documentation.
224+
225+
You can write query help for custom queries directly in a markdown file and save it alongside the
226+
corresponding query. Alternatively, for consistency with the standard CodeQL queries,
227+
you can write query help in the ``.qhelp`` format. Query help written in ``.qhelp``
228+
files can't be included in SARIF files, and they can't be processed by code
229+
scanning so must be converted to markdown before running
230+
the analysis. For more information, see ":ref:`Query help files <query-help-files>`"
231+
and ":doc:`Testing query help files <testing-query-help-files>`."
204232

205233
Results
206234
-------

docs/codeql/codeql-cli/testing-query-help-files.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ in the CodeQL repository.
1515
The CodeQL CLI includes a command to test query help and render the content as
1616
markdown, so that you can easily preview the content in your IDE. Use the command to validate
1717
query help files before uploading them to the CodeQL repository or sharing them with other users.
18+
From CodeQL CLI 2.7.1 onwards, you can also include the markdown-rendered query help in SARIF files
19+
generated during CodeQL analyses so that the query help can be displayed in the code scanning UI.
20+
For more information, see
21+
":ref:`Analyzing databases with the CodeQL CLI <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
1822

1923
Prerequisites
2024
-------------

docs/codeql/writing-codeql-queries/debugging-data-flow-queries-using-partial-flow.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ A typical data-flow query looks like this:
1010

1111
.. code-block:: ql
1212
13-
::
1413
1514
class MyConfig extends TaintTracking::Configuration {
1615
MyConfig() { this = "MyConfig" }
@@ -79,7 +78,8 @@ To avoid these problems, a data-flow ``Configuration`` comes with a mechanism fo
7978
*/
8079
final predicate hasPartialFlow(PartialPathNode source, PartialPathNode node, int dist) {
8180
82-
As noted in the documentation for ``hasPartialFlow`` (for example, in the `CodeQL for Java documentation <https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/dataflow/internal/DataFlowImpl2.qll/predicate.DataFlowImpl2$Configuration$hasPartialFlow.3.html>__`) you must first enable this by adding an override of ``explorationLimit``. For example:
81+
As noted in the documentation for ``hasPartialFlow`` (for example, in the
82+
`CodeQL for Java documentation <https://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/dataflow/internal/DataFlowImpl2.qll/predicate.DataFlowImpl2$Configuration$hasPartialFlow.3.html>`__) you must first enable this by adding an override of ``explorationLimit``. For example:
8383

8484
.. code-block:: ql
8585

docs/codeql/writing-codeql-queries/query-help-files.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ Query help files are written using a custom XML format, and stored in a file wit
4040
The header and single top-level ``qhelp`` element are both mandatory.
4141
The following sections explain additional elements that you may include in your query help files.
4242

43+
.. pull-quote::
44+
45+
Code scanning does not process ``.qhelp`` files for custom CodeQL queries, so to show
46+
query help for custom queries in the code scanning UI you must convert the ``.qhelp`` files to markdown
47+
and then include the markdown-rendered query help in SARIF files generated during an analysis.
48+
For more information, see
49+
":ref:`Analyzing databases with the CodeQL CLI <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
4350

4451
Section-level elements
4552
======================

0 commit comments

Comments
 (0)