GitHub to GitLab Auto Update is a Python-based tool designed to automate the configuration of repository mirroring between your GitHub and GitLab accounts. With this tool, you can automatically import new repositories from GitHub and update existing ones on GitLab, ensuring that the two platforms remain synchronized.
Managing and updating hundreds of repositories manually is time-consuming. This project retrieves all GitLab projects that you are a member of using the GitLab API and automatically sets up mirroring to the corresponding GitHub repositories. By doing so, any update on GitHub is automatically synchronized to GitLab.
- GitHub Account:
bocaletto-luca
- GitLab Account:
bocaletto-luca
- Project Name:
github-to-gitlab-auto-update
- Automated Mirroring Setup: Automatically configures repository mirroring for all your GitLab projects.
- Bulk Operations: Efficiently handles a large number (over 220) of repositories.
- Easy Configuration: Customize by simply updating a few variables.
- Secure: Use personal access tokens (PATs) for authentication with GitHub and GitLab. (Remember to handle your tokens securely!)
- Python 3.x
- Python Module
requests
(Install viapip install requests
) - Personal Access Tokens:
- GitHub PAT: Must have the
repo
scope to access private and public repositories. - GitLab PAT: Must have the
api
scope for modifying project settings.
- GitHub PAT: Must have the
-
Clone the Repository:
git clone https://github.com/bocaletto-luca/github-to-gitlab-auto-update.git
-
Navigate to the Project Directory:
cd github-to-gitlab-auto-update
-
(Optional) Create and Activate a Virtual Environment:
python3 -m venv venv source venv/bin/activate
-
Install Required Dependencies:
pip install requests
Update the configuration variables in the github_to_gitlab_auto_update.py
file at the beginning of the script:
# Configuration
GITLAB_URL = "https://gitlab.com/api/v4"
GITHUB_USERNAME = "bocaletto-luca" # Your GitHub username
GITHUB_TOKEN = "your_github_token_here" # Replace with your GitHub Personal Access Token
GITLAB_TOKEN = "your_gitlab_token_here" # Replace with your GitLab Personal Access Token
Security Note:
Never commit your tokens in plain text to public repositories. Consider loading these tokens from secure environment variables or a configuration file that is excluded from version control.
To start the process and set up mirroring for all your repositories, simply run:
python3 github_to_gitlab_auto_update.py
The script will:
- Retrieve all GitLab projects you are a member of.
- Construct the corresponding GitHub repository URLs.
- Configure each GitLab project with mirroring settings to the GitHub repository.
-
Fetching Projects:
The script uses the GitLab API endpoint/projects
to fetch all projects associated with your account. Pagination is handled to ensure all projects are retrieved. -
Building Repository URLs:
For every GitLab project, the script constructs the matching GitHub repository URL in this format:
https://github.com/bocaletto-luca/<project_name>.git
Ensure that your GitLab project names match those on GitHub. -
Setting Up Mirroring:
The script sends an HTTP PUT request to the GitLab API to configure the mirroring. It passes the GitHub repository URL along with your GitHub credentials (using the PAT) to enable automatic updates.
Contributions, suggestions, and bug reports are greatly appreciated!
If you have any improvements to propose, please open an issue or submit a pull request.
This project is released under the MIT License. See the LICENSE file for details.
Created by bocaletto-luca