https://github.com/launchdarkly/find-code-references-in-pull-request
Find Code Reference Flags in Pull Requests
https://github.com/launchdarkly/find-code-references-in-pull-request
actions github-action github-actions launchdarkly launchdarkly-integration managed-by-terraform
Last synced: 4 months ago
JSON representation
Find Code Reference Flags in Pull Requests
- Host: GitHub
- URL: https://github.com/launchdarkly/find-code-references-in-pull-request
- Owner: launchdarkly
- License: apache-2.0
- Created: 2021-04-12T12:20:51.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-12-15T10:05:39.000Z (6 months ago)
- Last Synced: 2026-01-13T19:59:26.422Z (5 months ago)
- Topics: actions, github-action, github-actions, launchdarkly, launchdarkly-integration, managed-by-terraform
- Language: Go
- Homepage: https://docs.launchdarkly.com/home/code/code-references
- Size: 11.1 MB
- Stars: 13
- Watchers: 28
- Forks: 6
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# LaunchDarkly Find Code References in Pull Request GitHub action
Adds a comment to a pull request (PR) whenever a feature flag reference is found in a PR diff and creates a [flag link](https://docs.launchdarkly.com/home/organize/links) in LaunchDarkly.


## Permissions
This action requires a [LaunchDarkly access token](https://docs.launchdarkly.com/home/account-security/api-access-tokens) with:
* Read access for the designated `project-key`
* (Optional) the `createFlagLink` action, when [`create-flag-links` input is `true` (default behavior)](#inputs)
Access tokens should be stored as an [encrypted secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
To add a comment to a PR, the `repo-token` used requires `write` permission for PRs. You can also specify permissions for the workflow with:
```yaml
permissions:
pull-requests: write
```
## Usage
Basic:
```yaml
on: pull_request
jobs:
find-flags:
runs-on: ubuntu-latest
name: Find LaunchDarkly feature flags in diff
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find flags
uses: launchdarkly/find-code-references-in-pull-request@v2
id: find-flags
with:
project-key: default
environment-key: production
access-token: ${{ secrets.LD_ACCESS_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
```
Use outputs in workflow:
```yaml
on: pull_request
jobs:
find-feature-flags:
runs-on: ubuntu-latest
name: Find LaunchDarkly feature flags in diff
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find flags
uses: launchdarkly/find-code-references-in-pull-request@v2
id: find-flags
with:
project-key: default
environment-key: production
access-token: ${{ secrets.LD_ACCESS_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Add or remove labels on PRs if any flags have changed.
# Note: This example requires the "ld-flags" label to have been created in the repository first:
# https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels#creating-a-label
- name: Add label
if: steps.find-flags.outputs.any-changed == 'true'
run: gh pr edit $PR_NUMBER --add-label ld-flags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Remove label
if: steps.find-flags.outputs.any-changed == 'false'
run: gh pr edit $PR_NUMBER --remove-label ld-flags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
```
### Flag aliases
This action has full support for code reference aliases. If the project has an existing [`.launchdarkly/coderefs.yaml`](https://github.com/launchdarkly/ld-find-code-refs/blob/main/docs/CONFIGURATION.md#yaml) file, it will use the aliases defined there.
You can find more information on aliases at [launchdarkly/ld-find-code-refs](https://github.com/launchdarkly/ld-find-code-refs/blob/main/docs/ALIASES.md).
### Monorepos
This action does not support monorepos or searching for flags across LaunchDarkly projects.
### Inputs
| name | description | required | default |
| --- | --- | --- | --- |
| `repo-token` |
Token to use to authorize comments on PR. Typically the GITHUB_TOKEN secret or equivalent github.token.
| `true` | `""` |
| `access-token` | LaunchDarkly access token
| `true` | `""` |
| `project-key` | LaunchDarkly project key
| `false` | `default` |
| `environment-key` | LaunchDarkly environment key for creating flag links
| `false` | `production` |
| `placeholder-comment` | Comment on PR when no flags are found. If flags are found in later commits, this comment will be updated.
| `false` | `false` |
| `include-archived-flags` | Scan for archived flags
| `false` | `true` |
| `max-flags` | Maximum number of flags to find per PR
| `false` | `5` |
| `base-uri` | The base URI for the LaunchDarkly server. Most members should use the default value.
| `false` | `https://app.launchdarkly.com` |
| `check-extinctions` | Check if removed flags still exist in codebase
| `false` | `true` |
| `create-flag-links` | Create links to flags in LaunchDarkly. To use this feature you must use an access token with the createFlagLink role. To learn more, read Flag links.
| `false` | `true` |
### Outputs
| name | description |
| --- | --- |
| `any-modified` |
Returns true if any flags have been added or modified in PR
|
| `modified-flags` | Space-separated list of flags added or modified in PR
|
| `modified-flags-count` | Number of flags added or modified in PR
|
| `any-removed` | Returns true if any flags have been removed in PR
|
| `removed-flags` | Space-separated list of flags removed in PR
|
| `removed-flags-count` | Number of flags removed in PR
|
| `any-changed` | Returns true if any flags have been changed in PR
|
| `changed-flags` | Space-separated list of flags changed in PR
|
| `changed-flags-count` | Number of flags changed in PR
|
| `any-extinct` | Returns true if any flags have been removed in PR and no longer exist in codebase. Only returned if check-extinctions is true.
|
| `extinct-flags` | Space-separated list of flags removed in PR and no longer exist in codebase. Only returned if check-extinctions is true.
|
| `extinct-flags-count` | Number of flags removed in PR and no longer exist in codebase. Only returned if check-extinctions is true.
|