Skip to content

Conversation

@neil-marcellini
Copy link
Contributor

@neil-marcellini neil-marcellini commented Feb 11, 2026

Explanation of Change

Problem: The failureNotifier.yml workflow creates GitHub issues when CI fails on main, but it sometimes links to the wrong PR. This happens because the GitHub API listPullRequestsAssociatedWithCommit returns ALL PRs containing a commit — including open PRs that have merged main into their feature branch. The old code took data[0] (the first result), which could be an unrelated open PR.

Example: Issue #82067 was incorrectly attributed to an open, unmerged PR.

Fix: Added a getMergedPR() utility that filters the API results to find the PR that was actually merged (merged_at !== null) into the target branch (base.ref === targetBranch), falling back to the first result only if no merged PR is found.

Refactor: Converted the workflow from inline github-script JavaScript steps to a proper custom GitHub Action (failureNotifier.ts), following the same pattern as all other JS actions in .github/actions/javascript/. This makes the logic testable and lintable. The core filtering logic lives in a separate utility file (.github/libs/failureNotifierUtils.ts) with unit tests.

Fixed Issues

$ #82067

Tests

  1. Run npx jest tests/unit/FailureNotifierUtilsTest.ts — all 5 tests pass:
    • Picks merged PR when an open PR appears first in API results (the bug scenario)
    • Picks merged PR when it appears first (normal case)
    • Filters by target branch (ignores PRs merged to other branches)
    • Falls back to first PR if no merged PR matches
    • Returns undefined for empty array
  2. No UI changes — this is a CI workflow fix
  • Verify that no errors appear in the JS console

Offline tests

N/A — CI workflow change only

QA Steps

[No QA] — this is an internal CI workflow fix with no user-facing impact.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

N/A — CI workflow fix, no UI changes

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

The failureNotifier workflow uses listPullRequestsAssociatedWithCommit
to find which PR caused a failure on main. However, this API returns
ALL PRs containing the commit, including open PRs that have merged
main into their feature branch. Taking data[0] could pick an unmerged
PR, creating misleading workflow failure issues.

Fix: Filter for PRs that are actually merged into the target branch
before falling back to the first result.

Co-authored-by: Cursor <cursoragent@cursor.com>
@neil-marcellini neil-marcellini requested a review from a team as a code owner February 11, 2026 02:18
@melvin-bot melvin-bot bot requested a review from brunovjk February 11, 2026 02:18
@melvin-bot
Copy link

melvin-bot bot commented Feb 11, 2026

@brunovjk Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team February 11, 2026 02:18
- Rename html_url/merged_at to htmlUrl/mergedAt in TS type and tests
- Use .at(0) instead of [0] per prefer-at rule
- Replace real usernames with generic test-user in test data

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 169cbeccc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

neil-marcellini and others added 3 commits February 10, 2026 18:27
Convert utility from TS to JS (CommonJS) so the workflow can
require() it directly. Update test to import the JS module and
use GitHub API field names (merged_at, base.ref) to match what
the workflow passes through from the API response.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Fix eslint-disable rule: no-relative-import -> no-relative-parent-imports
- Add no-unsafe-assignment to eslint-disable for require()
- Use context.payload.workflow_run.head_branch instead of YAML
  interpolation to avoid script injection from branch names
  containing quotes (addresses Codex review)

Co-authored-by: Cursor <cursoragent@cursor.com>
@neil-marcellini
Copy link
Contributor Author

(Neil's AI agent) Good catch on the YAML interpolation injection risk. Fixed in 99bbffc — now using context.payload.workflow_run.head_branch instead of \"${{ github.event.workflow_run.head_branch }}\".

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 14 files with indirect coverage changes

neil-marcellini and others added 2 commits February 10, 2026 18:40
The typecheck CI rejects new .js files in .github/libs/. Convert
the utility to .ts for clean test imports, and inline the same
logic in the workflow (which can only run raw JS). The TS module
serves as the tested reference implementation, with a comment in
the workflow pointing to it.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add eslint-disable for naming-convention on the PullRequest type
(matching GitHub API field names). Run Prettier on test file.

Co-authored-by: Cursor <cursoragent@cursor.com>
neil-marcellini and others added 6 commits February 10, 2026 19:06
Extract the inline github-script logic into a proper custom action
at .github/actions/javascript/failureNotifier/ that:
- Imports and uses getMergedPR from .github/libs/failureNotifierUtils.ts
- Is compiled via ncc into index.js (same pattern as all other actions)
- The workflow now uses the custom action instead of inline scripts
- The tested utility is the SAME code the action actually executes

This ensures the unit tests in FailureNotifierUtilsTest.ts are
testing the real logic used in production.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add WorkflowRun type to fix unsafe-any TypeScript errors from
  github.context.payload.workflow_run
- Rename annotations/annotation to checkResults/checkResult to avoid
  triggering the no-negated-variables rule (matches "not" substring)
- Rebuild index.js

Co-authored-by: Cursor <cursoragent@cursor.com>
The optional chain on head_commit?.id produces string | undefined,
but commit_sha requires string. Default to empty string.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Handle missing head_commit by early-returning instead of defaulting
  to empty string (fixes no-default-id-values ESLint rule)
- Use immutable SHA for actions/checkout (fixes validateImmutableActionRefs)
- Rebuild compiled index.js bundle

Co-authored-by: Cursor <cursoragent@cursor.com>
The local ncc build produced slightly different output for template
literals. Rebuilding via the official script ensures the bundle
matches what the verify CI job expects.

Co-authored-by: Cursor <cursoragent@cursor.com>
@neil-marcellini
Copy link
Contributor Author

No C+ needed. Requesting a review from @roryabraham because I think he has experience with GH actions and I don't have a ton of experience with them myself.

@neil-marcellini neil-marcellini marked this pull request as ready for review February 11, 2026 21:59
@neil-marcellini neil-marcellini removed the request for review from brunovjk February 12, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant