Add branch targeting check to analyze-pr workflow (#55383)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55383

Adds a branch targeting validation that replaces the equivalent Danger.js check.
  The check validates that PRs target either `main` or a `-stable` branch, and
  automatically adds the "Pick Request" label when targeting stable branches.

  - Created `checkBranchTarget.js` - pure function returning validation message
  - Added check step to `annotate-pr.yml` that calls the JS and adds labels
  - Added `issues: write` permission for label functionality

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D91685081

fbshipit-source-id: 87e7124f7d825b51cb791dc94720c487ff95d414
This commit is contained in:
Emily Brown authored and meta-codesync[bot] committed 2026-02-06 08:14:53 -08:00
1 parent 5e41043fb5
commit 1ee6fdc571
2 files changed
+63 -2

No files matched your search

+23 -2
View File
@@ -6,6 +6,7 @@ on:
permissions:
pull-requests: write
issues: write
jobs:
analyze-pr:
@@ -25,13 +26,33 @@ jobs:
script: |
const validatePRBody = require('./.github/workflow-scripts/validatePRBody.js');
const {message, status} = validatePRBody(context.payload.pull_request.body);
core.setOutput('message', message);
core.setOutput('status', status);
- name: Check branch target
id: check-branch-target
uses: actions/github-script@v8
with:
script: |
const checkBranchTarget = require('./.github/workflow-scripts/checkBranchTarget.js');
const baseRef = context.payload.pull_request.base.ref;
const {message, status, shouldAddPickLabel} = checkBranchTarget(baseRef);
if (shouldAddPickLabel) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['Pick Request'],
});
}
core.setOutput('message', message);
core.setOutput('status', status);
- name: Post PR comment
uses: ./.github/actions/post-pr-comment
with:
marker: '<!-- analyze-pr -->'
sections: '[${{ toJSON(steps.check-pr-body.outputs.message) }}]'
sections: '[${{ toJSON(steps.check-pr-body.outputs.message) }}, ${{ toJSON(steps.check-branch-target.outputs.message) }}]'
- name: Fail if validation errors
if: steps.check-pr-body.outputs.status == 'FAIL'
if: steps.check-pr-body.outputs.status == 'FAIL' || steps.check-branch-target.outputs.status == 'FAIL'
run: exit 1