Skip to content

feat: Aggregate UserActions #2725

feat: Aggregate UserActions

feat: Aggregate UserActions #2725

Workflow file for this run

# Validates the format of a PR title and body. Because the title will become the default commit message on squash-merge,
# it should follow the conventional commit format and be 70 characters long or fewer. Because the body will later be
# used in creating docs-site release notes, it must have a summary paragraph (70+ characters) followed by `\n---`.
name: "Validate PR"
on:
pull_request:
types:
- opened
- edited
- synchronize
jobs:
validate-pr-format:
name: Validate PR Format
runs-on: ubuntu-latest
steps:
- name: Parse PR Contents
id: parse-pr-contents
uses: actions/github-script@v6
with:
script: |
// Helpers for logging
const head = (text) => { core.info(`\u001b[36;1m${text}`) } // cyan bold
const echo = (text) => { core.info(text) }
const highlight = '\x1b[30;43m' // black on yellow
const greenBold = '\x1b[32;1m'
head('TITLE')
echo('----------------------------------------------------------------------')
const title = context.payload.pull_request.title.replaceAll(/(?:[ \-(]*)(?:NR|NEWRELIC)-\d+(?:[, \-)]*)/gi, '')
if (title.length > 70) echo(title.substring(0, 70) + highlight + title.substring(70))
else echo(title)
echo('')
head('DESCRIPTION')
echo('----------------------------------------------------------------------')
const prBody = (context.payload.pull_request.body || '').trim()
const headerMarker = prBody.indexOf('\n---')
const description = prBody.substring(0, headerMarker).trim()
if (prBody === '') echo(highlight + '[missing description header]')
else if (headerMarker === -1) echo(highlight + '[missing `---` line to terminate description header]')
else if (description.length === 0) echo(highlight + '[missing description header]')
else if (description.length < 70 && context.payload.pull_request.title.substring(0, 6) !== 'chore:') {
echo(description + highlight + (new Array(70 - description.length + 1)).join('\xa0'))
} else echo(description)
echo('')
const errors = []
if (context.payload.pull_request.title.length > 70) errors.push('PR title is longer than 70 characters and would be truncated. Please shorten.')
if (!(/(?:feat|fix|security|chore)(?:\([^)]+\))?: .*/g).test(context.payload.pull_request.title)) errors.push('Title does not start with a type of `feat`, `fix`, `security`, or `chore` followed by an optional scope then a colon and a space.')
if (prBody === '') errors.push('The PR description cannot be blank.')
else if (headerMarker === -1) errors.push('The PR description is missing a horizontal rule (`---`) on a line by itself to terminate the header section.')
if (description.length < 70 && context.payload.pull_request.title.substring(0, 6) !== 'chore:') errors.push('The top of the PR description must contain a summary paragraph of 70 characters or more followed by a horizontal rule (`---`) on a line by itself.');
if (errors.length) {
core.setFailed('Validation Failed')
echo('- ' + errors.join('\n- '))
} else {
echo(greenBold + 'Validation Succeeded')
echo('PR title and description are in a valid format for the change type.')
}