You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2023/05/23 10:12:55 UTC

[incubator-devlake] branch main updated: feat: improve the auto cherry pick action (#5262)

This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 1e107c8a7 feat: improve the auto cherry pick action (#5262)
1e107c8a7 is described below

commit 1e107c8a7cd431c17f48c4e205eb8019c3d09b6f
Author: 青湛 <0x...@gmail.com>
AuthorDate: Tue May 23 18:12:50 2023 +0800

    feat: improve the auto cherry pick action (#5262)
---
 .github/actions/auto-cherry-pick/action.yml     |  3 +-
 .github/actions/auto-cherry-pick/cherry-pick.sh | 40 +++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/.github/actions/auto-cherry-pick/action.yml b/.github/actions/auto-cherry-pick/action.yml
index 39b66467a..4d0966825 100644
--- a/.github/actions/auto-cherry-pick/action.yml
+++ b/.github/actions/auto-cherry-pick/action.yml
@@ -38,8 +38,9 @@ runs:
       shell: bash
       env:
         GH_TOKEN: ${{ github.token }}
-        REPOSITORY: ${{ github.repository }}
         PR_NUMBER: ${{ github.event.pull_request.number }}
+        PR_TITLE: ${{ github.event.pull_request.title }}
+        PR_BODY: ${{ github.event.pull_request.body }}
         LABEL_NAME: ${{ github.event.label.name }}
         AUTHOR_EMAIL: ${{ inputs.author_email }}
         AUTHOR_NAME: ${{ inputs.author_name }}
diff --git a/.github/actions/auto-cherry-pick/cherry-pick.sh b/.github/actions/auto-cherry-pick/cherry-pick.sh
index 45843881e..97c697d57 100644
--- a/.github/actions/auto-cherry-pick/cherry-pick.sh
+++ b/.github/actions/auto-cherry-pick/cherry-pick.sh
@@ -17,11 +17,19 @@
 
 #!/bin/bash
 
+set -e
+
 TARGET_BRANCH="release-${LABEL_NAME##*-}"
 PR_BRANCH="auto-cherry-pick-$TARGET_BRANCH-$GITHUB_SHA"
+AUTO_CHERRY_PICK_LABEL="bot/auto-cherry-pick"
+AUTO_CHERRY_PICK_VERSION_LABEL="bot/auto-cherry-pick-for-$TARGET_BRANCH"
+AUTO_CHERRY_PICK_FAILED_LABEL="bot/auto-cherry-pick-failed"
+AUTO_CHERRY_PICK_COMPLETED_LABEL="bot/auto-cherry-pick-completed"
 
-echo "REPOSITORY: $REPOSITORY"
+echo "==================== Basic Info ===================="
 echo "PR Number: $PR_NUMBER"
+echo "PR Title: $PR_TITLE"
+echo "PR Body: $PR_BODY"
 echo "Label: $LABEL_NAME"
 echo "GitHub SHA: $GITHUB_SHA"
 echo "Author Email: $AUTHOR_EMAIL"
@@ -30,6 +38,7 @@ echo "Assignees: $ASSIGNEES"
 echo "Target Branch: $TARGET_BRANCH"
 echo "PR Branch: $PR_BRANCH"
 
+echo "==================== Git Cherry Pick ===================="
 git config --global user.email "$AUTHOR_EMAIL"
 git config --global user.name "$AUTHOR_NAME"
 
@@ -37,8 +46,33 @@ git remote update
 git fetch --all
 git restore .
 git checkout -b $PR_BRANCH origin/$TARGET_BRANCH
-git cherry-pick $GITHUB_SHA
+git cherry-pick -m 1 --strategy=recursive --strategy-option=theirs $GITHUB_SHA || (
+	gh pr comment $PR_NUMBER --body "🤖 The current file has a conflict, and the pr cannot be automatically created."
+	gh pr edit $PR_NUMBER --add-label $AUTO_CHERRY_PICK_FAILED_LABEL || (
+		gh label create $AUTO_CHERRY_PICK_FAILED_LABEL -c "#D93F0B" -d "auto cherry pick failed"
+		gh pr edit $PR_NUMBEr --add-label $AUTO_CHERRY_PICK_FAILED_LABEL
+	)
+	exit 1
+)
 git push origin $PR_BRANCH
 
-gh pr create -B $TARGET_BRANCH -H $PR_BRANCH -t "cherry-pick: $PR_NUMBER" -b "this a auto create pr!<br />cherry pick from https://github.com/$REPOSITORY/pull/$PR_NUMBER" -a $ASSIGNEES
+echo "==================== GitHub Auto Create PR ===================="
+AUTO_CREATED_PR_LINK=$(gh pr create \
+	-B $TARGET_BRANCH \
+	-H $PR_BRANCH \
+	-t "$PR_TITLE (cherry-picked-from #$PR_NUMBER)" \
+	-b "$PR_BODY" \
+	-a $ASSIGNEES)
+
 gh pr comment $PR_NUMBER --body "🤖 cherry pick finished successfully 🎉!"
+gh pr edit $PR_NUMBER --add-label $AUTO_CHERRY_PICK_COMPLETED_LABEL || (
+	gh label create $AUTO_CHERRY_PICK_COMPLETED_LABEL -c "#0E8A16" -d "auto cherry pick completed"
+	gh pr edit $PR_NUMBER --add-label $AUTO_CHERRY_PICK_COMPLETED_LABEL
+)
+
+gh pr comment $AUTO_CREATED_PR_LINK --body "🤖 this a auto create pr!cherry picked from #$PR_NUMBER."
+gh pr edit $AUTO_CREATED_PR_LINK --add-label "$AUTO_CHERRY_PICK_LABEL,$AUTO_CHERRY_PICK_VERSION_LABEL" || (
+	gh label create $AUTO_CHERRY_PICK_LABEL -c "#5319E7" -d "auto cherry pick pr"
+	gh label create $AUTO_CHERRY_PICK_VERSION_LABEL -c "#5319E7" -d "auto cherry pick pr for $TARGET_BRANCH"
+	gh pr edit $AUTO_CREATED_PR_LINK --add-label "$AUTO_CHERRY_PICK_LABEL,$AUTO_CHERRY_PICK_VERSION_LABEL"
+)