如何创建一个Gitlab webhook来更新Github上的镜像回购? [英] How to create a Gitlab webhook to update a mirror repo on Github?

查看:149
本文介绍了如何创建一个Gitlab webhook来更新Github上的镜像回购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Gitlab中创建一个webhook,以便在发生 push 事件时自动更新Github上的镜像存储库。我检查了这个页面,但我不明白它是如何完成的。



我的Gitlab版本是6.5。这里是配置页面:





我应该在URL中输入什么内容?在哪里需要放置脚本来更新存储库?

解决方案

您不需要webhook。一个普通的post-receive钩子可以很好地工作。



要创建和使用这样一个钩子,您只需要在安装了gitlab的服务器上登录并创建一个ssh

  sudo -u git ssh-keygen -f /home/git/.ssh/reponame_key 

(不要在提示时输入任何密码短语)

转到您的github帐户,并将公钥(作为 /home/git/ssh/reponame_key.pub 创建)作为部署密钥添加到项目中。
查看 https://help.github.com/articles/managing-deploy-keys
如果你需要帮助。



一旦完成,你只需要配置你的git服务器和github之间的连接:
add an别名为git用户的ssh配置(将以下行添加到 /home/git/.ssh/config - 如果它不存在,请创建它)

 主机名称
IdentityFile /home/git/.ssh/reponame_key
HostName github.com
用户git

现在将新的远程(使用您刚创建的别名)添加到您的存储库:

  cd /home/git/repositories/namespace/reponame.git 

git remote add --mirror github reponame:youruser / reponame.git

现在一切都已到位,您必须创建实际的钩子:

  cd / home / git / repositories / namespace / r eponame.git / hooks 

echoexec git push --quiet github& >> post-receive

chmod 755 post-receive

最后一条命令非常重要因为git会在运行前检查一个钩子是否可执行。



就是这样!


$ b

(替换reponame,名称空间和youruser根据您的真实帐户和享受)。



最后一个注意:如果你想让你的名字和头像在github上提交,请确保你使用的电子邮件地址在gitlab上也是你的github账号中的一个地址。否则你会看到你的gitlab用户名。


I would like to create a webhook within Gitlab to automatically update a mirror repository on Github, whenever a push event happens. I've checked this page, but I didn't understand how it is done.

My Gitlab version is 6.5. Here is the configuration page:

What should I put in URL? Where do I need to place the script to update the repository?

解决方案

You don't need a webhook for that. A regular post-receive hook will work very well.

To create and use such a hook you just have to login on the server where your gitlab is installed and create an ssh key for git user.

sudo -u git ssh-keygen -f /home/git/.ssh/reponame_key

(do not type any passphrase when prompted)

Go to your github account and add the public key (it's been created as /home/git/ssh/reponame_key.pub) to your project as a deploy key. have a look at https://help.github.com/articles/managing-deploy-keys if you need help with that.

Once that is done, you just have to configure the connection between your git server and github's: add an alias to git user's ssh configuration (add following lines to /home/git/.ssh/config - create it if it's not present)

Host reponame  
IdentityFile /home/git/.ssh/reponame_key  
HostName github.com  
User git 

Now add the new remote (using the alias you just created) to your repository:

cd /home/git/repositories/namespace/reponame.git

git remote add --mirror github reponame:youruser/reponame.git

Now that everything is in place you'll have to create the actual hook:

cd /home/git/repositories/namespace/reponame.git/hooks

echo "exec git push --quiet github &" >> post-receive

chmod 755 post-receive

The lastcommand is very important because git will check if a hook is executable before running it.

That's it!

(Replace reponame, namespace and youruser according to your real accounts and enjoy).

Last note: if you want your name andavatar near commits on github, make sure that the email address you are using on gitlab is one of the addresses inked to your github account as well. You'll see your gitlab username otherwise.

这篇关于如何创建一个Gitlab webhook来更新Github上的镜像回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆