Skip to content

Commit

Permalink
Add CI assign current milestone for closed PR (#2516)
Browse files Browse the repository at this point in the history
Co-authored-by: Hien To <tominhhien97@gmail.com>
  • Loading branch information
hiento09 and hientominh committed Mar 27, 2024
1 parent a41fd2a commit c5c4649
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/auto-assign-milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Pipeline auto assign current milestone for PR after the PR is merge
name: Assign Milestone
on:
pull_request:
types: [closed]

jobs:
assign_milestone:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Assign Milestone
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const { number, merged } = context.payload.pull_request;
if (merged) {
const { data: milestones } = await github.issues.listMilestones({
owner,
repo,
state: 'open',
});
const mergedDate = new Date(context.payload.pull_request.merged_at);
const currentMilestone = milestones
.filter(milestone => milestone.due_on !== null)
.find((milestone) => {
const dueDate = new Date(milestone.due_on);
return mergedDate <= dueDate;
});
if (currentMilestone) {
await github.issues.update({
owner,
repo,
issue_number: number,
milestone: currentMilestone.number
});
}
}
debug: true

0 comments on commit c5c4649

Please sign in to comment.