如何在将分支推送到GitHub后添加带有链接到新拉取请求页面的消息?

时间:2018-04-22 18:08:00

标签: git github usability

例如,当我将分支推送到GitLab或Bitbucket时,我看到了这样的消息:

Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for branch-name, visit:
remote:   https://gitlab.com/username/reponame/merge_requests/new?merge_request%5Bsource_branch%5D=branch-name
remote:
To gitlab.com:username/reponame.git
 * [new branch]      branch-name -> branch-name

是否有简单的方法为GitHub添加此类消息?

3 个答案:

答案 0 :(得分:1)

该消息来自远程存储库中配置的post-receive hook。它是Git服务器上运行的软件的一部分。

除非您可以修改服务器上的代码(GitHub),否则您无法自定义它。

答案 1 :(得分:0)

正如@Jonathon Reinhart所提到的,你必须添加use hooks才能实现你的请求。

GitHub 中,您必须为此创建WebHooks 阅读here如何在GitHub帐户下创建挂钩。

如何将webhooks添加到GitHub

在GitHub中:

1. Sign in, then select the related repository you own.
2. Click on "Settings" on the right panel.
3. Then click on "Webhooks" on the left panel.
4. Click on the "Add WebHook" Button.
5. Paste the copied URL in the URL form field.
6. Select "application/json" as the content type.
7. Select "Just the push event"
8. Leave the "Active" checkbox checked.
9. Click on "Add webhook" to save the webhook.

enter image description here

答案 2 :(得分:0)

以下是使用bash脚本进行git origin push remote的解决方法。

创建包含以下内容的文件~/.github-create-pr.sh

#!/bin/bash
#
# ~/.github-create-pr.sh

IS_GITHUB=$(git remote -v | grep "origin.*(push)" | grep -c "github.com")

if [ $IS_GITHUB -ne 0 ]; then
  REPO_NAME=$(git remote -v | grep "origin.*(push)" | sed 's/.*:\(.*\)\.git.*/\1/g')
  BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
  echo ""
  echo "To create a merge request for $BRANCH_NAME, visit:"
  echo "https://github.com/$REPO_NAME/compare/$BRANCH_NAME?expand=1"
  echo ""
fi

然后

git push && sh ~/.github-create-pr.sh