func SetVersion(started *Started, finished *Finished, repoCommit, jobVersion string) {
	if started != nil && repoCommit != "" {
		started.DeprecatedRepoVersion = repoCommit  
		started.RepoCommit = repoCommit
	}
	if finished != nil && jobVersion != "" {
		if finished.Metadata == nil {
			finished.Metadata = Metadata{}
		}
		finished.Metadata["job-version"] = jobVersion
		finished.DeprecatedJobVersion = jobVersion
	}
}
SetVersion ensures that the repoCommit and jobVersion are set appropriately.
package metadata
import (
	"strings"
)
type Started struct {
	Timestamp int64 `json:"timestamp"`  
	Node string `json:"node,omitempty"`
	Pull string `json:"pull,omitempty"`
	Repos      map[string]string `json:"repos,omitempty"`  
	RepoCommit string            `json:"repo-commit,omitempty"`
	Metadata Metadata `json:"metadata,omitempty"`  
	DeprecatedJobVersion  string `json:"job-version,omitempty"`   
	DeprecatedRepoVersion string `json:"repo-version,omitempty"`  
}
const (
	JobVersion = "job-version"
)
type Finished struct {
	Timestamp *int64 `json:"timestamp,omitempty"`
	Passed *bool `json:"passed"`
	Metadata Metadata `json:"metadata,omitempty"`
	Result string `json:"result,omitempty"`  
	DeprecatedJobVersion  string `json:"job-version,omitempty"`   
	DeprecatedRevision    string `json:"revision,omitempty"`      
	DeprecatedRepoVersion string `json:"repo-version,omitempty"`  
}
type Metadata map[string]interface{}
func (m Metadata) String(name string) (*string, bool) {
	if v, ok := m[name]; !ok {
		return nil, false
	} else if t, good := v.(string); !good {
		return nil, true
	} else {
		return &t, true
	}
}
func (m Metadata) Meta(name string) (*Metadata, bool) {
	if v, ok := m[name]; !ok {
		return nil, false
	} else if t, good := v.(Metadata); good {
		return &t, true
	} else if t, good := v.(map[string]interface{}); good {
		child := Metadata(t)
		return &child, true
	}
	return nil, true
}
func (m Metadata) Keys() []string {
	ka := make([]string, 0, len(m))
	for k := range m {
		if _, ok := m.Meta(k); ok {
			ka = append(ka, k)
		}
	}
	return ka
}
func (m Metadata) Strings() map[string]string {
	bm := map[string]string{}
	for k, v := range m {
		if s, ok := v.(string); ok {
			bm[k] = s
		}
	}
	return bm
}
func (m Metadata) MultiString(name string) ([]string, bool) {
	if v, ok := m[name]; !ok {
		return []string{}, false
	} else if lstStr, good := v.([]string); good {
		return lstStr, true
	} else if lstInter, good := v.([]interface{}); good {
		convertedStrings := []string{}
		for _, inter := range lstInter {
			s, good := inter.(string)
			if !good {
				return []string{}, true
			}
			convertedStrings = append(convertedStrings, s)
		}
		return convertedStrings, true
	}
	return []string{}, true
}
func firstFilled(def string, options ...string) string {
	for _, o := range options {
		if o != "" {
			return o
		}
	}
	return def
}
const Missing = "missing"
func Version(started Started, finished Finished) string {
	meta := func(key string) string {
		if finished.Metadata == nil {
			return ""
		}
		v, ok := finished.Metadata.String(key)
		if !ok {
			return ""
		}
		return *v
	}
	val := firstFilled(
		Missing,
		finished.DeprecatedJobVersion, started.DeprecatedJobVersion,
		started.DeprecatedRepoVersion, finished.DeprecatedRepoVersion,
		meta("revision"), meta("repo-commit"),
		meta(JobVersion), started.RepoCommit,  
	)
	parts := strings.SplitN(val, "+", 2)
	val = parts[len(parts)-1]
	if n := len(val); n > 9 {
		return val[:9]
	}
	return val
}