簡體   English   中英

在 Git 推送上創建拉取請求

[英]Create Pull Request on Git Push

我有 GitHub 存儲庫,有 2 個分支:“master”和“develop”。

我們的工作流程是,任何代碼都應該提交到“develop”分支,然后推送到 GitHub,然后應該創建一個 Pull Request 將提交合並到“master”分支。

我正在嘗試編寫一個操作,一旦開發人員將提交推送到“開發”分支並具有以下腳本,它將創建一個拉取請求:

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 Requests!

我檢查了該操作的日志,並在拉取請求創建結束時發現了這些行:

將拉取請求分支推送到“起源/開發”
分支“開發”不再與基本分支“主”不同
關閉拉取請求並刪除分支“開發”

似乎我錯過了一些東西,但無法弄清楚。

任何幫助表示贊賞。

如果您查看 create-pull-request 操作的文檔,它會提到

創建拉取請求操作將:

  • 檢查操作工作區中的存儲庫更改。 這包括:
    • 未跟蹤的(新)文件 - 跟蹤的(修改的)文件 - 在工作流程中進行的未推送的提交
  • 將所有更改提交到新分支,或更新現有的拉取請求分支。
  • 創建一個拉取請求以將新分支合並到基礎——工作流中簽出的分支。

它總是需要一個可以提交更改的中間分支。

因此,如果您如下修改工作流配置,添加Reset master branch步驟以從遠程develop分支獲取最新更改並重置master分支,並指定branch: temp為操作,工作流將創建一個temp分支您推送到develop分支並打開從temp分支到master分支的 PR 的相同提交。 在隨后的開發提交中,它將繼續對temp分支進行相同的更改並類似地打開 PR 或更新現有的 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@v4
        with:
          commit-message: update master branch
          title: Update master branch
          branch: temp
          delete-branch: true
          assignees: user-you-want-to
          reviewers: user-you-want-to

請注意, temp分支將具有推送到develop分支的確切提交。

沒有中間分支的 PR

代替

你想要的團隊

或者

你想要的用戶

如果需要,與您想要分配的團隊或用戶一起,如果不評論他們。

name: Create pull request
on:
  push:
    branches:
      - develop
jobs:
  reatePullRequest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: master
      - name: Get latest changes
        run: |
          git fetch origin develop:develop
          git reset --hard develop
      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v4
        with:
          commit-message: Update master
          committer: GitHub <noreply@github.com>
          author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
          signoff: false
          branch: develop
          title: 'Updating master'
          labels: |
            update
          reviewers: user-you-want-to
          team-reviewers: |
            team-you-want-to
          draft: false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM