diff --git a/.github/workflows/danger-js.yml b/.github/workflows/danger-js.yml index 95d4c567888e..b2f6c6decbe8 100644 --- a/.github/workflows/danger-js.yml +++ b/.github/workflows/danger-js.yml @@ -8,8 +8,7 @@ on: - unlabeled - edited branches: - - main - - next + - "**" concurrency: group: ${{ github.workflow }}-${{ github.event.number }} diff --git a/scripts/dangerfile.js b/scripts/dangerfile.js index a5d1407eaa3f..27abd980000f 100644 --- a/scripts/dangerfile.js +++ b/scripts/dangerfile.js @@ -13,7 +13,7 @@ * Why: We want Danger to run as fast as possible in CI without installing dependencies or running * build processes. */ -import { danger, fail } from 'danger'; +import { danger, fail, warn } from 'danger'; /** * Returns the intersection of two arrays @@ -145,6 +145,28 @@ const checkManualTestingSection = (body) => { } }; +const checkTargetBranch = () => { + const targetBranch = danger.github.pr.base.ref; + const authorAssociation = danger.github.pr.author_association; + + // Only check for non-team members (not OWNER or MEMBER) + if (['OWNER', 'MEMBER'].includes(authorAssociation)) { + return; + } + + if (targetBranch === 'main' || targetBranch.includes('release')) { + fail( + `This PR targets \`${targetBranch}\`, but it should target \`next\`. Please update the base branch of your PR.` + ); + } else if (targetBranch !== 'next') { + warn( + `This PR targets \`${targetBranch}\`. The default branch for contributions is \`next\`. Please make sure you are targeting the correct branch.` + ); + } +}; + +checkTargetBranch(); + if (prLogConfig) { checkRequiredLabels(labels.map((l) => l.name)); checkPrTitle(danger.github.pr.title);