A Python script that automates the process of following repositories in Codacy. It can follow all repositories in an organization or specific ones you select, with comprehensive error handling and logging capabilities.
- Follow all repositories in an organization or select specific ones
- Automatic pagination handling for large organizations
- Detailed logging with debug mode option
- Success/failure tracking for each repository
- URL encoding for special characters in repository names
- Validates repository names before attempting to follow
- Comprehensive error handling and reporting
- Python 3.x
- Required Python packages:
- requests
- urllib3
- Clone this repository or download the script
- Install the required dependencies:
pip install requests
python codacy_follow.py --token YOUR_API_TOKEN --provider PROVIDER --organization ORG_NAME
python codacy_follow.py --token YOUR_API_TOKEN --provider PROVIDER --organization ORG_NAME --reponames "repo1,repo2,repo3"
python codacy_follow.py --token YOUR_API_TOKEN --provider PROVIDER --organization ORG_NAME --debug
--token
: (Required) Your Codacy API token--provider
: (Required) Git provider code (e.g., 'gh' for GitHub, 'gl' for GitLab)--organization
: (Required) Your organization name--baseurl
: (Optional) Codacy server address (default: 'https://app.codacy.com')--reponames
: (Optional) Comma-separated list of specific repositories to follow--debug
: (Optional) Enable debug logging
The script provides:
- Progress updates for each repository
- Success/failure status for each operation
- Summary of total successes and failures
- Execution time
- Detailed logs in debug mode
2024-01-12 10:00:01 - INFO - Starting script with provider: gh, organization: myorg
2024-01-12 10:00:02 - INFO - Retrieved 25 repositories
2024-01-12 10:00:03 - INFO - Successfully followed repo1
2024-01-12 10:00:03 - INFO - Successfully followed repo2
2024-01-12 10:00:04 - INFO - Script completed in 3.45 seconds
2024-01-12 10:00:04 - INFO - Successfully followed 2 repositories
The script handles various error scenarios:
- Invalid API tokens
- Network connectivity issues
- Rate limiting
- Invalid repository names
- Malformed API responses
- Permission issues
All errors are logged with appropriate detail level based on the debug setting.
- 0: All operations completed successfully
- 1: One or more operations failed
- Use environment variables for sensitive information like API tokens
- Enable debug mode when troubleshooting
- Test with a small set of repositories first
- Monitor rate limits when dealing with large organizations
- Store API tokens securely
- Use minimal required permissions for API tokens
- Consider using a dedicated service account
- Review logs for sensitive information before sharing
Common issues and solutions:
-
Rate Limiting
- Reduce concurrent requests
- Check API quotas
- Implement retry mechanism
-
Permission Errors
- Verify API token permissions
- Check organization access
- Verify repository visibility
-
Connection Issues
- Check network connectivity
- Verify base URL
- Check proxy settings
Contributions are welcome! Please feel free to submit a Pull Request.
For issues with:
- Codacy API: Visit the Codacy API documentation
- This script: Open an issue in the repository
- Initial release with merged functionality
- Added support for specific repository selection
- Implemented comprehensive error handling
- Added debug mode
- Added success/failure tracking