Trunk allows you to automate Linear Issue creation through webhooks. This will allow you to create Linear issues and auto-assign according to CODEOWNERS. This guide will walk you through integrating Trunk Flaky Tests with Linear Issues through webhooks. You will be able to automatically generate Linear issues for new flaky tests found in your repo that impact more than 2 PRs. This guide should take 15 minutes to complete. Trunk also has a built-in Linear integration for ticket creation. You only need to use webhooks if you want to automate ticket creation or need additional customization.Documentation Index
Fetch the complete documentation index at: https://trunk-4cab4936-mintlify-sync-from-docs-1778014214.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
1. Create a Linear Personal Access Token
Before you can create a webhook to automate GitHub Issue creation, you need to create an API token to authorize your requests.- In the Linear app, navigate to settings by holding
Gand pressingS, or by clicking on your profile on the top left and clicking Settings. - Under Account > Security & Access > Personal API Keys, Click New API Key to create a new access token.
- Copy the new API key and save it in a secure location. You’ll need to use this later.
2. Add a new webhook in Trunk
Trunk uses Svix to integrate with other services, such as creating Linear Issues through webhooks. You can create a new endpoint by:- Login to Trunk Flaky Tests
- From your profile on the top right, navigate to Settings
- Under Organization > Webhooks, click Automate Linear Issues Creation.
-
Paste the Linear GraphQL API endpoint into Endpoint URL, which is:
https://api.linear.app/graphql. - Review the transformation code automatically generated for Linear issues, you can customize this transformation at any time. Learn more about customizing transformations.
- Create the new endpoint. You will be redirected to the endpoint configuration view.
3. Add custom headers
The Linear GraphQL API requires some custom headers. You can configure custom headers in the endpoint configuration:- You can add custom headers under Webhooks > Advanced > Custom Headers.
- Fill in the Key and Value referencing the table below, and click the + button to add each header.
| Key | Value |
|---|---|
Authorization | <YOUR_API_TOKEN> |
4. Find your Linear Team, Project, and Label IDs
You need to find your Linear team, project, and label IDs to create issues with the appropriate labeling. You can do this by querying your Linear project using cURL.Team ID
First, you’ll need to find your team ID so you can create Linear issues under the correct team. You can make a request in your terminal using cURL, or a similar tool. You’ll need your Linear API key from step 1.Project ID
If you want to create issues under a specific project, you’ll need to find its project ID. You can use a query like this:Label ID
If you want to create issues with a specific label, you’ll need to find its label ID. You can use a query like this:5. Customize your transformation
Transformations are custom code snippets you can write to customize the Linear issues created by the webhook. A working template transformation will be added automatically for your webhook, but you can further customize the behavior of this webhook.- In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
- Click Edit transformation to update your transformation code, and click Save to update the transformation.
- You can test the transformation by selecting the
test_case.status_changedpayload and clicking Run Test. This will test the transformation but not send a message. You will learn to send a test message in step 6.
| Constant | Description |
|---|---|
LINEAR_TEAM_ID | (Required) Your Linear team ID. Learn about finding your team ID. |
LINEAR_PROJECT_ID | (Optional) The Linear project ID assigned to new issues. Learn more about finding your project ID. |
LINEAR_LABEL_IDS | (Optional) Array of label IDs assigned to new issues. Learn about finding your label IDs. |
PRS_IMPACTED_THRESHOLD | Issues will be created only for flaky tests that have impacted more PRs than the PRS_IMPACTED_THRESHOLD.You can adjust this value if you see many issues about low-impact flaky tests. |
The default transformation only creates issues when
newStatus === "flaky". If you also want to create issues for tests marked as Broken (consistently failing at a high rate), update the filter condition. For example, change newStatus !== "flaky" to newStatus !== "flaky" && newStatus !== "broken" to handle both statuses.(Optional) Automatic issue assignment
If you have CODEOWNERS configured in your repo, it will be reported by Trunk in the webhook payload. You can use this to map different CODEOWNERS to Linear assignees. You can access CODEOWNERS in the payload like this:webhook.payload.test_case.codeowners.
Since the way your owners map to your Linear user is unique to your team, you’ll need to provide your own mapping to convert code owners to their Linear ID.
You can modify your issue create payload like this to include an assignee:
6. Test your webhook
You can create test issues by delivering a mock webhook. You can do this by:- In the endpoint configuration view, navigate to the Testing tab and select a Send event
- Under Subscribed events, select
test_case.status_changedas the event type to send - Click Send Example to test your webhook