mirror of
https://github.com/vale981/agru
synced 2025-03-05 17:51:42 -05:00
speedup, add name field
This commit is contained in:
parent
c00433661f
commit
e87b3ee1ae
1 changed files with 22 additions and 10 deletions
32
main.go
32
main.go
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
@ -14,6 +15,7 @@ type RequirementsFile []RequirementsEntry
|
|||
type RequirementsEntry struct {
|
||||
Src string `yaml:"src"`
|
||||
Version string `yaml:"version"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
}
|
||||
|
||||
var requirementsPath string
|
||||
|
@ -32,13 +34,22 @@ func main() {
|
|||
|
||||
func updateRequirements(path string) {
|
||||
entries := parseRequirements(path)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(entries))
|
||||
for i, entry := range entries {
|
||||
newVersion := updateRequirementEntry(entry)
|
||||
if newVersion != "" {
|
||||
log.Println(entry.Src, entry.Version, "->", newVersion)
|
||||
entries[i].Version = newVersion
|
||||
}
|
||||
go func(i int, entry RequirementsEntry, wg *sync.WaitGroup) {
|
||||
newVersion := getNewVersion(entry.Src, entry.Version)
|
||||
if newVersion != "" {
|
||||
log.Println(entry.Src, entry.Version, "->", newVersion)
|
||||
entry.Version = newVersion
|
||||
entries[i] = entry
|
||||
}
|
||||
wg.Done()
|
||||
}(i, entry, &wg)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
outb, err := yaml.Marshal(entries)
|
||||
if err != nil {
|
||||
log.Println("ERROR: ", err)
|
||||
|
@ -63,17 +74,17 @@ func parseRequirements(path string) RequirementsFile {
|
|||
return req
|
||||
}
|
||||
|
||||
func updateRequirementEntry(entry RequirementsEntry) string {
|
||||
if ignoredVersions[entry.Version] {
|
||||
func getNewVersion(src, version string) string {
|
||||
if ignoredVersions[version] {
|
||||
return ""
|
||||
}
|
||||
|
||||
// not a git repo
|
||||
if !strings.Contains(entry.Src, "https") && !strings.Contains(entry.Src, "git") {
|
||||
if !strings.Contains(src, "git") {
|
||||
return ""
|
||||
}
|
||||
|
||||
repo := strings.Replace(entry.Src, "git+https", "https", 1)
|
||||
repo := strings.Replace(src, "git+https", "https", 1)
|
||||
tags, err := execute("git ls-remote -tq --sort=-version:refname " + repo)
|
||||
if err != nil {
|
||||
log.Println("ERROR: ", err)
|
||||
|
@ -90,7 +101,8 @@ func updateRequirementEntry(entry RequirementsEntry) string {
|
|||
return ""
|
||||
}
|
||||
last := strings.Replace(lastline[tagidx:], "refs/tags/", "", 1)
|
||||
if last != entry.Version {
|
||||
last = strings.Replace(last, "^{}", "", 1) // NOTE: very weird case with some github repos, didn't find out why it does that
|
||||
if last != version {
|
||||
return last
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue