From daf527031db8356588fdf62a5d8e87eeff79df29 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751NSS@gmail.com> Date: Thu, 4 Apr 2024 01:05:13 +0800 Subject: [PATCH] Create milestone.yml --- .github/workflows/milestone.yml | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 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 00000000..c61686a9 --- /dev/null +++ b/.github/workflows/milestone.yml @@ -0,0 +1,60 @@ +# shamelessly copied from https://github.com/sigstore/cosign/blob/main/.github/workflows/milestone.yaml + +name: milestone + +on: + pull_request_target: + types: [closed] + branches: + - main + +jobs: + milestone: + runs-on: ubuntu-latest + + permissions: + actions: none + checks: none + contents: read + deployments: none + issues: write + packages: none + pull-requests: write + repository-projects: none + security-events: none + statuses: none + + steps: + - uses: actions/github-script@v7 # v6 + with: + github-token: ${{ secrets.BOT_GITHUB_TOKEN }} + script: | + if (!context.payload.pull_request.merged) { + console.log('PR was not merged, skipping.'); + return; + } + + if (!!context.payload.pull_request.milestone) { + console.log('PR has existing milestone, skipping.'); + return; + } + + milestones = await github.rest.issues.listMilestones({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + sort: 'title', + direction: 'desc' + }) + + if (milestones.data.length === 0) { + console.log('There are no milestones, skipping.'); + return; + } + + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + milestone: milestones.data[0].number + });