1
votes

For GitLab, pull/push mirror has to be set up for each repository manually.

I want to know is there any way that could automatically sync all Github repo to GitLab, such that

  • when you create a new repo in GitHub, a repo in GitLab will be automatically be created and act like a pull mirror.
  • for all old repo in Github, set up repos in GitLab that will act like pull mirrors.

below is what I have thought:

  • proposal:
    • doesnt use gitlab pull mirror or github action to push
      • approach 0: a script in a server periodically pulling the change from all github repo to local from github and pushing to gitlab.
        • problems
          • required the server to be always running, and it has to contains all the github repos in drive.
    • use gitlab pull mirror:
      • approach 1: when you create a new repo in GitHub, the webhook is sent to a script that could create a GitLab repo, and then setup the mirror
        • problems
          • there is no API to configure the pull mirror in gitlab, so it couldn't be automated. existing feature request
          • even there are api, pull mirror only support password or deploy key
            • password: your github account become dangerous
            • deploy key:
              • have to retrieve the deploy key by program
              • seems no easy way of automatically attaching the deploy key to github repo by api ?
    • use github action to act like a push mirror:
      • approach 2: a server constantly running to check if any GitHub repo doesnt has a counter part in Gitlab, if found, create a GitLab repo, add a gitHub action by api to that GitHub repository that is set to push the change to the newly created gitlab repo.
        • advantage:
          • all old repository and new repository in Github will be linked to gitlab.
        • problems:
          • since the server has to add a github action, it means that it has write permission to all github repository, if the server is hacked, hacker could add any commit or change commit history.
          • the github action will have write permission to counterpart gitlab repository
            • possibly by ssh key set in github secret
              • so the secret has to be added by api also, but seems such api doesnt exist yet github secret api
2
What have you tried? What research have you done? What hasn't worked? - Daniel Mann
@DanielMann I don't know where to begin with so I am asking this question. Also, in guidelines, seems that there are no requirements for the question to be attached with tried method and research made. As long as the question is well-defined and non-meaningless, it is acceptable. - Luk Aron
@DanielMann my search and research are the first sentence of my question. That mirror has to be set up manually for each repository so it couldn't solve the problem. - Luk Aron

2 Answers

2
votes

After one month of research, I found a way.

Wrote a python script for this

https://github.com/AronWaterAron/Sync_GitHub_to_GitLab/blob/master/create_linkage.py

1
votes

There's currently (as for Gitlab version 13.9) no way to do this automatically. Like you said in your question, it has to be done manually for each repository you want to mirror.