Skip to content

codacy-acme/reanalyze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Codacy Organization Reanalyzer

Small Python script to trigger Codacy reanalysis for the latest commit on the default branch of every repository in an organization.

The script:

  1. Lists repositories in a Codacy organization.
  2. Finds each repository's default branch.
  3. Identifies the latest commit SHA on that branch.
  4. Prints repository -> branch -> commit.
  5. Triggers reanalysis for that commit, unless --dry-run is enabled.

Requirements

  • Python 3.9 or newer
  • A Codacy account API token

The script uses only Python's standard library, so no package installation is required.

Setup

Export your Codacy API token:

export CODACY_API_TOKEN="your-token-here"

The token is sent using Codacy's api-token header.

Usage

Run a dry run first:

python3 reanalyze_org.py <organization-name> --dry-run

For example, for the GitHub organization codacy:

python3 reanalyze_org.py codacy --dry-run

If the output looks correct, trigger the reanalysis:

python3 reanalyze_org.py <organization-name>

Provider

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-run

Common provider keys include:

  • gh for GitHub
  • gl for GitLab
  • bb for Bitbucket

Your Codacy installation may use other provider keys, such as enterprise provider identifiers.

Options

--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.

Examples

Dry run against a GitHub organization:

python3 reanalyze_org.py my-org --dry-run

Trigger reanalysis against a GitHub organization:

python3 reanalyze_org.py my-org

Dry run against a GitLab organization:

python3 reanalyze_org.py my-org --provider gl --dry-run

Trigger reanalysis and ask Codacy to clean cache first:

python3 reanalyze_org.py my-org --clean-cache

Notes

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages