Skip to content

A new good issue

A new good issue #11

name: Assign Milestone on Close
env:
MILESTONE_ID: 1
on:
issues:
types: [closed]
pull_request_target:
types: [closed]
permissions:
issues: write
pull-requests: write
jobs:
assign-milestone:
runs-on: ubuntu-latest
steps:
- name: Get payload content
id: payload-content
uses: actions/github-script@v7
with:
script: return JSON.stringify(context.payload);
result-encoding: string
- name: Print payload content
id: print-payload
run: echo "${{steps.get-payload.outputs.result}}"
- name: Check if milestone is set
id: check-milestone
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueOrPr = context.payload.issue || context.payload.pull_request;
if (!issueOrPr.milestone) {
core.setOutput('milestoneNotSet', 'true');
} else {
core.setOutput('milestoneNotSet', 'false');
}
- name: Check completed or merged
id: check-done
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// No need to check if this is a merged PR, as pull_request_target takes care of that for us.
if (context.payload.issue && context.payload.issue.state_reason === "completed") {
core.setOutput('isDone', 'true');
} else {
core.setOutput('isDone', 'false');
}
- name: Assign default milestone
if: steps.check-milestone.outputs.milestoneNotSet == 'true' && steps.check-done.outputs.isDone== 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueOrPrNumber = (context.payload.issue || context.payload.pull_request).number;
const repository = context.repo;
await github.rest.issues.update({
...repository,
issue_number: issueOrPrNumber,
milestone: process.env.MILESTONE_ID
});