Connect GitHub repository (service) to a Launchdarkly project
This guide aims to demonstrate how to connect a GitHub repository (referred to as Service for the rest of the guide) to a Launchdarkly project in Port.
- This guide assumes you have a Port account and that you have finished the onboarding process. We will use the
Service
blueprint that was created during the onboarding process. - Ensure you have Launchdarkly installed and configured in your environment.
- Ensure you have GitHub installed and configured
Add topics to services in GitHubโ
Tagging repositories with topics allows you to categorize, filter and add metadata information to them. You can use topics to group repositories related to a Launchdarkly project. In this guide, we will add a topic to tell us what Launchdarkly project the repo is related to:
- Log in to GitHub as a user with enough permissions to edit topics for a repository.
- Navigate to the repository you want to add a topic to.
- Click on the settings icon
-
Click on the
Topics
field to add a topic. -
Add a topic that represents the Launchdarkly project the service is related to,
port-launchdarkly-kafka
. For this guide, let's assume there is a service entity identified bykafka
in yourLaunchdarklyProject
blueprint in Port.
Since our GitHub repository may already have several labels, we will need a mechanism to control how these topics will be related to our LaunchdarklyProject
blueprint. A way to achieve this relation is to prefix the topic name with the keyword port-launchdarkly-
. We will then use JQ to select the topics that starts with this keyword. So, our example topic will be named port-launchdarkly-kafka
, which will correspond to a Launchdarkly Project entity identified by kafka
in Port.
Create the Project relationโ
Now that Port is synced with our GitHub resources, let's reflect the topic in our services to display the Launchdarkly project associated with a service. First, we will need to create a relation between our services and the corresponding Launchdarkly Project.
- Head back to the Builder, choose the
Service
(GitHub repository) blueprint, and click onNew relation
:
- Fill out the form like this, then click
Create
:
Now that the blueprints are related, we need to assign the relevant Services to each of our Launchdarkly Projects. This can be done by adding some mapping logic. Go to your data sources page, and click on your GitHub integration:
Under the resources
key, modify the mapping for the service
kind by using the following YAML block. Then click Save & Resync
:
Relation mapping (Click to expand)
resources:
- kind: repository
selector:
query: 'true'
port:
entity:
mappings:
identifier: .name
title: .name
blueprint: '"service"'
properties:
readme: file://README.md
url: .html_url
language: .language
relations:
launchDarklyProject: .topics | map(select(startswith("port-launchdarkly-"))) | map(sub("port-launchdarkly-"; ""; "g"))
The JQ below selects all topics that start with the keyword port-launchdarkly-
. It then removes "port-launchdarkly-" from each topic, leaving only the part that comes after it. It then selects the first match, which is equivalent to the Launchdarkly Project in Port.
launchDarklyProject: .topics | map(select(startswith("port-launchdarkly-"))) | map(sub("port-launchdarkly-"; ""; "g"))
What we just did was map the Launchdarkly Project
to the relation between it and our Services
.
Now, if our Launchdarkly Project
identifier is equal to the GitHub service label, the service
will automatically be linked to it ย ๐
Conclusionโ
By following these steps, you can seamlessly connect a GitHub repository with an existing Launchdarkly Project blueprint in Port using topics.
More relevant guides and examples: