95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/publish"
|
|
)
|
|
|
|
type runSummary struct {
|
|
dryRun bool
|
|
planned int
|
|
publishNew int
|
|
upsertAdditive int
|
|
replaceCatalog int
|
|
skipSame int
|
|
forceReplace int
|
|
failUnmanaged int
|
|
failConflict int
|
|
failures int
|
|
fixedPath int
|
|
}
|
|
|
|
func (s *runSummary) recordPlan(action publish.Action) {
|
|
s.planned++
|
|
switch action {
|
|
case publish.ActionPublishNew:
|
|
s.publishNew++
|
|
case publish.ActionUpsertAdditive:
|
|
s.upsertAdditive++
|
|
case publish.ActionReplaceCatalog:
|
|
s.replaceCatalog++
|
|
case publish.ActionForceReplace:
|
|
s.forceReplace++
|
|
case publish.ActionSkipSame, publish.ActionSkipDestinationNewer:
|
|
s.skipSame++
|
|
}
|
|
}
|
|
|
|
func (s *runSummary) recordFailureAction(action string) {
|
|
switch action {
|
|
case string(publish.ActionFailUnmanaged):
|
|
s.failUnmanaged++
|
|
case string(publish.ActionFailConflict):
|
|
s.failConflict++
|
|
}
|
|
}
|
|
|
|
func (s *runSummary) recordFailure() {
|
|
s.failures++
|
|
}
|
|
|
|
func (s *runSummary) recordFixedPath() {
|
|
s.fixedPath++
|
|
}
|
|
|
|
type RunSummaryCounters struct {
|
|
Status string `json:"status"`
|
|
Planned int `json:"planned"`
|
|
PublishNew int `json:"publish_new"`
|
|
UpsertAdditive int `json:"upsert_additive"`
|
|
ReplaceCatalog int `json:"replace_catalog"`
|
|
SkipSame int `json:"skip_same"`
|
|
ForceReplace int `json:"force_replace"`
|
|
FailUnmanaged int `json:"fail_unmanaged"`
|
|
FailConflict int `json:"fail_conflict"`
|
|
Failed int `json:"failed"`
|
|
DryRun bool `json:"dry_run"`
|
|
FixedPath int `json:"fixed_path"`
|
|
}
|
|
|
|
func (s RunSummaryCounters) Line() string {
|
|
return fmt.Sprintf("Final status: %s planned=%d publish_new=%d upsert_additive=%d replace_catalog=%d skip_same=%d force_replace=%d fail_unmanaged=%d fail_conflict=%d failed=%d dry_run=%t fixed_path=%d", s.Status, s.Planned, s.PublishNew, s.UpsertAdditive, s.ReplaceCatalog, s.SkipSame, s.ForceReplace, s.FailUnmanaged, s.FailConflict, s.Failed, s.DryRun, s.FixedPath)
|
|
}
|
|
|
|
func (s runSummary) Result() RunSummaryCounters {
|
|
status := "ok"
|
|
if s.failures > 0 {
|
|
status = "failed"
|
|
}
|
|
return RunSummaryCounters{
|
|
Status: status,
|
|
Planned: s.planned,
|
|
PublishNew: s.publishNew,
|
|
UpsertAdditive: s.upsertAdditive,
|
|
ReplaceCatalog: s.replaceCatalog,
|
|
SkipSame: s.skipSame,
|
|
ForceReplace: s.forceReplace,
|
|
FailUnmanaged: s.failUnmanaged,
|
|
FailConflict: s.failConflict,
|
|
Failed: s.failures,
|
|
DryRun: s.dryRun,
|
|
FixedPath: s.fixedPath,
|
|
}
|
|
}
|