Fix milestone reminder #5
Workflow file for this run
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
name: Milestone Reminder | |
on: | |
pull_request: | |
jobs: | |
milestone-reminder: | |
name: Remind to set milestone | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 5 | |
permissions: | |
pull-requests: write | |
issues: read | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | # js | |
const { getLinkedIssues } = require('${{ github.workspace }}/release/utils/index.js'); | |
const owner = context.repo.owner; | |
const repo = context.repo.repo; | |
const pullNumber = '${{ github.event.pull_request.number }}'; | |
function getMilestone(pullOrIssue) { | |
// pull has pull.data.milestone, issue has issue.milestone | |
return pullOrIssue?.data?.milestone || pullOrIssue?.milestone; | |
} | |
const pull = await github.rest.pulls.get({ | |
owner, | |
repo, | |
pull_number: pullNumber, | |
}); | |
if (getMilestone(pull)) { | |
console.log("Pull request has milestone", pull.data.milestone?.title); | |
process.exit(0); | |
} | |
// the github API doesn't expose linked issues, so we have to parse the body ourselves | |
const linkedIssues = getLinkedIssues(pull); | |
if (Array.isArray(linkedIssues) && linkedIssues.length > 0) { | |
console.log('linked issue(s) found'); | |
linkedIssues.forEach(async (issueId, index) => { | |
const issue = await github.rest.issues.get({ | |
owner, | |
repo, | |
issue_number: issueId, | |
}); | |
const milestone = getMilestone(issue); | |
if (milestone) { | |
console.log(`Linked issue #${issueId} has milestone`, milestone.title); | |
index === linkedIssues.length -1 && process.exit(0); | |
} else { | |
console.log("No milestone found"); | |
const author = pull.data.user.login; | |
const guideLink = "https://www.notion.so/metabase/Metabase-Branching-Strategy-6eb577d5f61142aa960a626d6bbdfeb3?pvs=4#3dea255ffa3b4f74942a227844e889fa"; | |
const message = `@${author} Did you forget to add a milestone to the issue for this PR? _[When and where should I add a milestone?](${guideLink})_`; | |
await github.rest.issues.createComment({ | |
owner, | |
repo, | |
issue_number: pullNumber, | |
body: message, | |
}); | |
// Exit as soon as we found an issue without a milestone and alerted the author. | |
process.exit(0); | |
} | |
}); | |
} | |