In this example, you will create blueprint for codecov_coverage
that ingests all repositories and their associated coverage report from your CodeCov account. You will add some python script to make API calls to CodeCov REST API and fetch data for your account. In addition to ingesting data via REST API, you will configure webhooks to automatically update your entities in Port anytime an event occurs in your CodeCov account.
Log in to your Port account and create the following blueprints:
Create the coverage blueprint in Port using this json file
The list of variables required to run this script are:
PORT_CLIENT_ID
- Your Port client idPORT_CLIENT_SECRET
- Your Port client secretCODECOV_TOKEN
- CodeCov API access tokenCODECOV_SERVICE_PROVIDER
- Git hosting service provider. Acceptable values aregithub
,github_enterprise
,bitbucket
,bitbucket_server
,gitlab
andgitlab_enterprise
CODECOV_SERVICE_PROVIDER_ACCOUNT_NAME
- Username from the Git service provider
NOTE: Find your Port credentials using this guide
To ingest data from your CodeCov account to Port, run the following commands:
export PORT_CLIENT_ID=<ENTER CLIENT ID>
export PORT_CLIENT_SECRET=<ENTER CLIENT SECRET>
export CODECOV_TOKEN=<ENTER CODECOV TOKEN>
export CODECOV_SERVICE_PROVIDER=<ENTER CODECOV SERVICE PROVIDER>
export CODECOV_SERVICE_PROVIDER_ACCOUNT_NAME=<ENTER CODECOV SERVICE PROVIDER ACCOUNT NAME>
git clone https://github.com/port-labs/example-codecov-test-coverage.git
cd example-codecov-test-coverage
pip install -r ./requirements.txt
python app.py
Webhooks are a great way to receive updates from third party platforms, and in this case, CodeCov. To create a codecov webhook notification, you will first need to generate a webhook URL from Port.
Follow the following steps to create a webhook:
- Navigate to the Builder section in Port and click Data source;
- Under Webhook tab, click Custom integration;
- In the basic details tab, you will be asked to provide information about your webhook such as the
title
,identifier
description
, andicon
; - In the integration configuration tab, copy and paste the webhook configuration file into the Map the data from the external system into Port form;
- Take note of the webhook
URL
provided by Port on this page. You will need thisURL
when subscribing to events in CodeCov; - Test the webhook configuration mapping and click on Save;
- From your CodeCov account, open Settings and then click on the Global YAML tab at the left sidebar menu;
- In the YAML editor, add the following codecov configuration to notify Port anytime an event occurs in your repositories:
Remember to replace
YOUR_PORT_WEBOOK
with the value of theURL
you received after creating the webhook configuration in Port.
coverage:
notify:
webhook:
default:
only_pulls: false
url: YOUR_PORT_WEBHOOK
- Click Save changes to save the webhook configuration;
For more information on customizing the notification service, follow this documentation
All set! When any changes occur in your CodeCov account, a webhook event will be triggered to the URL provided by Port. Port will then parse the events based on the mapping and subsequently update the catalog entities.