> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# launchdarkly/ld-find-code-refs

Job for finding and sending feature flag code references to LaunchDarkly. Code references documentation: https://docs.launchdarkly.com/home/code/circleci

## Jobs

### find-code-references

Scans a git repository for code references.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `access_token` | string | ${LD_ACCESS_TOKEN} | LaunchDarkly access token (use env var $LD_ACCESS_TOKEN to populate). |
| `proj_key` | string |  | LaunchDarkly project key. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with `projects` block in configuration file. |
| `base_uri` | string | https://app.launchdarkly.com | Set the base URL of the LaunchDarkly server for this configuration. Only necessary if using a private instance of LaunchDarkly. |
| `context_lines` | integer | 2 | The number of context lines above and below a code reference for the job to send to LaunchDarkly. By default, the flag finder will not send any context lines to LaunchDarkly. If < 0, no source code will be sent to LaunchDarkly. If 0, only the lines containing flag references will be sent. If > 0, will send that number of context lines above and below the flag reference. A maximum of 5 context lines may be provided. |
| `repo_type` | enum | custom | The repo service provider. Used to correctly categorize repositories in the LaunchDarkly UI. |
| `repo_url` | string |  | The URL for the repository. If provided and `repoType` is not custom, LaunchDarkly will attempt to automatically generate source code links. Example: `https://github.com/launchdarkly/ld-find-code-refs` |
| `default_branch` | string | main | The git default branch. The LaunchDarkly UI will default to display code references for this branch. |
| `commit_url_template` | string |  | If provided, LaunchDarkly will attempt to generate links to your Git service provider per commit. Example: `https://github.com/launchdarkly/ld-find-code-refs/commit/${sha}`. Allowed template variables: `branchName`, `sha`. If `commitUrlTemplate` is not provided, but `repoUrl` is provided and `repoType` is not `custom`, LaunchDarkly will attempt to automatically generate source code links for the given `repoType`. |
| `hunk_url_template` | string |  | If provided, LaunchDarkly will attempt to generate links to your Git service provider per code reference. Example: `https://github.com/launchdarkly/ld-find-code-refs/blob/${sha}/${filePath}#L${lineNumber}`. Allowed template variables: `sha`, `filePath`, `lineNumber`. If `hunkUrlTemplate` is not provided, but `repoUrl` is provided and `repoType` is not `custom``, LaunchDarkly will attempt to automatically generate source code links for the given `repoType`. |
| `allow_tags` | boolean | false | Enables storing references for tags. The tag will be listed as a branch. |
| `debug` | boolean | false | Enables verbose debug logging. |
| `ignore_service_errors` | boolean | false | If enabled, the scanner will terminate with exit code 0 when the LaunchDarkly API is unreachable or returns an unexpected response. |
| `lookback` | integer | 10 | Sets the number of git commits to search in history for whether a feature flag was removed from code. May be set to 0 to disable this feature. Setting this option to a high value will increase search time. |

## Examples

### minimal_config

Minimal configuration

```yaml
version: 2.1
orbs:
  launchdarkly: launchdarkly/ld-find-code-refs@2.14.0
workflows:
  main:
    jobs:
      - launchdarkly/find-code-references:
          access_token: ${LD_ACCESS_TOKEN}
          proj_key: YOUR_LAUNCHDARKLY_PROJECT_KEY
          debug: true
```

### context_lines

Configuration with context lines provided. Context line documentation: https://docs.launchdarkly.com/home/code/code-references#configuring-context-lines

```yaml
version: 2.1
orbs:
  launchdarkly: launchdarkly/ld-find-code-refs@2.14.0
workflows:
  main:
    jobs:
      - launchdarkly/find-code-references:
          debug: true
          access_token: ${LD_ACCESS_TOKEN}
          proj_key: YOUR_LAUNCHDARKLY_PROJECT_KEY
          context_lines: 3
```

### standard_configuration

A configuration with the the `repoType` set to GitHub, and the `repuUrl` set to a GitHub URL. We recommend configuring these parameters so LaunchDarkly is able to generate reference links to your source code

```yaml
version: 2.1
orbs:
  launchdarkly: launchdarkly/ld-find-code-refs@2.14.0
workflows:
  main:
    jobs:
      - launchdarkly/find-code-references:
          debug: true
          access_token: ${LD_ACCESS_TOKEN}
          proj_key: YOUR_LAUNCHDARKLY_PROJECT_KEY
          repo_type: github
          repo_url: YOUR_REPO_URL
          context_lines: 3
```