Skip to content
This documentation applies to Codacy Self-hosted v4.2.0

For the latest updates and improvements, see the latest Cloud documentation instead.

Obtaining code quality metrics for files#

To obtain the code quality information for your files in a flexible way, use the Codacy API endpoint listFiles.

For example, if you're managing your source code using a monorepo strategy you may want to generate separate code quality reports for the subset of files that belong to each component or project in your repository.

Example: Obtaining code quality metrics for a subdirectory of your repository#

This example exports the grade, total issues, complexity, coverage, and duplication in CSV format for all files in the directory src/router of the GitHub repository codacy/website.

The example script:

  1. Defines an account API token.
  2. Calls the Codacy API endpoint to retrieve the code quality metrics, filtering the results by files that include src/router/ in the path.
  3. Uses jq to select only the necessary data fields and convert the results to the CSV format.
export CODACY_API_TOKEN="<your account API token>"

curl -X GET "https://app.codacy.com/api/v3/organizations/gh/codacy/repositories/website/files?search=src/router/" \
     -H "api-token: $CODACY_API_TOKEN" \
| jq -r ".data[] | [.path, .gradeLetter, .totalIssues, .complexity, .coverage, .duplication] | @csv"

Output:

"src/components/router/index.ts","A",0,8,70,0"
"src/components/router/Link.tsx","A",0,5,100,0"
"src/components/router/Redirect.tsx","B",0,2,14,0"
"src/components/router/routes/account.ts","A",0,0,100,0"
[...]

Important

For the sake of simplicity, the example doesn't consider paginated results obtained from the Codacy API. Learn how to use pagination to ensure that you obtain all the results returned by the API.

Share your feedback 📢

Did this page help you?

Thanks for the feedback! Is there anything else you'd like to tell us about this page?

We're sorry to hear that. Please let us know what we can improve:

Alternatively, you can create a more detailed issue on our GitHub repository.

Thanks for helping improve the Codacy documentation.

If you have a question or need help please contact support@codacy.com.

Last modified June 17, 2021