Skip to main content
A webhook tells you about each test the moment its status changes. A weekly digest shows the week as a whole: which tests got worse, which recovered, and which team owns each one. That’s what a triage meeting needs. Trunk’s API has everything the digest needs, so a short script on a schedule can build it.

1. Find the tests whose status changed

Every test has a status (healthy, flaky or broken) and a statusSince, the time that status began. A test changed this week if its statusSince is within the last seven days. Don’t look for those tests by listing every test. An organization can have hundreds of thousands of healthy tests. Make two short lists instead, paging through each with nextCursor:
  • Turned flaky or broken. Call GET /v2/tests with status=flaky,broken, include=metrics and period=7d. The metrics give each test’s failure rate for the week.
  • Turned healthy. A test recovers when a monitor stops flagging it, and the monitor records that as an event. Call GET /v2/detection-events with isClassificationEvent=true, monitorStatus=inactive and detectedAfter set to the start of the week. For each test in those events that isn’t in the first list, call GET /v2/tests/{testId} with include=metrics&period=7d.
From both lists, keep the tests whose statusSince is within the week. Add testCollectionId to the list calls to send a digest for one collection.
Use statusSince rather than newlyFlaky=true. newlyFlaky returns only tests that became flaky for the first time. It leaves out a test that was fixed and then turned flaky again, and a test that turned broken. Detection events don’t include a test someone flagged as flaky by hand. So if someone clears that flag and the test turns healthy, the test isn’t in the digest.

2. Compare with the start of the week

A test can change status more than once in a week. For example, it can turn flaky on Monday and recover on Thursday. For each test from step 1, call GET /v2/tests/{testId}/status-history with startedAfter set to the start of the week. Transitions are listed newest first, so the last one’s fromStatus was the test’s status when the week began.
  • If that status is the same as the test’s current status, the test changed and then changed back. Leave it out.
  • Otherwise, report the test as fromStatus → status, such as healthy → flaky or broken → healthy.
Each transition’s activeMonitors lists the monitors that flagged the test, if you want to show why it changed.

3. Group by owner and post to Slack

Each test has codeowners, such as @acme/payments. Group the tests by owner. A test with more than one owner goes under each of them, and a test with none goes under Unowned. Then post the groups to a Slack incoming webhook. Each test’s url links to its page in Trunk. This script does all three steps. It needs Node.js 18 or later and an API key. Reading tests needs no permissions, so leave them all off.
flaky-digest.mjs
The script makes up to 10 requests at a time and lists up to 8 tests for each owner, worst first, and up to 49 owners, which stays within Slack’s limits for one message. To send each team its own digest, keep only that team’s group from byOwner and post it to the team’s webhook URL.

4. Run it every week

Run the script from any scheduler, such as cron or a scheduled CI job. This GitHub Actions workflow posts every Monday at 14:00 UTC. Store the API key and the Slack webhook URL as repository secrets:
.github/workflows/flaky-digest.yml
The number of requests depends on how many tests are unhealthy or changed status this week, not on how many tests you have. On an organization with over 275,000 tests and about 2,300 unhealthy ones, the digest made about 1,300 requests and took under 90 seconds. Requests share your organization’s rate limit, so run the digest outside working hours.