From f6ab243d2f0eea5927ebbe77bd5fb0405fa50569 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751NSS@gmail.com> Date: Wed, 20 Mar 2024 10:32:41 +0800 Subject: [PATCH] Update bot-cherry-pick.yml (#2132) --- .github/workflows/bot-cherry-pick.yml | 42 ++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bot-cherry-pick.yml b/.github/workflows/bot-cherry-pick.yml index e488e97de..71597189c 100644 --- a/.github/workflows/bot-cherry-pick.yml +++ b/.github/workflows/bot-cherry-pick.yml @@ -12,23 +12,57 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Github Rebot for Cherry Pick On Comment +name: Github Robot for Cherry Pick On Comment + on: issue_comment: types: [created] + jobs: cherry-pick: name: Cherry Pick - # && github.event.comment.user.login=='kubbot' if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/cherry-pick') runs-on: ubuntu-latest + steps: - name: Checkout the latest code uses: actions/checkout@v4 with: token: ${{ secrets.BOT_GITHUB_TOKEN }} - fetch-depth: 0 # otherwise, you will fail to push refs to dest repo + fetch-depth: 0 # To ensure all history is available for cherry-picking + - name: Automatic Cherry Pick uses: vendoo/gha-cherry-pick@v1 + with: + # Assuming the cherry-pick commit SHA is passed in the comment like '/cherry-pick sha' + commit-sha: ${{ github.event.comment.body }} + env: + GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + + - name: Create a new branch for PR + run: | + PR_BRANCH="cherry-pick-${GITHUB_SHA}-to-${{ github.base_ref }}" + git checkout -b $PR_BRANCH + git push origin $PR_BRANCH + env: + GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} + + - name: Create Pull Request + uses: actions/github-script@v5 + with: + script: | + const prTitle = "Cherry-pick to ${{ github.base_ref }}" + const prBody = "Automated cherry-pick of ${{ github.event.comment.body }}\n\n/cc @kubbot" + const base = "${{ github.base_ref }}" + const head = "cherry-pick-${{ github.sha }}-to-${{ github.base_ref }}" + const createPr = await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: prTitle, + body: prBody, + head: head, + base: base, + maintainer_can_modify: true, // Allows maintainers to edit the PR + }) env: - GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}