Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(eslint-plugin): [restrict-template-expressions] check base types in allow list #757

fix(eslint-plugin): [restrict-template-expressions] check base types in allow list

fix(eslint-plugin): [restrict-template-expressions] check base types in allow list #757

# IMPORTANT: Do not reuse old name of "Semantic Breaking Change PR Test" here
name: Breaking Change Validation
on:
# WARNING: Using pull_request_target here because we want to validate PRs on forks
# pull_request_target can be UNSAFE because it runs in the TARGET repo context (not fork context).
# DO NOT CHECK OUT THE REPO IN THIS WORKFLOW
pull_request_target:
types:
- opened
- edited
- synchronize
- labeled
- unlabeled
# IMPORTANT: Minimal permissions necessary for this workflow to function
permissions:
pull-requests: read
jobs:
validate:
name: Validate Breaking Change PR
runs-on: ubuntu-latest
steps:
- name: Check PR title and body
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function getPullRequest() {
const pr = context.payload.pull_request;
if (!pr) {
throw new Error("This action can only be run on pull_request events.");
}
const owner = pr.base.repo.owner.login;
const repo = pr.base.repo.name;
const pull_number = pr.number;
const { data } = await github.rest.pulls.get({
owner,
repo,
pull_number,
});
return data;
}
function checkTitle(title) {
if (/^[a-z]+(\([a-z-]+\))?!: /.test(title)) {
throw new Error(
`Do not use exclamation mark ('!') to indicate breaking change in the PR Title.`,
);
}
}
function checkDescription(body, labels) {
if (!labels.some(label => label.name === 'breaking change')) {
return;
}
const [firstLine, secondLine] = body.split(/\r?\n/);
if (!firstLine || !/^BREAKING CHANGE:/.test(firstLine)) {
throw new Error(
`Breaking change PR body should start with "BREAKING CHANGE:". See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}
if (!secondLine) {
throw new Error(
`The description of breaking change is missing. See https://typescript-eslint.io/maintenance/releases#2-merging-breaking-changes.`,
);
}
}
const pr = await getPullRequest();
checkTitle(pr.title);
checkDescription(pr.body ?? '', pr.labels);