Skip to main content

github2gitlab

NOTE: This is based on the work of https://pypi.python.org/pypi/github2gitlab. However, the original repo http://workbench.dachary.org/dachary/github2gitlab is not accessible anymore. This is a clone with some improvements.

github2gitlab is a command line tool to mirror projects from GitHub to GitLab. It does the following, in sequence:

  • Upload the ~/.ssh/id_rsa.pub ssh key to gitlab if not found

  • Create the gitlab project if it does not exist

  • Mirror the github git repository to the gitlab git repository

  • Create or update the GitLab merge requests to match the GitHub pull requests

Examples

Mirror http://github.com/dachary/test to http://workbench.dachary.org/dachary/test

github2gitlab \
   --gitlab-url http://workbench.dachary.org \
   --gitlab-token sxQJ67SQKihMrGWVf \
   --github-repo dachary/test

Mirror http://github.com/ceph/ceph to http://workbench.dachary.org/ceph/ceph-backports and use the GitHub token to be allowed to do more requests than when anonymous. Use –ignore-closed to get rid of pull requests that are closed and were never merged.

github2gitlab \
   --gitlab-url http://workbench.dachary.org \
   --gitlab-token sxQJ67SQKihMrGWVf \
   --gitlab-repo ceph/ceph-backports \
   --github-token 64933d355fda9844aadd4e224d \
   --github-repo ceph/ceph \
   --ignore-closed

Mirroring details

The GitHub git repository contains a reference for each pull requests. For instance the pull request 483 has the refs/pull/483/head reference which is the tip of the branch that was pushed. If the pull request is open and can be merged on the destination, the reference refs/pull/483/merge also exists and is the result of the merge.

Instead of mirroring the refs/pull/* references to GitLab, they are moved to refs/heads/pull/* so they become branches. If GitLab CI is watching the project, it will run a job each time the pull/*/head reference is updated.

The pull requests title and description are mirrored exactly. The state of the pull request cannot be mapped exactly and is translated as follows:

if the pull request is opened, the merge request is opened
if the pull request is closed,
  if the pull request merged_at field is null,
    the merge request is closed
  else
    the merge request is merged

If a merge request is opened to mirror a pull request that has been merged already, GitLab will refuse to set it to the merged state because it notices that there would be nothing to merge. In this case the merge request is set to the closed state and the :MERGED: string is append to the description.

Hacking

  • Get the code : git clone http://workbench.dachary.org/dachary/github2gitlab.git

  • Run the unit tests : tox

  • Run the integration tests. They require a gitlab token and a github token from actual users with permissions to delete and create projects. The github project specified with –github-repo and the github project specified with –gitlab-repo will be removed and all their data and git repository lost during the test.

    PYTHONPATH=. tests/integration.py

    –gitlab-url http://workbench.dachary.org –gitlab-token XXXXXXXXX –gitlab-repo dachary/testrepo2 –github-token XXXXXXXXX –github-repo dachary/testrepo –ssh-public-key ~/.ssh/id_rsa.pub –verbose

  • Tag a version

  • version=1.3.0 ; perl -pi -e “s/^version.*/version = $version/” setup.cfg ; for i in 1 2 ; do python setup.py sdist ; amend=$(git log -1 –oneline | grep –quiet “version $version” && echo –amend) ; git commit $amend -m “version $version” ChangeLog setup.cfg ; git tag -a -f -m “version $version” $version ; done

  • Check the documentation : rst2html < README.rst > /tmp/a.html

  • Publish a new version

  • python setup.py sdist upload –sign

  • git push ; git push –tags

  • pypi maintenance

Release files for hub2lab 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hub2lab 1.6.1
File Size Uploaded
hub2lab-1.6.1.tar.gz 30.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hub2lab 1.6.1
File Interpreter ABI Platform
hub2lab-1.6.1-py3.8.egg Legacy Egg format - - Details

Total release size: 48.3 kB

Release files / hub2lab-1.6.1.tar.gz

Download URL hub2lab-1.6.1.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e3082d0b1862a654b24f2811f7b732db61e3e37e53de49960a12a5e053cee6c7
BLAKE2b-256 checksum
How to use checksums
b24ef2a80c73d41c29d024388071e90c255334a9615b8603850a897a487140d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.14

Release files / hub2lab-1.6.1-py3.8.egg

Download URL hub2lab-1.6.1-py3.8.egg
Size 18.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
d9149dfb2e5d33e07d3707c1c67a085bb408c3f40aa74540a0596995fba9f7ea
BLAKE2b-256 checksum
How to use checksums
795f347fb98110a1345109561ac7e48d6edd831810c1bbd720f6eeac530ebe1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.14

Release history Release notifications | RSS feed

This release

1.6.1 This release

2 release files

1.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page