Skip to content

Commit 3e5905a

Browse files
authored
Code scanning: Using the CodeQL runner to scan PRs
1 parent 400f24a commit 3e5905a

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

content/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-codeql-code-scanning-in-your-ci-system.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ There are three versions of the {% data variables.product.prodname_codeql_runner
3030

3131
To customize the way the {% data variables.product.prodname_codeql_runner %} scans your code, you can use flags, such as `--languages` and `--queries`, or you can specify custom settings in a separate configuration file.
3232

33+
### Scanning pull requests
34+
35+
Scanning code whenever a pull request is created prevents developers from introducing new vulnerabilities and errors into the code.
36+
37+
To scan a pull request, run the `analyze` command and use the `--ref` flag to specify the pull request. The reference is `refs/pull/<pr-number>/head` or `refs/pull/<pr-number>/merge`, depending on whether you have checked out the HEAD commit of the pull request branch or a merge commit with the base branch.
38+
39+
```shell
40+
$ /path/to-runner/codeql-runner-linux analyze --ref refs/pull/42/head
41+
```
42+
3343
### Overriding automatic language detection
3444

3545
The {% data variables.product.prodname_codeql_runner %} automatically detects and scans code written in the supported languages.
@@ -116,7 +126,7 @@ Initializes the {% data variables.product.prodname_codeql_runner %} and creates
116126
| `--queries` | | Comma-separated list of additional queries to run, in addition to the default suite of security queries. |
117127
| `--config-file` | | Path to custom configuration file. |
118128
| `--codeql-path` | | Path to a copy of the {% data variables.product.prodname_codeql %} CLI executable to use. By default, the {% data variables.product.prodname_codeql_runner %} downloads a copy. |
119-
| `--temp-dir` | | Directory where temporary files are stored. The default is _./codeql-runner_. |
129+
| `--temp-dir` | | Directory where temporary files are stored. The default is `./codeql-runner`. |
120130
| `--tools-dir` | | Directory where {% data variables.product.prodname_codeql %} tools and other files are stored between runs. The default is a subdirectory of the home directory. |
121131
| <nobr>`--checkout-path`</nobr> | | The path to the checkout of your repository. The default is the current working directory. |
122132
| `--debug` | | None. Prints more verbose output. |
@@ -129,7 +139,7 @@ Attempts to build the code for the compiled languages C/C++, C#, and Java. For t
129139
| Flag | Required | Input value |
130140
| ---- |:--------:| ----------- |
131141
| `--language` | | The language to build. By default, the {% data variables.product.prodname_codeql_runner %} builds the compiled language with the most files. |
132-
| <nobr>`--temp-dir`</nobr> | | Directory where temporary files are stored. The default is _./codeql-runner_. |
142+
| <nobr>`--temp-dir`</nobr> | | Directory where temporary files are stored. The default is `./codeql-runner`. |
133143
| `--debug` | | None. Prints more verbose output. |
134144
| `-h`, `--help` | | None. Displays help for the command. |
135145

@@ -141,7 +151,7 @@ Analyzes the code in the {% data variables.product.prodname_codeql %} databases
141151
| ---- |:--------:| ----------- |
142152
| `--repository` || Name of the repository to analyze. |
143153
| `--commit` || SHA of the commit to analyze. In Git and in Azure DevOps, this corresponds to the value of `git rev-parse HEAD`. In Jenkins, this corresponds to `$GIT_COMMIT`. |
144-
| `--ref` || Name of the reference to analyze, for example `refs/heads/main`. In Git and in Jenkins, this corresponds to the value of `git symbolic-ref HEAD`. In Azure DevOps, this corresponds to `$(Build.SourceBranch)`. |
154+
| `--ref` || Name of the reference to analyze, for example `refs/heads/main` or `refs/pull/42/merge`. In Git or in Jenkins, this corresponds to the value of `git symbolic-ref HEAD`. In Azure DevOps, this corresponds to `$(Build.SourceBranch)`. |
145155
| `--github-url` || URL of the {% data variables.product.prodname_dotcom %} instance where your repository is hosted. |
146156
| `--github-auth` || A {% data variables.product.prodname_github_apps %} token or personal access token. |
147157
| <nobr>`--checkout-path`</nobr> | | The path to the checkout of your repository. The default is the current working directory. |
@@ -150,20 +160,26 @@ Analyzes the code in the {% data variables.product.prodname_codeql %} databases
150160
| `--ram` | | Amount of memory to use when running queries. The default is to use all available memory. |
151161
| <nobr>`--no-add-snippets`</nobr> | | None. Excludes code snippets from the SARIF output. |
152162
| `--threads` | | Number of threads to use when running queries. The default is to use all available cores. |
153-
| `--temp-dir` | | Directory where temporary files are stored. The default is _./codeql-runner_. |
163+
| `--temp-dir` | | Directory where temporary files are stored. The default is `./codeql-runner`. |
154164
| `--debug` | | None. Prints more verbose output. |
155165
| `-h`, `--help` | | None. Displays help for the command. |
156166

157167
#### `upload`
158168

159169
Uploads SARIF files to {% data variables.product.product_location %}.
160170

171+
{% note %}
172+
173+
**Note**: If you analyze code with the CodeQL runner, the `analyze` command uploads SARIF results by default. You can use the `upload` command to upload SARIF results that were generated by other tools.
174+
175+
{% endnote %}
176+
161177
| Flag | Required | Input value |
162178
| ---- |:--------:| ----------- |
163179
| `--sarif-file` || SARIF file to upload, or a directory containing multiple SARIF files. |
164180
| `--repository` || Name of the repository that was analyzed. |
165181
| `--commit` || SHA of the commit that was analyzed. In Git and in Azure DevOps, this corresponds to the value of `git rev-parse HEAD`. In Jenkins, this corresponds to `$GIT_COMMIT`. |
166-
| `--ref` || Name of the reference that was analyzed, for example `refs/heads/main`. In Git and in Jenkins, this corresponds to the value of `git symbolic-ref HEAD`. In Azure DevOps, this corresponds to `$(Build.SourceBranch)`. |
182+
| `--ref` || Name of the reference that was analyzed, for example `refs/heads/main` or `refs/pull/42/merge`. In Git or in Jenkins, this corresponds to the value of `git symbolic-ref HEAD`. In Azure DevOps, this corresponds to `$(Build.SourceBranch)`. |
167183
| `--github-url` || URL of the {% data variables.product.prodname_dotcom %} instance where your repository is hosted. |
168184
| `--github-auth` || A {% data variables.product.prodname_github_apps %} token or personal access token. |
169185
| <nobr>`--checkout-path`</nobr> | | The path to the checkout of your repository. The default is the current working directory. |

0 commit comments

Comments
 (0)