-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.go
More file actions
237 lines (203 loc) · 7.29 KB
/
report.go
File metadata and controls
237 lines (203 loc) · 7.29 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package main
import (
"fmt"
"sort"
"strings"
"time"
)
// plural returns "s" if n != 1, otherwise empty string
func plural(n int) string {
if n == 1 {
return ""
}
return "s"
}
// GenerateBasicReport creates a Markdown report of upgrade candidates and archived dependencies
func GenerateBasicReport(candidates []UpgradeCandidate, archivedDeps []ArchivedDependency) string {
var sb strings.Builder
sb.WriteString("# Dependency Major Version Upgrade Analysis\n")
fmt.Fprintf(&sb, "Generated: %s\n\n", time.Now().UTC().Format("2006-01-02 15:04:05 MST"))
// Summary section
archivedWithUpgrades := 0
for _, c := range candidates {
if c.Archived {
archivedWithUpgrades++
}
}
totalArchived := archivedWithUpgrades + len(archivedDeps)
sb.WriteString("## Summary\n")
fmt.Fprintf(&sb, "- Upgrade candidates: %d\n", len(candidates))
if totalArchived > 0 {
fmt.Fprintf(&sb, "- ⚠️ Archived dependencies: %d\n", totalArchived)
}
sb.WriteString("\n")
// Sort candidates by version jump (descending), then alphabetically by path
sortedCandidates := make([]UpgradeCandidate, len(candidates))
copy(sortedCandidates, candidates)
sort.Slice(sortedCandidates, func(i, j int) bool {
if sortedCandidates[i].VersionJump() != sortedCandidates[j].VersionJump() {
return sortedCandidates[i].VersionJump() > sortedCandidates[j].VersionJump()
}
return sortedCandidates[i].Path < sortedCandidates[j].Path
})
// Available upgrades section
if len(sortedCandidates) > 0 {
sb.WriteString("## Available Upgrades\n\n")
for _, uc := range sortedCandidates {
writeUpgradeCandidate(&sb, uc)
}
}
// Archived dependencies without upgrades section
if len(archivedDeps) > 0 {
sb.WriteString("## Archived Dependencies (No Upgrades Available)\n\n")
sb.WriteString("The following dependencies are archived and no longer maintained. ")
sb.WriteString("You are currently on the latest version, but you should consider migrating to actively maintained alternatives.\n\n")
// Sort archived deps alphabetically
sortedArchived := make([]ArchivedDependency, len(archivedDeps))
copy(sortedArchived, archivedDeps)
sort.Slice(sortedArchived, func(i, j int) bool {
return sortedArchived[i].Path < sortedArchived[j].Path
})
for _, ad := range sortedArchived {
writeArchivedDependency(&sb, ad)
}
}
return sb.String()
}
// writeUpgradeCandidate writes a single upgrade candidate to the report
func writeUpgradeCandidate(sb *strings.Builder, uc UpgradeCandidate) {
latest := uc.LatestAvailable()
// Header with package name and version jump
fmt.Fprintf(sb, "### %s: %s → %s (%d major version",
extractPackageName(uc.Path), uc.CurrentVer, latest.MajorVer, uc.VersionJump())
if uc.VersionJump() > 1 {
sb.WriteString("s")
}
sb.WriteString(")\n\n")
// Archived warning (prominent)
if uc.Archived {
sb.WriteString("**🗄️ ARCHIVED**: This repository is archived and no longer maintained\n\n")
}
// Current version with full version string, release date and age
if uc.CurrentReleasedAt != nil {
// Calculate age
age := time.Since(*uc.CurrentReleasedAt)
days := int(age.Hours() / 24)
ageStr := fmt.Sprintf("%d days old", days)
if days > 365 {
years := days / 365
months := (days % 365) / 30
if months > 0 {
ageStr = fmt.Sprintf("%d year%s, %d month%s old", years, plural(years), months, plural(months))
} else {
ageStr = fmt.Sprintf("%d year%s old", years, plural(years))
}
} else if days > 30 {
months := days / 30
ageStr = fmt.Sprintf("%d month%s old", months, plural(months))
}
fmt.Fprintf(sb, "**Current**: %s (released %s, %s)\n",
uc.CurrentFull, uc.CurrentReleasedAt.Format("2006-01-02"), ageStr)
} else {
fmt.Fprintf(sb, "**Current**: %s\n", uc.CurrentFull)
}
// Latest available version with release date
if latest.ReleasedAt != nil {
fmt.Fprintf(sb, "**Latest**: %s (released %s)\n",
latest.FullVersion, latest.ReleasedAt.Format("2006-01-02"))
// Warn if the "upgrade" is actually older than current
if uc.CurrentReleasedAt != nil && latest.ReleasedAt.Before(*uc.CurrentReleasedAt) {
sb.WriteString("**⚠️ Warning**: This version is OLDER than your current version (suggests version numbering scheme changed)\n")
}
} else {
fmt.Fprintf(sb, "**Latest**: %s\n", latest.FullVersion)
}
// Impact analysis
if uc.Impact != nil {
fmt.Fprintf(sb, "**Impact**: %d files affected", uc.Impact.FilesAffected)
if len(uc.Impact.Components) > 0 {
fmt.Fprintf(sb, " (%s)", strings.Join(uc.Impact.Components, ", "))
}
sb.WriteString("\n")
}
// GitHub link
githubURL := extractGitHubURL(uc.BasePath)
if githubURL != "" {
fmt.Fprintf(sb, "**Repository**: %s\n", githubURL)
}
// Changelog information
if uc.Changelog != nil && uc.Changelog.Found {
fmt.Fprintf(sb, "**Changelog**: %s\n", uc.Changelog.URL)
// Breaking changes
if len(uc.Changelog.BreakingChanges) > 0 {
sb.WriteString("**Breaking Changes**:\n")
for _, change := range uc.Changelog.BreakingChanges {
fmt.Fprintf(sb, "- %s\n", change)
}
}
}
sb.WriteString("\n")
}
// writeArchivedDependency writes a single archived dependency to the report
func writeArchivedDependency(sb *strings.Builder, ad ArchivedDependency) {
// Header with package name
fmt.Fprintf(sb, "### %s: %s\n\n", extractPackageName(ad.Path), ad.CurrentFull)
// Archived warning
sb.WriteString("**🗄️ ARCHIVED**: This repository is archived and no longer maintained\n\n")
// Current version info
if ad.CurrentReleasedAt != nil {
// Calculate age
age := time.Since(*ad.CurrentReleasedAt)
days := int(age.Hours() / 24)
ageStr := fmt.Sprintf("%d days old", days)
if days > 365 {
years := days / 365
months := (days % 365) / 30
if months > 0 {
ageStr = fmt.Sprintf("%d year%s, %d month%s old", years, plural(years), months, plural(months))
} else {
ageStr = fmt.Sprintf("%d year%s old", years, plural(years))
}
} else if days > 30 {
months := days / 30
ageStr = fmt.Sprintf("%d month%s old", months, plural(months))
}
fmt.Fprintf(sb, "**Current Version**: %s (released %s, %s)\n", ad.CurrentFull, ad.CurrentReleasedAt.Format("2006-01-02"), ageStr)
} else {
fmt.Fprintf(sb, "**Current Version**: %s\n", ad.CurrentFull)
}
// GitHub link
githubURL := extractGitHubURL(ad.BasePath)
if githubURL != "" {
fmt.Fprintf(sb, "**Repository**: %s\n", githubURL)
}
sb.WriteString("\n")
}
// extractPackageName extracts a short package name from the full path
// e.g., github.com/vbauerster/mpb/v4 -> vbauerster/mpb
func extractPackageName(path string) string {
// Remove version suffix
basePath := versionSuffixRegex.ReplaceAllString(path, "")
// For github.com/owner/repo format, return owner/repo
parts := strings.Split(basePath, "/")
if len(parts) >= 3 && parts[0] == "github.com" {
return parts[1] + "/" + parts[2]
}
// For other paths, return last 2 components or the whole thing
if len(parts) >= 2 {
return parts[len(parts)-2] + "/" + parts[len(parts)-1]
}
return basePath
}
// extractGitHubURL converts a module path to a GitHub URL if possible
func extractGitHubURL(path string) string {
// Resolve vanity imports first
resolvedPath := resolveVanityImport(path)
if strings.HasPrefix(resolvedPath, "github.com/") {
parts := strings.Split(resolvedPath, "/")
if len(parts) >= 3 {
return fmt.Sprintf("https://github.com/%s/%s", parts[1], parts[2])
}
}
return ""
}