Skip to content

Commit f365cc3

Browse files
author
Dan O'Brien
authored
Do not run extinctions with dry run (#176)
* do not run extinctions with dry run * change dry run logic conditional log message * fix typo
1 parent 5f7ffd0 commit f365cc3

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

coderefs/coderefs.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func handleOutput(opts options.Options, matcher search.Matcher, branch ld.Branch
152152

153153
func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.BranchRep, repoParams ld.RepoParams, gitClient *git.Client, ldApi ld.ApiClient) {
154154
lookback := opts.Lookback
155+
dryRun := opts.DryRun
155156
if lookback > 0 {
156157
missingFlags := []string{}
157158
for flag, count := range branch.CountByFlag(matcher.Elements[0].Elements) {
@@ -165,23 +166,29 @@ func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.Bran
165166
if err != nil {
166167
log.Warning.Printf("unable to generate flag extinctions: %s", err)
167168
} else {
168-
log.Info.Printf("found %d removed flags", len(removedFlags))
169+
msg := fmt.Sprintf("found %d removed flags", len(removedFlags))
170+
if dryRun {
171+
msg += ", --dryRun flag set, not updating LaunchDarkly"
172+
}
173+
log.Info.Printf(msg)
169174
}
170-
if len(removedFlags) > 0 {
175+
if len(removedFlags) > 0 && !dryRun {
171176
err = ldApi.PostExtinctionEvents(removedFlags, repoParams.Name, branch.Name)
172177
if err != nil {
173178
log.Error.Printf("error sending extinction events to LaunchDarkly: %s", err)
174179
}
175180
}
176181
}
177-
log.Info.Printf("attempting to prune old code reference data from LaunchDarkly")
178-
remoteBranches, err := gitClient.RemoteBranches()
179-
if err != nil {
180-
log.Warning.Printf("unable to retrieve branch list from remote, skipping code reference pruning: %s", err)
181-
} else {
182-
err = deleteStaleBranches(ldApi, repoParams.Name, remoteBranches)
182+
if !dryRun {
183+
log.Info.Printf("attempting to prune old code reference data from LaunchDarkly")
184+
remoteBranches, err := gitClient.RemoteBranches()
183185
if err != nil {
184-
helpers.FatalServiceError(fmt.Errorf("failed to mark old branches for code reference pruning: %w", err), opts.IgnoreServiceErrors)
186+
log.Warning.Printf("unable to retrieve branch list from remote, skipping code reference pruning: %s", err)
187+
} else {
188+
err = deleteStaleBranches(ldApi, repoParams.Name, remoteBranches)
189+
if err != nil {
190+
helpers.FatalServiceError(fmt.Errorf("failed to mark old branches for code reference pruning: %w", err), opts.IgnoreServiceErrors)
191+
}
185192
}
186193
}
187194
}

0 commit comments

Comments
 (0)