Factor updatePolicy out
@@ -183,7 +183,14 @@ func (d *Daemon) UpdateManifests(spec update.Spec) (job.ID, error) {
case release.Changes:
return d.queueJob(d.release(spec, s)), nil
case policy.Updates:
- return d.queueJob(func(jobID job.ID, working *git.Checkout, logger log.Logger) (*history.CommitEventMetadata, error) {
+ return d.queueJob(d.updatePolicy(spec, s)), nil
+ default:
+ return id, fmt.Errorf(`unknown update type "%s"`, spec.Type)
+ }
+}
+
+func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) DaemonJobFunc {
+ return func(jobID job.ID, working *git.Checkout, logger log.Logger) (*history.CommitEventMetadata, error) {
// For each update
var serviceIDs []flux.ServiceID
metadata := &history.CommitEventMetadata{
@@ -196,7 +203,7 @@ func (d *Daemon) UpdateManifests(spec update.Spec) (job.ID, error) {
// automation run straight ASAP.
var anythingAutomated bool
- for serviceID, u := range s {
+ for serviceID, u := range updates {
if policy.Set(u.Add).Contains(policy.Automated) {
anythingAutomated = true
}
@@ -238,7 +245,7 @@ func (d *Daemon) UpdateManifests(spec update.Spec) (job.ID, error) {
return metadata, nil
}
- if err := working.CommitAndPush(policyCommitMessage(s, spec.Cause), &git.Note{JobID: jobID, Spec: spec}); err != nil {
+ if err := working.CommitAndPush(policyCommitMessage(updates, spec.Cause), &git.Note{JobID: jobID, Spec: spec}); err != nil {
// On the chance pushing failed because it was not
// possible to fast-forward, ask for a sync so the
// next attempt is more likely to succeed.
@@ -255,9 +262,6 @@ func (d *Daemon) UpdateManifests(spec update.Spec) (job.ID, error) {
return nil, err
}
return metadata, nil
- }), nil
- default:
- return id, fmt.Errorf(`unknown update type "%s"`, spec.Type)
}
}
