The git_repo_analyzer tool helps automate the process of cloning and analyzing repositories from GitHub or Stash (Bitbucket Server). It provides a command-line interface (CLI) that can be used to:
- Clone repositories from GitHub or Stash.
- Analyze repositories by checking their structure, branches, commits, and more.
- Handle rate limits for API requests.
- Perform other tasks like fetching all branches and pulling updates from cloned repositories.
To get started with git_repo_analyzer, you need to ensure the following dependencies are installed:
- Python 3.x: Ensure that Python is installed on your system.
- Required Libraries:
requests
(for interacting with GitHub and Stash APIs)github
(for GitHub API)stashy
(for Stash/Bitbucket Server API)argparse
(for command-line argument parsing)subprocess
(for executing system commands likegit
)
You can install the necessary Python libraries using pip
:
pip install requests github stashy
Once you have everything set up, you can use the git_repo_analyzer.py
script to interact with GitHub or Stash. This tool supports different actions like cloning repositories, analyzing them, and checking rate limits.
To clone repositories from GitHub or Stash, use the -action clone
argument.
python git_repo_analyzer.py -token YOUR_TOKEN -username YOUR_USERNAME -dest /path/to/destination -action clone -platform github
-token
: Your GitHub or Stash API token.-username
: Your GitHub or Stash username.-dest
: Destination directory where the repositories will be cloned.-action
: Useclone
to clone repositories.-platform
: Eithergithub
orstash
.-project
: Optional. The name of a specific project to clone.-olderThan
: Optional. Filter repositories based on their last modification time (in minutes).
Clone all repositories from a GitHub user:
python git_repo_analyzer.py -token your_github_token -username your_github_username -dest ./repos -action clone -platform github
To analyze all repositories in the destination folder, use the -action analyze
argument. This will perform checks on the cloned repositories in the specified folder.
python git_repo_analyzer.py -token YOUR_TOKEN -username YOUR_USERNAME -dest /path/to/destination -action analyze -platform github
- This command will analyze all the repositories in the destination folder (
/path/to/destination
). - You can further customize the analysis with options like
-project
to analyze only a specific repository or-olderThan
to filter repositories by modification time.
To prevent hitting the rate limit when using GitHub or Stash API, you can check the rate limit status.
python git_repo_analyzer.py -token YOUR_TOKEN -username YOUR_USERNAME -dest /path/to/destination -action check-rate-limit -platform github
This will check the rate limit and wait if the requests have exceeded the limit.
Below are the command-line arguments supported by the Git Repo Analyzer.
Argument | Description |
---|---|
-token |
Required. API Token for GitHub or Stash. |
-username |
Required. GitHub or Stash username. |
-dest |
Required. Destination folder where repositories will be cloned or analyzed. |
-action |
Required. Action to perform (clone , analyze , check-rate-limit ). |
-platform |
Required. The platform to use (github or stash ). |
-project |
Optional. The specific project name to filter repositories. |
-olderThan |
Optional. Analyze repositories modified within the last X minutes. |
-rate-limit |
Optional. Rate limit time window for API requests (default is 60 seconds). |
-stash-url |
Optional. The URL for the Stash server (required for Stash platform). |
python git_repo_analyzer.py -token your_github_token -username your_github_username -dest ./repos -action clone -platform github
This command clones all repositories from the specified GitHub user into the ./repos
folder.
python git_repo_analyzer.py -token your_github_token -username your_github_username -dest ./repos -action analyze -platform github -olderThan 30
This command analyzes repositories that have not been modified in the last 30 minutes.
python git_repo_analyzer.py -token your_github_token -username your_github_username -dest ./repos -action check-rate-limit -platform github
This command checks if the rate limit for GitHub API requests has been reached and waits for reset if necessary.
python git_repo_analyzer.py -token your_stash_token -username your_stash_username -dest ./stash_repos -action clone -platform stash -stash-url http://your.stash.server
This command clones all repositories from a Stash server into the ./stash_repos
folder.