mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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:
1 parent
5e41043fb5
commit
1ee6fdc571
2 files changed
+63
-2
No files matched your search
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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;
|
||||
Reference in new issue
Block a user