Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/javascript/failureNotifier/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/failureNotifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/unit/FailureNotifierTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading