ubc / github2gitlab

Github to Gitlab sync script with Docker support
GNU Affero General Public License v3.0
39 stars 21 forks source link
docker github gitlab mirror sync

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:

Examples

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

.. code:: sh

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.

.. code:: sh

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