This tool helps you identify archived repositories in Bitbucket Server that are also imported into Snyk, and provides options to analyze and delete the corresponding Snyk projects.
- 🔍 Analysis: Find archived Bitbucket repositories and match them with Snyk targets
- 📊 DataFrame Operations: Uses pandas for efficient data manipulation and comparison
- 🗑️ Bulk Operations: Delete multiple Snyk projects that match archived Bitbucket repos
- 🔒 Dry Run Mode: Safe testing without actually deleting anything
- 📝 Detailed Logging: Comprehensive logging for troubleshooting
- 📄 JSON Export: Save analysis results for review
- Python 3.10.14 or higher
- Access to Bitbucket Server with username/password authentication
- Snyk API token with appropriate permissions
- Required Python packages (see requirements.txt)
-
Clone the Repository
git clone <repository-url> cd bitbucket-delete-archieved-repos
-
Install Dependencies
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Set Environment Variables
export SNYK_TOKEN="your-snyk-api-token" export BITBUCKET_USERNAME="your-bitbucket-username" export BITBUCKET_PASSWORD="your-bitbucket-password" # or app password
Find archived Bitbucket repositories and match them with Snyk targets:
python3 bitbucket_snyk_cleanup.py analyze \
--bitbucket-url "https://bitbucket.company.com" \
--bitbucket-username "your-username" \
--bitbucket-password "your-password" \
--snyk-org-id "your-snyk-org-id" \
--output-file "analysis-results.json"
Get a list of all archived repositories in Bitbucket:
python3 bitbucket_snyk_cleanup.py list-archived-repos \
--bitbucket-url "https://bitbucket.company.com" \
--bitbucket-username "your-username" \
--bitbucket-password "your-password" \
--output-file "archived-repos.json"
Preview what would be deleted without actually deleting:
python3 bitbucket_snyk_cleanup.py delete-matching-projects \
--input-file "analysis-results.json" \
--dry-run
Actually delete the matching Snyk projects:
python3 bitbucket_snyk_cleanup.py delete-matching-projects \
--input-file "analysis-results.json" \
--execute
--log-level
: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)--snyk-tenant
: Snyk tenant URL (default: api.us.snyk.io)
--bitbucket-url
/-b
: Bitbucket Server base URL (required)--bitbucket-username
/-u
: Bitbucket username (required)--bitbucket-password
/-p
: Bitbucket password (required)--snyk-org-id
/-s
: Snyk organization ID (required)--output-file
/-o
: Output file for results (default: bitbucket-snyk-analysis.json)
--input-file
/-i
: Input file from analyze command (required)--dry-run
: Preview deletions without executing (default: True)--execute
: Actually perform deletions
--bitbucket-url
/-b
: Bitbucket Server base URL (required)--bitbucket-username
/-u
: Bitbucket username (required)--bitbucket-password
/-p
: Bitbucket password (required)--output-file
/-o
: Output file for archived repos (default: archived-repos.json)
The analysis command generates a JSON file with the following structure:
{
"summary": {
"total_archived_bitbucket_repos": 15,
"total_snyk_targets": 120,
"matching_targets": 8,
"matching_projects": 12
},
"archived_repositories": [...],
"matching_targets": [...],
"matching_projects": [...]
}
- Connect to Bitbucket Server: Authenticates using username/password
- Fetch Archived Repos: Retrieves all repositories marked as archived
- Connect to Snyk: Uses API token to fetch all targets
- URL Matching: Compares normalized URLs between Bitbucket and Snyk
- Project Analysis: Finds all Snyk projects associated with matching targets
- Bulk Operations: Provides safe deletion with dry-run capability
The tool normalizes URLs for comparison by:
- Converting to lowercase
- Removing
.git
suffixes - Removing trailing slashes
- Handling different clone URL formats (SSH, HTTPS, HTTP)
- Dry Run by Default: All deletion operations default to dry-run mode
- Confirmation Required: Execute mode requires explicit confirmation
- Detailed Logging: Comprehensive logs for audit trails
- Error Handling: Graceful handling of API errors and network issues
-
Authentication Failures
- Verify Bitbucket credentials are correct
- Check if account has appropriate permissions
- Ensure Snyk token has required scopes
-
No Matches Found
- Check if URLs are being normalized correctly
- Verify repository names and project keys
- Review logging output for URL comparison details
-
API Rate Limits
- The tool includes basic error handling for rate limits
- Consider running during off-peak hours for large datasets
Enable debug logging for detailed information:
python3 bitbucket_snyk_cleanup.py analyze \
--bitbucket-url "https://bitbucket.company.com" \
--bitbucket-username "your-username" \
--bitbucket-password "your-password" \
--snyk-org-id "your-snyk-org-id" \
--log-level DEBUG
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
[Add your license information here]
For issues and questions:
- Check the troubleshooting section
- Review the logs with DEBUG level
- Create an issue in the repository