在Git Push上创建请求请求 [英] Create Pull Request on Git Push
问题描述
我有GitHub存储库,其中有2个分支:"master"和& 开发".
I have GitHub repository with 2 branches: "master" & "develop".
我们的工作流程是,任何代码都应提交到"develop"分支,然后再推送到GitHub,然后应创建一个Pull Request,以将提交合并到"master"分支.
The workflow for us is that any code should be committed to the "develop" branch then pushed to GitHub, then a Pull Request should be created to merge the commits into the "master" branch.
我正在尝试编写一个操作,一旦开发人员将提交提交到分支"develop"并具有以下脚本,该操作将创建拉取请求":
I am trying to write an Action that will create a Pull Request once a developer pushes commits to the branch "develop" and had the following script:
name: Create pull request
on:
push:
branches:
- develop
jobs:
prForMasterBranch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
commit-message: update master branch
title: Update master branch
branch: develop
我可以看到此操作已在"develop"分支的"Push"事件上成功执行,但是看不到任何新的Pull Request!
I can see that this action has executed successfully on "Push" event of the "develop" branch, but I can't see any new Pull Requests!
我检查了操作日志,并在创建请求请求结束时找到了以下几行:
I checked the logs for the action and found these lines at the end of pull request creation:
将拉取请求分支推送到起源/开发"
分支开发"与基础分支主"不再不同
关闭拉取请求并删除分支"develop"
Pushing pull request branch to 'origin/develop'
Branch 'develop' no longer differs from base branch 'master'
Closing pull request and deleting branch 'develop'
似乎我缺少了一些东西,但无法弄清楚.
It seems I am missing something, but couldn't figure it out.
感谢您的帮助.
推荐答案
If you look at the documentation of the create-pull-request action, it mentions that
创建请求请求"操作将:
Create Pull Request action will:
- 在动作"工作空间中检查存储库更改.这包括:
- 未跟踪的(新)文件
- 跟踪(已修改)的文件
- 工作流中尚未推送的承诺
- Check for repository changes in the Actions workspace. This includes:
- untracked (new) files
- tracked (modified) files
- commits made during the workflow that have not been pushed
它总是需要一个中间分支来提交更改.
It would always need an intermediary branch where it can commit the changes.
因此,如果您按以下方式修改工作流配置,请添加
Reset master branch
步骤以从远程develop
分支获取最新更改并重置master
分支,并为操作(工作流)指定branch: temp
会创建一个temp
分支,其提交与您推送到develop
分支的提交相同,并打开从temp
到master
分支的PR.在随后的开发承诺中,它将继续对temp
分支进行相同的更改,并类似地打开PR或更新现有PR.So if you modify your workflow config as below, adding the
Reset master branch
step to get the latest changes from the remotedevelop
branch and reset themaster
branch, and specifybranch: temp
for the action, the workflow would create atemp
branch with the same commits that you have pushed todevelop
branch and open a PR fromtemp
tomaster
branch. In subsequent commits to develop, it would keep on making the same changes totemp
branch and open a PR similarly or update the existing PR.name: Create pull request on: push: branches: - develop jobs: prForMasterBranch: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: ref: master - name: Reset master branch run: | git fetch origin develop:develop git reset --hard develop - name: Create Pull Request uses: peter-evans/create-pull-request@v2 with: commit-message: update master branch title: Update master branch branch: temp
请注意,
temp
分支将具有推送到develop
分支的确切提交.Note that the
temp
branch will have the exact commits that are pushed to thedevelop
branch.这篇关于在Git Push上创建请求请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!