From 2dae1eb84c3c1a8a1afbbaa9b07728366ae8aa95 Mon Sep 17 00:00:00 2001 From: Grieve Date: Wed, 20 Nov 2024 17:49:09 +0800 Subject: [PATCH] ci(milestone): add workflow to assign milestone to new PR --- .github/workflows/milestone.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/milestone.yml diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml new file mode 100644 index 000000000..0c5c54c7b --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,33 @@ +name: Auto Milestone Assign + +on: + pull_request_target: + types: [opened] + +jobs: + assign-milestone: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Fetch latest milestone + id: fetch-milestone + run: | + LATEST_MILESTONE=$(gh api repos/${{ github.repository }}/milestones --jq '.[0].title') + if [ -z "$LATEST_MILESTONE" ] || [ "$LATEST_MILESTONE" == "null" ]; then + echo "No open milestone found." + exit 1 + fi + echo "latest_milestone=$LATEST_MILESTONE" >> $GITHUB_ENV + - name: Assign milestone to PR + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + milestone: ${{ env.latest_milestone }}, + })