-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
105 lines (92 loc) · 2.06 KB
/
Copy pathhelpers.go
File metadata and controls
105 lines (92 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"time"
)
func truncateString(s string, maxLen int) string {
if len(s) <= maxLen {
return s
}
if maxLen <= 3 {
return s[:maxLen]
}
return s[:maxLen-3] + "..."
}
func openBrowser(url string) {
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("open", url)
case "windows":
cmd = exec.Command("cmd", "/c", "start", url)
default: // linux, freebsd, etc.
cmd = exec.Command("xdg-open", url)
}
if err := cmd.Start(); err != nil {
fmt.Fprintf(os.Stderr, "Error opening browser: %v\n", err)
}
}
func formatRelativeTime(t time.Time) string {
if t.IsZero() {
return "-"
}
duration := time.Since(t)
minutes := int(duration.Minutes())
hours := int(duration.Hours())
days := hours / 24
weeks := days / 7
months := days / 30
if minutes < 60 {
return fmt.Sprintf("%dm ago", minutes)
}
if hours < 24 {
return fmt.Sprintf("%dh ago", hours)
}
if days < 7 {
return fmt.Sprintf("%dd ago", days)
}
if weeks < 4 {
return fmt.Sprintf("%dw ago", weeks)
}
return fmt.Sprintf("%dmo ago", months)
}
func calculateAvgReleaseFreq(entries []ChangelogEntry) string {
// Need at least 2 entries with valid dates to calculate average
var validEntries []ChangelogEntry
for _, e := range entries {
if !e.ReleasedAt.IsZero() {
validEntries = append(validEntries, e)
}
if len(validEntries) >= 10 {
break
}
}
if len(validEntries) < 2 {
return "-"
}
// Calculate intervals between consecutive releases
var totalDuration time.Duration
for i := 0; i < len(validEntries)-1; i++ {
interval := validEntries[i].ReleasedAt.Sub(validEntries[i+1].ReleasedAt)
totalDuration += interval
}
avgDuration := totalDuration / time.Duration(len(validEntries)-1)
// Format as relative time
hours := int(avgDuration.Hours())
days := hours / 24
weeks := days / 7
months := days / 30
if days < 1 {
return fmt.Sprintf("~%dh", hours)
}
if days < 7 {
return fmt.Sprintf("~%dd", days)
}
if weeks < 4 {
return fmt.Sprintf("~%dw", weeks)
}
return fmt.Sprintf("~%dmo", months)
}