An helper to enable, disable or toggle configuration files for Codacy engines.
Create a file named auth.cookie and dump inside it the value of your Codacy cookie.
The requirements.txt lists all Python libraries that should be installed before running the script:
pip3 install -r requirements.txtarguments:
-h, --help show this help message and exit
--token TOKEN the api-token to be used on the REST API
--action {enableengine,disableengine,listengines,useconfigurationfile,dontuseconfigurationfile} action to take
--which WHICH repository to be updated, none means all
--provider PROVIDER git provider
--organization ORGANIZATION organization id
--engine ENGINE engine id
--baseurl BASEURL codacy server address (ignore if cloud)
psql -U codacy -h {host} -d postgres
\c analysis
\t on
\pset format unaligned
with t as (select "id", "internalId" from "Pattern")
select json_agg(t) from t \g patterns.json
\q
python3 main.py --action securityonly --baseurl https://yourserveraddress --token {token} --provider {git-provider} --organization {organization} --which {repoId}Flag --which is optional. If missing, will be for all repositories.
This script should be used if you are looking to set set-up a service account or similar. The script will open some tabs on the browser in order to enable the integration. Currently works on Codacy Cloud. On-prem will be available in the next release (>= 4.4.0)
python3 reintegrator.py --token {token} --provider {git-provider} --organization {organization} --which {reponame (optional)} --baseurl {baseurl (optional)}Flag --which is optional. If missing, will be for all repositories.
This script will add the slack integration automatically for a specific repository (or all repositories if the option --which and --repoid is not present). To integrate a specific repository, you must use the arguments --which and --repoid
python3 addSlackIntegration.py --token {token} --provider {git-provider} --organization {organization} --which {reponame (optional)} --repoid {repoid (optional)} --baseurl {baseurl (optional)} --slackChannel {slack channel} --webhookURL {url of slack app}Flag --which is optional. If missing, will be for all repositories.
This script will create a coding standard with all Medium and Critical Security issues enabled (all the other ones disabled) automatically for all repositories with the languages already present in all repositories within the organization and supported by Codacy
python3 createCodingStandards.py --token {token} --provider {git-provider} --organization {organization} --baseurl {baseurl (optional)}Generates a configuration file for the given tool. Since it's a PoC, currently only supports PMD.
config_file_generator.py [-h] [--token TOKEN] [--provider PROVIDER] [--organization ORGANIZATION] [--tooluuid TOOLUUID] [--baseurl BASEURL]Tools list can be retrieved using:
python3 main.py --action listengines [--baseurl BASEURL]This script will generate a report (in XLSX format) with all security issues you can find on all organizations you have permission to see or a specific organization and the list of all security issues per repository
python3 generateSecurityReport.py --baseurl {ignore it, if cloud} --orgname {organization names separated by comma or ignore it if you want all organizations} --token {API token}This script will generate a CSV file where you can find the new, fixed and ignored issues for all commits in the last x months for every repository across the organization.
python3 commitsPerformance.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --orgid {organization id} --token {API token} --months {number of months}This script will update the Quality Settings for Pull-Requests (you can do the same for the commits as well) with the following rules: the PR's will be blocked if it has at least one Security issue or Medium/Critical issue of other category (Error Prone, Performance, Code Style, etc). This script allows you to update the Quality Settings for a specific list of repos or the entire organization.
python3 updateQualitySettings.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --orgid {organization id} --token {API token} --reponame {comma separated list of the repositories to be updated, none means all}With this script, you'll be able to enable all decorations on the Integrations tab in all your active repositories in Codacy or in specific repositories using the flag --reponame
python3 enableDecorations.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --token {API token} --reponame {comma separated list of the repositories to be updated, none means all}With this script, you'll be able to add all repositories into Codacy or specific repositories using the flag --reponame. This script is able to get all repositories directly from the organization on Github
python3 addRepositories.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --token {API token on user account} --githubToken {user token from github account} --reponame {comma separated list of the repositories to be updated, none means all} --githubBaseURL {ignore it, if cloud. For SH instance, you should use http(s)://HOSTNAME/api/v3/}With this script, you'll be able to see the coverage percentages from the last 3 months of commits in each repo of the entire organization. The available values are: the current coverage percentage, an intermediate coverage percentage (from a commit 1-2 months ago) and the coverage percentage of a commit from 3 months ago.
python3 generateCoverageOverview.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --apiToken {API token on user account}With this script, you'll be able to generate a report with the following information: -> PR Status -> Date -> PR Id -> PR number -> PR Title -> PR Author -> Issues added -> Fixed issues -> Complexity added -> Clones added -> Diff Coverage -> Delta Coverage
from the last 30 days of a specific repository in your organization
python3 generateReportPullRequests.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --apiToken {API token on user account} --repoName {repository name}With this script, you'll be able to generate a report with all issues per repository by severity.
python3 generateIssuesReport.py --baseurl {ignore it, if cloud} --provider {git-provider} --organization {organization name} --apiToken {API token on user account}This utility automates the maintenance of your Bitbucket repository by removing stale branches. It ensures that active development branches and the main codebase remain untouched while clearing out old, merged, or abandoned branches.
The script applies the following decision logic to every branch in your repository:
- PR Check: Does the branch have an OPEN Pull Request associated with it? -> KEEP
- Whitelist Check: Is the branch the
main/master/defaultbranch or in theWHITELIST(e.g.,develop,release)? -> KEEP - Age Check: Was the last commit made more than X days ago (Default: 180)?
- No: -> KEEP
- Yes: -> DELETE
- Python 3.7+
- A Bitbucket Repository Access Token
To avoid system permission errors, run these commands in the script folder:
# Create a virtual environment
python3 -m venv venv
# Activate the environment
# (On Mac/Linux):
source venv/bin/activate
# (On Windows):
# venv\Scripts\activate
# Install required libraries
pip install requests python-dotenvDo not use your personal password. Create a token specifically for this script:
Go to Repository Settings > Security > Access Tokens.
Click Create Repository Access Token.
Select the following Scopes:
-
Pull requests: Read (To check for open PRs)
-
Repositories: Read & Write (To read/delete branches)
Copy the token immediately.
Create a file named .env in the same folder as the script. Important: Ensure the variable names match exactly what is in the script.
BITBUCKET_WORKSPACE=your_workspace_id
BITBUCKET_USERNAME=your_username
BITBUCKET_REPO_SLUG=your_repo_slug
BITBUCKET_ACCESS_TOKEN=your_access_token_hereBy default, the script runs in Dry Run mode. It lists what would be deleted without actually removing anything.
python delete_bb_branches.pyTo check for branches older than 90 days (instead of the default 180):
python delete_bb_branches.py --days 90Once you have verified the Dry Run output, pass the --force flag to perform the actual deletion.
python delete_bb_branches.py --forceOr if you want to delete all branches older than 90 days:
python delete_bb_branches.py --force --days 90To prevent specific branch names from ever being deleted, edit the WHITELIST array inside delete_bb_branches.py:
WHITELIST = ['develop', 'release', 'master', 'main', 'production']Note: the default branch is whitelisted by default