diff --git a/.github/actions/javascript/failureNotifier/failureNotifier.ts b/.github/actions/javascript/failureNotifier/failureNotifier.ts index d8c1ca53b8be2..6f558e69bb15f 100644 --- a/.github/actions/javascript/failureNotifier/failureNotifier.ts +++ b/.github/actions/javascript/failureNotifier/failureNotifier.ts @@ -17,7 +17,7 @@ type PullRequest = RestEndpointMethodTypes['repos']['listPullRequestsAssociatedW * targeting the correct base branch to avoid blaming the wrong PR. */ function getMergedPR(associatedPRs: PullRequest[], targetBranch = 'main'): PullRequest | undefined { - return associatedPRs.find((pr) => pr.merged_at !== null && pr.base.ref === targetBranch) ?? associatedPRs.at(0); + return associatedPRs.find((pr) => pr.merged_at !== null && pr.base.ref === targetBranch); } async function run() { diff --git a/.github/actions/javascript/failureNotifier/index.js b/.github/actions/javascript/failureNotifier/index.js index 194ac6d414452..e3db6e6d7b8a4 100644 --- a/.github/actions/javascript/failureNotifier/index.js +++ b/.github/actions/javascript/failureNotifier/index.js @@ -9559,7 +9559,7 @@ const github = __importStar(__nccwpck_require__(5438)); * targeting the correct base branch to avoid blaming the wrong PR. */ function getMergedPR(associatedPRs, targetBranch = 'main') { - return associatedPRs.find((pr) => pr.merged_at !== null && pr.base.ref === targetBranch) ?? associatedPRs.at(0); + return associatedPRs.find((pr) => pr.merged_at !== null && pr.base.ref === targetBranch); } async function run() { const token = core.getInput('GITHUB_TOKEN', { required: true }); diff --git a/.github/workflows/failureNotifier.yml b/.github/workflows/failureNotifier.yml index 84ba8594b96d8..a9dafe86873a2 100644 --- a/.github/workflows/failureNotifier.yml +++ b/.github/workflows/failureNotifier.yml @@ -3,6 +3,7 @@ name: Notify on Workflow Failure on: workflow_run: workflows: ["Process new code merged to main", "Remote Build iOS", "Remote Build Android"] + branches: [main] types: - completed diff --git a/tests/unit/FailureNotifierTest.ts b/tests/unit/FailureNotifierTest.ts index 46a1ca7f654ce..e1961a073f00f 100644 --- a/tests/unit/FailureNotifierTest.ts +++ b/tests/unit/FailureNotifierTest.ts @@ -65,13 +65,12 @@ describe('getMergedPR', () => { expect(result?.number).toBe(82016); }); - it('should fall back to first PR if no merged PR is found', () => { + it('should return undefined when no merged PR is found instead of blaming an unmerged PR', () => { const associatedPRs = [openPRWithMainMerged, openPRDifferentBase]; const result = getMergedPR(associatedPRs); - // Falls back to first element when no merged PR matches - expect(result?.number).toBe(80254); + expect(result).toBeUndefined(); }); it('should return undefined for empty array', () => {