mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Accept stacked PR base branches in analyze-pr (#59109)
Summary: The `analyze_pr` check fails every PR in a stack above the first (example: https://github.com/react/react-native/pull/58867), since each targets the branch of the PR below it rather than `main` or a `-stable` branch. - Pass the branch target check when the base branch is the head of another open PR in the repo. - Other base branches still fail as before, and the parent PR's own check still guards its target. NOTE: The workflow runs on `pull_request_target` from `main`, so this takes effect only after it lands. Changelog: [Internal] Pull Request resolved: https://github.com/react/react-native/pull/59109 Test Plan: ``` yarn jest .github/workflow-scripts/__tests__/checkBranchTarget-test.js ``` Checked the lookup the workflow makes against GitHub: ``` gh api 'repos/react/react-native/pulls?state=open&head=react:pr58950' ``` ✅ Returns https://github.com/react/react-native/issues/58950, so https://github.com/react/react-native/issues/58951 (based on `pr58950`) will pass. ℹ️ A non-PR branch returns no results and still fails. Reviewed By: christophpurrer Differential Revision: D125867260 Pulled By: Abbondanzo fbshipit-source-id: e30b4768525f5c4938e782231b9b9fc435953f42
This commit is contained in:
1 parent
7439937ef9
commit
adc28a0b60
3 files changed
+58
-2
No files matched your search
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
const checkBranchTarget = require('../checkBranchTarget');
|
||||
|
||||
describe('checkBranchTarget', () => {
|
||||
test('passes for main', () => {
|
||||
expect(checkBranchTarget('main')).toEqual({
|
||||
message: '',
|
||||
status: 'PASS',
|
||||
shouldAddPickLabel: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('passes for a stable branch and adds the pick label', () => {
|
||||
expect(checkBranchTarget('0.76-stable')).toEqual({
|
||||
message: '',
|
||||
status: 'PASS',
|
||||
shouldAddPickLabel: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('passes for the head branch of another open PR', () => {
|
||||
expect(checkBranchTarget('pr58950', true)).toEqual({
|
||||
message: '',
|
||||
status: 'PASS',
|
||||
shouldAddPickLabel: false,
|
||||
});
|
||||
});
|
||||
|
||||
test('fails for any other branch', () => {
|
||||
const {message, status, shouldAddPickLabel} =
|
||||
checkBranchTarget('feature-branch');
|
||||
|
||||
expect(status).toBe('FAIL');
|
||||
expect(message).toContain('`feature-branch`');
|
||||
expect(shouldAddPickLabel).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -13,15 +13,17 @@
|
||||
* Validates that the PR targets an appropriate base branch.
|
||||
*
|
||||
* @param {string} baseRef - The base branch ref (e.g., 'main', '0.76-stable')
|
||||
* @param {boolean} [isStacked] - Whether the base branch is the head of another
|
||||
* open PR, as in a stack of PRs
|
||||
* @returns {{message: string, status: 'PASS'|'FAIL', shouldAddPickLabel: boolean}}
|
||||
*/
|
||||
function checkBranchTarget(baseRef) {
|
||||
function checkBranchTarget(baseRef, isStacked = false) {
|
||||
const isMain = baseRef === 'main';
|
||||
const isStable = baseRef.endsWith('-stable');
|
||||
|
||||
let message = '';
|
||||
let status = 'PASS';
|
||||
if (!isMain && !isStable) {
|
||||
if (!isMain && !isStable && !isStacked) {
|
||||
status = 'FAIL';
|
||||
message = `> [!CAUTION]
|
||||
> **Invalid Base Branch**
|
||||
|
||||
@@ -44,8 +44,15 @@ jobs:
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.issue.number,
|
||||
});
|
||||
const {data: basePullRequests} = await github.rest.pulls.list({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
state: 'open',
|
||||
head: `${context.repo.owner}:${pullRequest.base.ref}`,
|
||||
});
|
||||
const {message, status, shouldAddPickLabel} = checkBranchTarget(
|
||||
pullRequest.base.ref,
|
||||
basePullRequests.length > 0,
|
||||
);
|
||||
|
||||
if (shouldAddPickLabel) {
|
||||
|
||||
Reference in new issue
Block a user