-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github workflow to check for Change log entry
- Loading branch information
Showing
1 changed file
with
72 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,72 @@ | ||
name: Ensure change log entry | ||
on: | ||
pull_request: | ||
types: [opened, reopened, edited] | ||
|
||
jobs: | ||
check: | ||
# permissions: | ||
# issues: write | ||
# contents: read | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Find changelog entry | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{secrets.GHA_PAT}} | ||
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) { | ||
return | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: ${{ github.event.pull_request.number }}, | ||
body: message | ||
}) | ||
} |