V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ZedRover
V2EX  ›  程序员

关于 git 自动化的问题求助

  •  
  •   ZedRover · 332 天前 · 1141 次点击
    这是一个创建于 332 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 github 和公司的 gitlab 管理平时的代码, 分两个 branch, github 搭配 deepsource 进行代码检查, 现在每次都是 push 到 github 的 main 分支, 然后手动 merge deepsource 修改后的分支到 main, 然后本地 pull main 之后再 push 到公司的 gitlab 上, 想问一下有没有自动化工具能够实现自动 push main => pull main => push 公司 这个流程呢?

    5 条回复    2023-05-29 19:02:30 +08:00
    deplivesb
        1
    deplivesb  
       332 天前
    写个 shell 脚本?
    defunct9
        2
    defunct9  
       332 天前
    action
    ge145
        3
    ge145  
       332 天前
    GPT:
    您可以使用 GitLab 的自动化功能和 GitHub 的 Webhooks 将 GitHub 项目自动同步到 GitLab 。下面是一个基本的步骤:

    在 GitLab 中创建一个新项目,以便将来将 GitHub 中的代码同步到其中。
    在 GitHub 中打开要同步的项目并转到 Settings -> Webhooks 。点击 Add webhook 创建一个新的 Webhook ,将 Payload URL 设置为 https://gitlab.example.com/api/v4/projects/<project_id>/mirror/pull?private_token=<access_token>,其中<project_id>是您在 GitLab 中创建的项目 ID ,<access_token>则是您在 GitLab 中生成用于访问 API 的私有令牌。
    在 Webhooks -> Add webhook 页面中,还需设置 Webhook 的触发事件。建议选择 push 事件,这将在 GitHub 上进行任何提交时都会触发同步操作。
    保存新的 Webhook 设置后,您应该会看到一个成功的提示消息。现在可以在 GitHub 中进行提交了。
    此外,如果您想把 GitLab 上的更改推送回 GitHub ,请转到 GitLab 项目中的 Settings -> Repository 页面,并启用“Mirror Repository”选项。然后将 Push Events Webhook 添加到 GitHub 中,使其能够根据需要将更改推回 GitHub 。
    liudong7351
        4
    liudong7351  
       332 天前
    让 2 个仓库代码同步,公司会不会不允许啊
    Vegetable
        5
    Vegetable  
       332 天前
    github action 呗,直接 push 到 github 后边自动化
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1825 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:33 · PVG 00:33 · LAX 09:33 · JFK 12:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.