Support shortening of revision with digest
The `\b` in the regular expression ensures we only match with a hexadecimal notation as awhole, while still allowing to match with e.g. `sha1:...` which would not have been possible by using `\W` as this includes `_`. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
@@ -18,15 +18,15 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
|
||||
|
||||
"github.com/fluxcd/flux2/internal/utils"
|
||||
)
|
||||
|
||||
var getKsCmd = &cobra.Command{
|
||||
@@ -80,10 +80,8 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in
|
||||
item := a.Items[i]
|
||||
revision := item.Status.LastAppliedRevision
|
||||
status, msg := statusAndMessage(item.Status.Conditions)
|
||||
if status == string(metav1.ConditionTrue) {
|
||||
revision = shortenCommitSha(revision)
|
||||
msg = shortenCommitSha(msg)
|
||||
}
|
||||
revision = utils.TruncateHex(revision)
|
||||
msg = utils.TruncateHex(msg)
|
||||
return append(nameColumns(&item, includeNamespace, includeKind),
|
||||
revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)), status, msg)
|
||||
}
|
||||
@@ -100,13 +98,3 @@ func (a kustomizationListAdapter) statusSelectorMatches(i int, conditionType, co
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
func shortenCommitSha(msg string) string {
|
||||
r := regexp.MustCompile("/([a-f0-9]{40})$")
|
||||
sha := r.FindString(msg)
|
||||
if sha != "" {
|
||||
msg = strings.Replace(msg, sha, string([]rune(sha)[:8]), -1)
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user