Skip to content

Warn on missing "Change log entry" section #17

Warn on missing "Change log entry" section

Warn on missing "Change log entry" section #17

name: Ensure change log entry
on:
pull_request:
types: [opened, reopened, edited]
jobs:
ensure_changelog_entry:
permissions: read-all
runs-on: ubuntu-latest
steps:
- name: Find changelog entry
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Is author a member of the DataDog Org.
// NOTE: https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
const creator = context.payload.sender.login
try {
response = await github.rest.orgs.checkMembershipForUser({
org: context.repo.owner,
username: creator
})
isMember = response.status == 204
} catch (e) {
console.log(e)
isMember = false
}
const username = !isMember ? "@DataDog/ruby-guild" : `@${ creator }`
const message = `:wave: Hey ${ username }, please fill "Change log entry" section in the pull request description.
If changes need to be present in [CHANGELOG.md](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md) you can state it this way
\`\`\`md
**Change log entry**
Yes. A brief summary to be placed into the CHANGELOG.md
\`\`\`
_(possible answers Yes/Yep/Yeah)_
Or you can opt out like that
\`\`\`md
**Change log entry**
None.
\`\`\`
_(possible answers No/Nope/None)_`
const regex = /\*\*Change log entry\*\*\s+(?:(?<answer_yes>yes|yep|yeah)(?:\.\s*(?<yes_message>.*))?|(?<answer_no>no|nope|none)\.?)\s*/mi
const entry = context.payload.pull_request.body.match(regex)
const isWriteComment =
!isMember
|| null === entry
|| (undefined === entry.groups.answer_yes && undefined === entry.groups.answer_no)
|| (undefined !== entry.groups.answer_yes && undefined === entry.groups.yes_message)
? true : false
if (isWriteComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
body: message
})
}