mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
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
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Validates that the PR targets an appropriate base branch.
|
|
*
|
|
* @param {string} baseRef - The base branch ref (e.g., 'main', '0.76-stable')
|
|
* @returns {{message: string, status: 'PASS'|'FAIL', shouldAddPickLabel: boolean}}
|
|
*/
|
|
function checkBranchTarget(baseRef) {
|
|
const isMain = baseRef === 'main';
|
|
const isStable = baseRef.endsWith('-stable');
|
|
|
|
let message = '';
|
|
let status = 'PASS';
|
|
if (!isMain && !isStable) {
|
|
status = 'FAIL';
|
|
message = `> [!CAUTION]
|
|
> **Invalid Base Branch**
|
|
>
|
|
> The base branch for this PR is \`${baseRef}\`, which is not \`main\` or a \`-stable\` branch.
|
|
> [Are you sure you want to target this branch?](https://reactnative.dev/docs/contributing#pull-requests)`;
|
|
}
|
|
|
|
return {
|
|
message,
|
|
status,
|
|
shouldAddPickLabel: isStable,
|
|
};
|
|
}
|
|
|
|
module.exports = checkBranchTarget;
|