Locally testing snap-ins
To test out changes in snap-in locally, you can create a snap-in version in test mode. A snap-in version created in test mode enables you to specify a public HTTP URL to receive events from DevRev. This makes for quick code changes on the local machine without needing to repeatedly deploy the snap-in again for testing the changes.
To set up the framework, follow these steps.
Set up the server
- Run a server locally to ingest events from DevRev. The
port
parameter is optional. If not set, the server starts default on8000
.
- Expose the local port as a publicly available URL. We recommend using
ngrok
since it is free and easy to set up. The command for running ngrok tunneling on port8000
:
This returns a public HTTP URL.
- Create a snap-in version with the
testing-url
flag set.
HTTP_URL
is the publicly available URL from the previous step. The URL should start with http
or https
. Do note that
the developer cannot use the path
and testing-url
flags together.
- Once the snap-in version is ready, create a snap-in, update, and activate it.
Receive events locally
After the snap-in has been activated, it can receive events locally from DevRev as a
snap-in would. For example, if the snap-in is listening for the work_created
event type, then creating a
new work item would send the event to the local server.
If utilizing ngrok, you can access the ngrok UI by opening http://127.0.0.1:4040/ in the browser. This interface offers a neat way to review the list of requests and replay them if necessary.
The service account token included with the request is valid for only 30 minutes. Therefore, attempting to call the DevRev API with that token for events older than this timeframe results in a 401 Unauthorized error.
Update the URL
The code can be changed without the need to create a snap-in version or redeploy the snap-in. On any change to the
src
folder, the server restarts with the updated changes. However, on patch compatible updates to the manifest or the testing URL, you can upgrade
the snap-in version.
In case of non-patch compatible updates, the force
flag can be used to upgrade the version. However, forcing the update deletes any
existing snap-ins that have been created from this version.
The manifest must always be provided when upgrading a snap-in version.