Skip to main content

One post tagged with "launchdarkly"

View All Tags

GitHub → LaunchDarkly: Show feature flags for this repo

See feature flags tagged to this repo
🔒
https://github.com/mycompany/webshop
preload

How does this help you?​

  • See your LaunchDarkly feature flags directly from your GitHub repositories
  • Jump directly to each feature flag in the LaunchDarkly dashboard
  • Quickly identify which flags are associated with specific repositories
tip

You can easily modify this integration to return other tagged resources or use different tag formats

Preview​

How it looks in the extension

ToolJump•
launchdarklyFeature Flags (3 flags)
• ... Other items ...

High level approach​

We query LaunchDarkly's API for feature flags tagged with the repository name (tag key repository, value matching the GitHub repo name, e.g. my-repo). We extract the last part of the repository path (after the final /) and use that as the tag value. We then render a dropdown of the first 10 flags. If there are more, a final "More…" item links to the LaunchDarkly flags page filtered by the repository tag.

Notes:

  • Only the first 10 flags are shown to keep the dropdown manageable
  • Each item links to the specific feature flag page in LaunchDarkly
  • The "More…" link goes to the LaunchDarkly flags list with the tag filter applied

Prerequisites​

For the code below to work, you need a LaunchDarkly access token with read permissions for feature flags. Provide LAUNCHDARKLY_ACCESS_TOKEN as a secret.

The LaunchDarkly access token must have the following permissions:

  • read:flag - to read feature flags
  • read:project - to access project information

Code​

github.launchdarkly.integration.example.js
module.exports = {
metadata: {
name: 'github-launchdarkly',
description: 'Show LaunchDarkly feature flags tagged with this repository as a dropdown',
match: {
contextType: 'github',
context: {
'page.repository': { startsWith: 'my-org/' }
}
},
requiredSecrets: ['LAUNCHDARKLY_ACCESS_TOKEN'],
cache: 1800
},
run: async function (context, secrets = {}) {
// Extract repository name (last part after /)
const repository = context.page.repository; // e.g., "company/webshop"
const repoName = repository.split('/').pop(); // e.g., "webshop"

const projectKey = 'your-project-key'; // Replace with your LaunchDarkly project key
const tagKey = 'repository';
const tagValue = repoName;

const apiUrl = `https://app.launchdarkly.com/api/v2/flags/${projectKey}?filter=tags:${tagKey}:${tagValue}`;

const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${secrets.LAUNCHDARKLY_ACCESS_TOKEN}`,
'Content-Type': 'application/json'
}
});

if (!response.ok) {
throw new Error(`LaunchDarkly API request failed: ${response.status} ${response.statusText}`);
}

const data = await response.json();
const flags = data.items || [];

if (flags.length === 0) {
return [];
}

// First 10 items
const items = flags.slice(0, 10).map(flag => ({
content: flag.key,
href: `https://app.launchdarkly.com/${projectKey}/flags/${flag.key}`,
icon: 'launchdarkly'
}));

// If more than 10, add a More… item linking to LaunchDarkly flags list filtered by tag
if (flags.length > 10) {
const moreUrl = `https://app.launchdarkly.com/${projectKey}/flags?filter=tags:${tagKey}:${tagValue}`;
items.push({
content: 'More…',
href: moreUrl,
status: 'relevant',
icon: 'launchdarkly'
});
}

return [{
type: 'dropdown',
content: `Feature Flags (${flags.length} flags)`,
icon: 'launchdarkly',
items
}];
}
};