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
The example script:
- Defines the account API token used to authenticate on the Codacy API.
- Calls the Codacy API endpoint listFiles to retrieve the code quality metrics, filtering the results by files that include
src/router/in the path.
- Uses jq to select only the necessary data fields and convert the results to the CSV format.
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"
"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 [...]
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 process all 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?
255 characters left
We're sorry to hear that. Please let us know what we can improve:
255 characters left
Alternatively, you can create a more detailed issue on our GitHub repository.
Thanks for helping improve the Codacy documentation.
Edit this page on GitHub if you notice something wrong or missing.
If you have a question or need help please contact firstname.lastname@example.org.