-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI assign current milestone for closed PR (janhq#2516)
Co-authored-by: Hien To <[email protected]>
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|