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 .env
file 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:
如果在运行请求请求创建脚本后一切正常,则应该有一个类似于以下内容的脚本:
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中手动合并单个存储库🙂
github请求超时