Skip to content

Commit 11ae20f

Browse files
jazanneJaz White
andauthored
[sc-223067] allow branch pruning to be disabled in main job (#405)
Co-authored-by: Jaz White <[email protected]>
1 parent d73aa5d commit 11ae20f

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

build/metadata/github-actions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ If the action fails, there may be a problem with your configuration. To investig
8686
| lookback | Set the number of commits to search in history for whether you removed a feature flag from code. You may set to 0 to disable this feature. Setting this option to a high value will increase search time. | `false` | 10 |
8787
| projKey | Key of the LaunchDarkly project associated with this repository. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with `projects` block in configuration file. | `false` | |
8888
| repoName | The repository name. Defaults to the current GitHub repository. | `false` | |
89+
| prune | There is a known issue where the GitHub Action will not prune deleted branch data in private repos. Only enable this if you are running the action in a public repo. | `false` | false |
8990
<!-- action-docs-inputs -->

build/metadata/github-actions/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ inputs:
3838
repoName:
3939
description: "The repository name. Defaults to the current GitHub repository."
4040
required: false
41+
prune:
42+
default: "false"
43+
description: "There is a known issue where the GitHub Action will not prune deleted branch data in private repos. Only enable this if you are running the action in a public repo."
44+
required: false
4145
runs:
4246
using: 'docker'
4347
image: 'Dockerfile'
@@ -51,3 +55,4 @@ runs:
5155
LD_DEBUG: ${{ inputs.debug }}
5256
LD_IGNORE_SERVICE_ERRORS: ${{ inputs.ignoreServiceErrors }}
5357
LD_LOOKBACK: ${{ inputs.lookback }}
58+
LD_PRUNE: ${{ inputs.prune }}

coderefs/coderefs.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ func generateHunkOutput(opts options.Options, matcher search.Matcher, branch ld.
166166
}
167167

168168
func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.BranchRep, repoParams ld.RepoParams, gitClient *git.Client, ldApi ld.ApiClient) {
169-
lookback := opts.Lookback
170-
dryRun := opts.DryRun
171-
if lookback > 0 {
169+
if opts.Lookback > 0 {
172170
var removedFlags []ld.ExtinctionRep
173171

174172
flagCounts := branch.CountByProjectAndFlag(matcher.GetElements(), opts.GetProjectKeys())
@@ -180,22 +178,22 @@ func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.Bran
180178
}
181179
}
182180
log.Info.Printf("checking if %d flags without references were removed in the last %d commits for project: %s", len(missingFlags), opts.Lookback, project.Key)
183-
removedFlagsByProject, err := gitClient.FindExtinctions(project, missingFlags, matcher, lookback+1)
181+
removedFlagsByProject, err := gitClient.FindExtinctions(project, missingFlags, matcher, opts.Lookback+1)
184182
if err != nil {
185183
log.Warning.Printf("unable to generate flag extinctions: %s", err)
186184
} else {
187185
log.Info.Printf("found %d removed flags", len(removedFlagsByProject))
188186
}
189187
removedFlags = append(removedFlags, removedFlagsByProject...)
190188
}
191-
if len(removedFlags) > 0 && !dryRun {
189+
if len(removedFlags) > 0 && !opts.DryRun {
192190
err := ldApi.PostExtinctionEvents(removedFlags, repoParams.Name, branch.Name)
193191
if err != nil {
194192
log.Error.Printf("error sending extinction events to LaunchDarkly: %s", err)
195193
}
196194
}
197195
}
198-
if !dryRun {
196+
if !opts.DryRun && opts.Prune {
199197
log.Info.Printf("attempting to prune old code reference data from LaunchDarkly")
200198
remoteBranches, err := gitClient.RemoteBranches()
201199
if err != nil {

docs/CONFIGURATION.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,22 @@ Flags:
4444
-B, --defaultBranch string The default branch. The LaunchDarkly UI will default to this branch. If not provided, will fallback to 'main'. (default "main")
4545
4646
-d, --dir string Path to existing checkout of the repository.
47-
4847
--dryRun If enabled, the scanner will run without sending code references to LaunchDarkly. Combine with the outDir option to output code references to a CSV.
4948
5049
-h, --help help for ld-find-code-refs
5150
5251
--hunkUrlTemplate string If provided, LaunchDarkly will attempt to generate links to your VCS 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".
52+
5353
-i, --ignoreServiceErrors If enabled, the scanner will terminate with exit code 0 when the LaunchDarkly API is unreachable or returns an unexpected response.
5454
5555
-l, --lookback int 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 disabled this feature. Setting this option to a high value will increase search time. (default 10)
56+
5657
-o, --outDir string If provided, will output a csv file containing all code references for the project to this directory.
5758
5859
-p, --projKey string LaunchDarkly project key. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with "projects" block in configuration file.
5960
61+
--prune If enabled, branches that are not found in the remote repository will be deleted from LaunchDarkly. (default true)
62+
6063
-r, --repoName string Repository name. Will be displayed in LaunchDarkly. Case insensitive. Repository names must only contain letters, numbers, '.', '_' or '-'."
6164
6265
-T, --repoType string The repo service provider. Used to correctly categorize repositories in the LaunchDarkly UI. Acceptable values: bitbucket|custom|github|gitlab. (default "custom")
@@ -67,6 +70,8 @@ Flags:
6770
6871
-s, --updateSequenceId int An integer representing the order number of code reference updates. Used to version updates across concurrent executions of the flag finder. If not provided, data will always be updated. If provided, data will only be updated if the existing "updateSequenceId" is less than the new "updateSequenceId". Examples: the time a "git push" was initiated, CI build number, the current unix timestamp. (default -1)
6972
73+
--userAgent string (Internal) Platform where code references is run.
74+
7075
-v, --version version for ld-find-code-refs
7176
```
7277

options/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ the project to this directory.`,
111111
defaultValue: "",
112112
usage: `LaunchDarkly project key. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with "projects" block in configuration file.`,
113113
},
114+
{
115+
name: "prune",
116+
defaultValue: true,
117+
usage: `If enabled, branches that are not found in the remote repository will be deleted from LaunchDarkly.`,
118+
},
114119
{
115120
name: "repoName",
116121
short: "r",

options/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ type Options struct {
5757
RepoType string `mapstructure:"repoType"`
5858
RepoUrl string `mapstructure:"repoUrl"`
5959
Revision string `mapstructure:"revision"`
60+
UserAgent string `mapstructure:"userAgent"`
6061
ContextLines int `mapstructure:"contextLines"`
6162
Lookback int `mapstructure:"lookback"`
6263
UpdateSequenceId int `mapstructure:"updateSequenceId"`
6364
AllowTags bool `mapstructure:"allowTags"`
6465
Debug bool `mapstructure:"debug"`
6566
DryRun bool `mapstructure:"dryRun"`
6667
IgnoreServiceErrors bool `mapstructure:"ignoreServiceErrors"`
67-
UserAgent string `mapstructure:"userAgent"`
68+
Prune bool `mapstructure:"prune"`
6869

6970
// The following options can only be configured via YAML configuration
7071

0 commit comments

Comments
 (0)