GitHub Issues Integration
Last updated
Last updated
Trunk allows you to automate GitHub Issue creation through webhooks. This will allow you to create GitHub issues and auto-assign them to CODEOWNERS using Webhooks.
This guide will walk you through integrating Trunk Flaky Tests with GitHub Issues through webhooks. You will be able to automatically generate GitHub issues for new flaky or broken tests. This guide should take 15 minutes to complete.
Before you can create a webhook to automate GitHub Issue creation, you need to create an API token to authorize your requests.
Navigate to GitHub Developer Settings under Settings > Developer settings
Under Personal access token > Fine-grained tokens > Click Generate new token
Name the token something like Trunk Flaky Tests
so you can recognize your token and set it never to expire.
Select the repositories you need to create issues to under Repository access
Under Permissions > Repository Permissions, select Read and Write access for Issues.
Click Generate Token and copy your API token.
Trunk uses Svix to integrate with other services, such as GitHub 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 Add Endpoint
Paste your GitHub repo's Issues endpoint into Endpoint URL. Your Endpoint URL should be formatted as: https://api.github.com/repos/{OWNER}/{REPO}/issues
. You can verify the URL by visiting it in your browser, such as https://api.github.com/repos/trunk-io/docs/issues.
Under Subscribe to events, select test_case.status_changed
Create the new endpoint. You will be redirected to the endpoint configuration view.
If you're having trouble adding a new webhook endpoint with Svix, please see the Adding Endpoint docs from Svix.
The GitHub Issues API requires some custom headers. You can configure custom headers in Trunk:
You can add custom headers under Advanced > Custom Headers
Fill in the Key and Value referencing the table below, and click the + button to add each header.
You'll need to configure the following headers.
Accept
application/vnd.github+json
Authorization
Bearer <YOUR_API_TOKEN>
X-GitHub-Api-Version
2022-11-28
Next, you need to create a custom transformation to turn the Trunk Flaky Tests event into a GitHub Issue.
In the endpoint configuration view, navigate to the Advanced tab. Under Transformation, toggle the Enabled switch.
Click Edit transformation to create a custom transformation script.
Copy and paste the transformation script below and click Save. You can modify this script to customize how your issues look and what they contain.
You can test the transformation by selecting the test_case.status_changed
payload and clicking Run Test. This will test the transformation but not send a message. You will learn to send a test message in step 5.
An example transformation script is provided below and you can customize your GitHub Issues integration by following the GitHub and Svix transformations documentation.
If you have CODEOWNERS configured for your GitHub repo, you can create issues with assignees using CODEOWNERS. Uncomment the code on lines 14-18 to enable automatic assignment. Limitations of Automatic Assignment
CODEOWNERS supports assigning files to teams, but GitHub doesn't support assigning issues to teams. If you have team owners in your CODEOWNERS file, the requests will fail.
The example payload has the CODEOWNERS assigned to @backend
. If you're testing following the instructions in step 5, the delivery attempt can fail.
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_changed
as the event type to send.
Click Send Example to test your webhook
A GitHub Issue will now be created when a test's health status changes. You can further modify your transformation script to customize your issues.
See the Trunk webhook event catalog
Want to chat with Trunk's engineers? Join us and 1500+ fellow engineers on Slack.
You can monitor the events and the webhook's delivery logs in the Overview tab of an endpoint configuration view.
You can see an overview of how many webhook deliveries have been attempted, how many are successful, how many are in-flight, and how many fail in the Attempt Delivery Stats modal.
You can see a list of past delivery attempts in the Message Attempts modal. You can filter this list by Succeeded and Failed status, and you can click on each message to see the Message content, response code, and error message of each attempt. You can learn more about replaying messages and filtering logs in the Svix docs.