在Git Push上创建请求请求 [英] Create Pull Request on Git Push

查看:117
本文介绍了在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分支的提交相同,并打开从tempmaster分支的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 remote develop branch and reset the master branch, and specify branch: temp for the action, the workflow would create a temp branch with the same commits that you have pushed to develop branch and open a PR from temp to master branch. In subsequent commits to develop, it would keep on making the same changes to temp 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 the develop branch.

      这篇关于在Git Push上创建请求请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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