From cf83c8705d70a43ea652e0e35126787ab8b2f7f1 Mon Sep 17 00:00:00 2001 From: baegteun Date: Thu, 7 Mar 2024 17:52:56 +0900 Subject: [PATCH] =?UTF-8?q?:construction=5Fworker:=20::=20[#433]=20Issue?= =?UTF-8?q?=EC=9D=98=20Labels=EC=9D=84=20PR=EB=A1=9C=20=EC=98=AE=EA=B8=B0?= =?UTF-8?q?=EB=8A=94=20=EC=9E=90=EB=8F=99=ED=99=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/IssueToPRLabelSync.yml | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/IssueToPRLabelSync.yml diff --git a/.github/workflows/IssueToPRLabelSync.yml b/.github/workflows/IssueToPRLabelSync.yml new file mode 100644 index 000000000..104c461f9 --- /dev/null +++ b/.github/workflows/IssueToPRLabelSync.yml @@ -0,0 +1,52 @@ +name: Issue to PR label sync + +on: + pull_request: + types: + - opened + - reopened + +jobs: + add-label: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Extract issue number from PR title + id: extract-issue-number + run: echo "issue_number=$(echo ${{ github.event.pull_request.title }} | grep -oP '\(#[0-9]+\)' | grep -oP '[0-9]+')" >> $GITHUB_OUTPUT + + - name: Check if issue number is found + id: check-issue-number + run: echo "valid_format=$(if [[ -n "${{ steps.extract-issue-number.outputs.issue_number }}" ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT + + - name: Add label if valid issue format + if: steps.check-issue-number.outputs.valid_format == 'true' + run: | + ISSUE_NUMBER="${{ steps.extract-issue-number.outputs.issue_number }}" + echo "Found Issue Number: $ISSUE_NUMBER" + gh issue view $ISSUE_NUMBER --json labels --template "{{range .labels}}'{{.name}}',{{end}}" \ + | sed 's/.$//g' \ + | xargs -I LABELS gh pr edit ${{ github.event.number }} --add-label "LABELS" + env: + GH_TOKEN: ${{ github.token }} + + - name: Skip if invalid issue format + if: steps.check-issue-number.outputs.valid_format == 'false' + run: echo "Invalid issue format. Skipping label addition." + + - name: Comment success result to PR + uses: mshick/add-pr-comment@v2 + if: steps.check-issue-number.outputs.valid_format == 'true' + with: + message: "## ✅ 이슈와 PR의 Labels 동기화를 성공했어요!" + allow-repeats: true + + - name: Comment skip result to PR + uses: mshick/add-pr-comment@v2 + if: steps.check-issue-number.outputs.valid_format == 'false' + with: + message: "## 🛠️ 이슈와 PR의 Labels 동기화를 스킵했어요." + allow-repeats: true