github请求超时_创建请求请求,然后从命令行合并多个github仓库

本文介绍了一种使用Bash脚本结合GitHub的Hub工具和API,从命令行批量创建并合并多个GitHub仓库的拉取请求的方法。通过这种方式,可以在不依赖GitHub UI的情况下自动化PR流程,节省手动操作的时间。
摘要由CSDN通过智能技术生成

github请求超时

The problem I’m trying to solve: how to create PRs for multiple GitHub repositories and then merge those repos via CLI—without using the GitHub UI!

我要解决的问题是:如何为多个GitHub存储库创建PR,然后通过CLI合并这些存储库,而无需使用GitHub UI!

I decided to take advantage of GitHub’s Hub, which GitHub describes as “an extension to command-line git” to create the pull requests, and then use GitHub’s API to merge those PRs. I work on a Mac, so I used Brew to install Hub: brew install hub

我决定利用GitHub的Hub (GitHub将其描述为“命令行git的扩展”)创建拉取请求,然后使用GitHub的API合并这些PR。 我在Mac上工作,所以我使用Brew安装Hub: brew install hub

To solve the problem, I developed this Bash script to create the Pull Requests (Note that anything in less than/greater than brackets <> needs to be altered to match your setup):

为了解决该问题,我开发了这个Bash脚本来创建请求请求(请注意,小于/大于括号<>任何内容都需要更改以匹配您的设置):

#!/bin/bashdate=$(date +%F-%H)
curdir=$(pwd)
echo '#!/bin/bash' >> merge_all-${date}.sh
echo 'source .env' >> merge_all-${date}.sh
for path in */<path_goes_here>*
do
[[ ! -d "$path" ]] && continue
echo "$path"
cd "$path"
pr=$(hub pull-request --base <
echo "$pr"
repo=$(echo "$pr" | awk -F "/" {'print $5'})
pull_number=$(echo "$pr" | awk -F "/" {'print $7'})
cd $curdir
echo "echo \"$repo\"" >> merge_all-${date}.sh
echo "curl -s -X PUT \
-H \"Authorization: token \$token\" \
https://api.github.com/repos/<OWNER>/$repo/pulls/$pull_number/merge" >> merge_all-${date}.sh
done

This script lives at the root of a directory that contains several repos. It loops through the directories using the $path variable, creates the PR, then adds that PR to a new script that is generated in the root directory. That generated script will be called merge_all-<Date_of_Execution>.sh and will contain several curl commands that use the GitHub API to then merge the PRs. I separated Pull Requesting and Merging into distinct scripts in order to allow time for peer reviewing.

该脚本位于包含多个存储库的目录的根目录中。 它使用$path变量遍历目录,创建PR,然后将该PR添加到在根目录中生成的新脚本中。 生成的脚本将称为merge_all-<Date_of_Execution>.sh ,并将包含几个使用GitHub API合并PR的curl命令。 我将“拉取请求和合并”分为不同的脚本,以便留出时间进行同行评审。

Note that the GitHub API requires an Authorization token, which you can set up following GitHub’s documentation. That token will need to be in a .envfile that also lives at the root directory. Here’s what that .env file looks like:

请注意,GitHub API需要一个Authorization令牌,您可以按照GitHub的文档进行设置。 该令牌必须位于一个.env文件中,该文件也位于根目录中。 该.env文件如下所示:

token=“<GitHub_Token_Goes_Here>”

If everything goes well after running the pull request creation script, you should have a script that looks somewhat like this:

如果在运行请求请求创建脚本后一切正常,则应该有一个类似于以下内容的脚本:

Image for post

If this helps you out at all, then congrats on all the time you’ll save not having to manually merge individual repos in the GitHub GUI 🙂

如果这完全可以帮助您,那么恭喜您节省了所有时间,不必在GitHub GUI中手动合并单个存储库🙂

翻译自: https://itnext.io/create-pull-requests-and-then-merge-multiple-github-repos-from-the-command-line-ceef76c3cf65

github请求超时

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值