Skip to content

Commit ff4a4a4

Browse files
Sahilb315abhisek
andauthored
update pmg banner & fix empty commit (#127)
* update pmg banner & fix empty commit * rm old banner * precompile regex for version * fix: Color in github URL (#128) --------- Co-authored-by: Abhisek Datta <abhisek.datta@gmail.com>
1 parent edfdd54 commit ff4a4a4

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

internal/ui/banner.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,53 @@ package ui
22

33
import (
44
"fmt"
5+
"regexp"
6+
"strings"
57

68
"github.com/fatih/color"
79
)
810

911
var (
10-
brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink
11-
whiteDim = color.New(color.Faint).SprintFunc()
12+
brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink
13+
whiteDim = color.New(color.Faint).SprintFunc()
14+
pseudoPattern = regexp.MustCompile(`^(v?\d+\.\d+\.\d+)-0\.\d{14}-[a-f0-9]{12}$`)
1215
)
1316

1417
func GeneratePMGBanner(version, commit string) string {
15-
var pmgASCIIText = `
16-
█▀█ █▀▄▀█ █▀▀ From SafeDep
17-
█▀▀ █░▀░█ █▄█` // It should end here no \n
18+
// Build the first line with a differently colored URL segment
19+
line1 := fmt.Sprintf("%s\tFrom SafeDep %s", brandPinkRed("█▀█ █▀▄▀█ █▀▀"), whiteDim("(github.com/safedep/pmg)"))
20+
line2 := brandPinkRed("█▀▀ █░▀░█ █▄█")
21+
22+
pmgASCIIText := "\n" + line1 + "\n" + line2 // It should end here no \n
1823

1924
if len(commit) >= 6 {
2025
commit = commit[:6]
2126
}
2227

23-
return fmt.Sprintf("%s %s: %s %s: %s\n\n", brandPinkRed(pmgASCIIText),
28+
// Clean version to remove pseudo-version complexity
29+
version = cleanVersion(version)
30+
31+
return fmt.Sprintf("%s %s: %s %s: %s\n\n", pmgASCIIText,
2432
whiteDim("version"), Colors.Bold(version),
2533
whiteDim("commit"), Colors.Bold(commit),
2634
)
2735
}
36+
37+
// cleanVersion removes ugly pseudo-version timestamps and dirty flags
38+
// Keeps clean versions like v1.2.3-alpha.1 and v0.3.5-edfdd54 as-is
39+
func cleanVersion(version string) string {
40+
if version == "" {
41+
return version
42+
}
43+
44+
// Remove build metadata (+dirty, +build.1, etc.)
45+
version = strings.Split(version, "+")[0]
46+
47+
// Only clean pseudo-versions with timestamps
48+
// Pattern: v1.2.3-0.20220101123456-abcdef123456
49+
if matches := pseudoPattern.FindStringSubmatch(version); len(matches) > 1 {
50+
return matches[1]
51+
}
52+
53+
return version
54+
}

internal/version/version.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ var (
88
)
99

1010
func init() {
11+
buildInfo, ok := runtimeDebug.ReadBuildInfo()
12+
if !ok {
13+
return
14+
}
15+
1116
if Version == "" {
12-
buildInfo, _ := runtimeDebug.ReadBuildInfo()
1317
Version = buildInfo.Main.Version
1418
}
19+
20+
if Commit == "" {
21+
for _, setting := range buildInfo.Settings {
22+
if setting.Key == "vcs.revision" {
23+
Commit = setting.Value
24+
break
25+
}
26+
}
27+
}
1528
}

0 commit comments

Comments
 (0)