Skip to main content

Check out Port for yourselfย 

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.

Prerequisites

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:

  1. Log in to GitHub as a user with enough permissions to edit topics for a repository.
  2. Navigate to the repository you want to add a topic to.
  3. Click on the settings icon
  1. Click on the Topics field to add a topic.

  2. 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 by kafka in your LaunchdarklyProject blueprint in Port.

Control the topic name

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.

  1. Head back to the Builder, choose the Service (GitHub repository) blueprint, and click on New relation:


  1. 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"))
JQ explanation

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: