Skip to main content

Obtaining current issues in repositories

To obtain information about the current issues in your repositories in a flexible way, use the Codacy API endpoint searchRepositoryIssues.

For example, you may want to generate a report that includes only issues that belong to specific categories (such as security issues), or that have a minimum severity level.

Example: Obtaining security issues with level Error and Warning

This example exports the pattern ID, issue level, file path, and timestamp for all security issues that have the severity level Warning or Error in the GitHub repository codacy/website.

The example script:

  1. Defines the account API token used to authenticate on the Codacy API.
  2. Calls the endpoint searchRepositoryIssues to retrieve information about the issues, filtering the results by security issues with the relevant severity levels.
  3. Uses jq to select only the necessary data fields and convert the results to the CSV format.
CODACY_API_TOKEN="<your account API token>"
GIT_PROVIDER="<your Git provider>" # gh, ghe, gl, gle, bb, or bbe
ORGANIZATION="<your organization name>"
REPOSITORY="<your repository name>"

curl -X POST "https://app.codacy.com/api/v3/analysis/organizations/$GIT_PROVIDER/$ORGANIZATION/repositories/$REPOSITORY/issues/search" \
-H "api-token: $CODACY_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "levels": ["Error", "Warning"], "categories": ["Security"] }' \
| jq -r ".data[] | [.patternInfo.id, .patternInfo.level, .filePath, .commitInfo.timestamp] | @csv"

Example output:

"BundlerAudit_Insecure Dependency","Error","Gemfile.lock","2021-06-16T11:46:24Z"
"Custom_Scala_PredictableRandom","Warning","src/test/database/SpecsHelper.scala","2021-05-21T16:20:15Z"
"Custom_Scala_PlayUntrustedHttpRequestParameter","Warning","app/RedirectController.scala","2021-04-26T15:06:33Z"
[...]
caution

Learn how to use pagination to ensure that you process all results returned by the API.

See also