简体   繁体   English

自动将所有 GitHub 存储库镜像到 gitlab

[英]Auto mirror all GitHub repository to gitlab

For GitLab, pull/push mirror has to be set up for each repository manually.对于 GitLab,必须手动为每个存储库设置拉/推镜像。

I want to know is there any way that could automatically sync all Github repo to GitLab, such that我想知道有什么方法可以自动将所有 Github 存储库同步到 GitLab,这样

  • when you create a new repo in GitHub, a repo in GitLab will be automatically be created and act like a pull mirror.当您在 GitHub 中创建新仓库时,将自动创建 GitLab 中的仓库并像拉镜像一样工作。
  • for all old repo in Github, set up repos in GitLab that will act like pull mirrors.对于 Github 中的所有旧仓库,在 GitLab 中设置仓库,其作用类似于拉镜像。

below is what I have thought:以下是我的想法:

  • proposal:提议:
    • doesnt use gitlab pull mirror or github action to push不使用 gitlab 拉镜或 github 动作推
      • approach 0: a script in a server periodically pulling the change from all github repo to local from github and pushing to gitlab.方法 0:服务器中的脚本定期将所有 github 存储库中的更改从 github 拉到本地并推送到 gitlab。
        • problems问题
          • required the server to be always running, and it has to contains all the github repos in drive.要求服务器始终运行,并且它必须包含驱动器中的所有 github 存储库。
    • use gitlab pull mirror:使用gitlab拉镜:
      • 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方法 1:当您在 GitHub 中创建新的 repo 时,webhook 被发送到可以创建 GitLab repo 的脚本,然后设置镜像
        • problems问题
          • there is no API to configure the pull mirror in gitlab, so it couldn't be automated. gitlab中没有API来配置拉镜像,所以不能自动化。 existing feature request现有功能请求
          • even there are api, pull mirror only support password or deploy key甚至还有api,拉镜像只支持密码或部署密钥
            • password: your github account become dangerous密码:您的 github 帐户变得危险
            • 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?似乎不容易通过 api 将部署密钥自动附加到 github 存储库?
    • use github action to act like a push mirror:使用 github 动作来充当推镜:
      • 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. 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 回购。
        • advantage:优势:
          • all old repository and new repository in Github will be linked to gitlab. Github 中的所有旧存储库和新存储库都将链接到 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.由于服务器必须添加 github 操作,这意味着它对所有 github 存储库具有写入权限,如果服务器被黑客入侵,黑客可以添加任何提交或更改提交历史。
          • the github action will have write permission to counterpart gitlab repository github 操作将对对应的 gitlab 存储库具有写入权限
            • possibly by ssh key set in github secret可能由 github 密钥中设置的 ssh 密钥
              • so the secret has to be added by api also, but seems such api doesnt exist yet github secret api所以秘密也必须由 api 添加,但似乎这样的api尚不存在

There's currently (as for Gitlab version 13.9) no way to do this automatically.目前(至于 Gitlab 版本 13.9)无法自动执行此操作。 Like you said in your question, it has to be done manually for each repository you want to mirror.就像您在问题中所说的那样,必须为您要镜像的每个存储库手动完成。

After one month of research, I found a way.经过一个月的研究,我找到了一种方法。

Wrote a python script for this为此编写了 python 脚本

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM