Small Python script to trigger Codacy reanalysis for the latest commit on the default branch of every repository in an organization.
The script:
- Lists repositories in a Codacy organization.
- Finds each repository's default branch.
- Identifies the latest commit SHA on that branch.
- Prints
repository -> branch -> commit. - Triggers reanalysis for that commit, unless
--dry-runis enabled.
- Python 3.9 or newer
- A Codacy account API token
The script uses only Python's standard library, so no package installation is required.
Export your Codacy API token:
export CODACY_API_TOKEN="your-token-here"The token is sent using Codacy's api-token header.
Run a dry run first:
python3 reanalyze_org.py <organization-name> --dry-runFor example, for the GitHub organization codacy:
python3 reanalyze_org.py codacy --dry-runIf the output looks correct, trigger the reanalysis:
python3 reanalyze_org.py <organization-name>Codacy's API requires both a provider and an organization name:
/organizations/{provider}/{remoteOrganizationName}/repositories
The script defaults to GitHub's provider key, gh.
Use --provider when the organization is hosted somewhere else:
python3 reanalyze_org.py <organization-name> --provider gl --dry-run
python3 reanalyze_org.py <organization-name> --provider bb --dry-runCommon provider keys include:
ghfor GitHubglfor GitLabbbfor Bitbucket
Your Codacy installation may use other provider keys, such as enterprise provider identifiers.
--dry-run
Only print repository, default branch, and commit SHA. Do not trigger reanalysis.
--provider PROVIDER
Codacy provider key. Defaults to gh.
--repository-filter {Synced,AllSynced,NotSynced}
Repository list filter. Defaults to Synced.
--limit LIMIT
Page size for Codacy list endpoints. Defaults to 100.
--base-url URL
Codacy API base URL. Defaults to https://app.codacy.com/api/v3.
--clean-cache
Send cleanCache=true when requesting commit reanalysis.
Dry run against a GitHub organization:
python3 reanalyze_org.py my-org --dry-runTrigger reanalysis against a GitHub organization:
python3 reanalyze_org.py my-orgDry run against a GitLab organization:
python3 reanalyze_org.py my-org --provider gl --dry-runTrigger reanalysis and ask Codacy to clean cache first:
python3 reanalyze_org.py my-org --clean-cache-
Reanalysis calls are sent to:
POST /organizations/{provider}/{remoteOrganizationName}/repositories/{repositoryName}/reanalyzeCommit -
The request body is:
{ "commitUuid": "<commit-sha>", "cleanCache": false } -
Repositories without a default branch or latest commit SHA are skipped and reported on stderr.