BUG: "ppreview --expect-no-changes" returns error for "informational" messages (#2936)

This commit is contained in:
Tom Limoncelli 2024-05-07 14:14:20 -04:00 committed by GitHub
parent a679095bcb
commit 6817e08baa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 10 deletions

View file

@ -232,27 +232,34 @@ func prun(args PPreviewArgs, push bool, interactive bool, out printer.CLI, repor
var anyErrors bool
for _, zone := range zonesToProcess {
out.StartDomain(zone.GetUniqueName())
// Process DNS provider changes:
providersToProcess := whichProvidersToProcess(zone.DNSProviderInstances, args.Providers)
for _, provider := range zone.DNSProviderInstances {
skip := skipProvider(provider.Name, providersToProcess)
out.StartDNSProvider(provider.Name, skip)
if !skip {
corrections := zone.GetCorrections(provider.Name)
totalCorrections += len(corrections)
numActions := countActions(corrections)
totalCorrections += numActions
out.EndProvider2(provider.Name, numActions)
reportItems = append(reportItems, genReportItem(zone.Name, corrections, provider.Name))
anyErrors = cmp.Or(anyErrors, pprintOrRunCorrections(zone.Name, provider.Name, corrections, out, push, interactive, notifier, report))
out.EndProvider(provider.Name, len(corrections), nil)
}
}
// Process Registrar changes:
skip := skipProvider(zone.RegistrarInstance.Name, providersToProcess)
out.StartRegistrar(zone.RegistrarName, !skip)
if skip {
corrections := zone.GetCorrections(zone.RegistrarInstance.Name)
totalCorrections += len(corrections)
numActions := countActions(corrections)
out.EndProvider2(zone.RegistrarName, numActions)
totalCorrections += numActions
reportItems = append(reportItems, genReportItem(zone.Name, corrections, zone.RegistrarName))
anyErrors = cmp.Or(anyErrors, pprintOrRunCorrections(zone.Name, zone.RegistrarInstance.Name, corrections, out, push, interactive, notifier, report))
out.EndProvider(zone.RegistrarName, len(corrections), nil)
}
}
if os.Getenv("TEAMCITY_VERSION") != "" {
@ -274,6 +281,16 @@ func prun(args PPreviewArgs, push bool, interactive bool, out printer.CLI, repor
return nil
}
func countActions(corrections []*models.Correction) int {
r := 0
for _, c := range corrections {
if c.F != nil {
r++
}
}
return r
}
func whichZonesToProcess(domains []*models.DomainConfig, filter string) []*models.DomainConfig {
if filter == "" || filter == "all" {
return domains
@ -429,25 +446,40 @@ func pprintOrRunCorrections(zoneName string, providerName string, corrections []
return false
}
var anyErrors bool
for i, correction := range corrections {
out.PrintCorrection(i, correction)
cc := 0
cn := 0
for _, correction := range corrections {
// Print what we're about to do.
if correction.F == nil {
out.PrintReport(cn, correction)
cn++
} else {
out.PrintCorrection(cc, correction)
cc++
}
var err error
if push {
// If interactive, ask "are you sure?" and skip if not.
if interactive && !out.PromptToRun() {
continue
}
// If it is an action (not an informational message), notify and execute.
if correction.F != nil {
notifier.Notify(zoneName, providerName, correction.Msg, err, false)
err = correction.F()
out.EndCorrection(err)
if err != nil {
anyErrors = true
}
}
out.EndCorrection(err)
}
notifier.Notify(zoneName, providerName, correction.Msg, err, !push)
}
_ = report // File name to write report to.
_ = report // File name to write report to. (obsolete)
return anyErrors
}

View file

@ -16,6 +16,7 @@ type CLI interface {
StartDomain(domain string)
StartDNSProvider(name string, skip bool)
EndProvider(name string, numCorrections int, err error)
EndProvider2(name string, numCorrections int)
StartRegistrar(name string, skip bool)
PrintCorrection(n int, c *models.Correction)
@ -170,6 +171,18 @@ func (c ConsolePrinter) EndProvider(name string, numCorrections int, err error)
}
}
// EndProvider2 is called at the end of each provider.
func (c ConsolePrinter) EndProvider2(name string, numCorrections int) {
plural := "s"
if numCorrections == 1 {
plural = ""
}
if (SkinnyReport) && (numCorrections == 0) {
return
}
fmt.Fprintf(c.Writer, "%d correction%s (%s)\n", numCorrections, plural, name)
}
// Debugf is called to print/format debug information.
func (c ConsolePrinter) Debugf(format string, args ...interface{}) {
if c.Verbose {
@ -197,7 +210,7 @@ func (c ConsolePrinter) Errorf(format string, args ...interface{}) {
fmt.Fprintf(c.Writer, "ERROR: "+format, args...)
}
// Errorf is called to optionally print/format a message.
// PrintfIf is called to optionally print/format a message.
func (c ConsolePrinter) PrintfIf(print bool, format string, args ...interface{}) {
if print {
fmt.Fprintf(c.Writer, format, args...)