diff --git a/providers/git/provider.go b/providers/git/provider.go index 0a118d4..593658a 100644 --- a/providers/git/provider.go +++ b/providers/git/provider.go @@ -19,13 +19,13 @@ package git import ( "bufio" "bytes" - "fmt" + "fmt" "github.com/DataDrake/cuppa/results" "io" + "os" "os/exec" "strings" "time" - "os" ) // Provider provides a common interface for each of the backend providers @@ -40,43 +40,43 @@ func (p Provider) Name() string { func (p Provider) Latest(name string) (r *results.Result, s results.Status) { pieces := strings.Split(name, "/") repoName := strings.Split(pieces[len(pieces)-1], ".")[0] - tmp := fmt.Sprintf("/tmp/%s", repoName) + tmp := fmt.Sprintf("/tmp/%s", repoName) cmd := exec.Command("git", "clone", "--depth=1", name) - cmd.Dir = "/tmp" + cmd.Dir = "/tmp" err := cmd.Run() - if err == nil { - cmd = exec.Command("git", "fetch", "--tags", "--depth=1") - cmd.Dir = tmp - err = cmd.Run() - } + if err == nil { + cmd = exec.Command("git", "fetch", "--tags", "--depth=1") + cmd.Dir = tmp + err = cmd.Run() + } buff := new(bytes.Buffer) read := bufio.NewReader(buff) - var line []byte - var tag string - var date time.Time - if err != nil { - s = results.Unavailable - goto CLEANUP - } - cmd = exec.Command("git", "log", "--tags", "-n 10", "--format='%S %cI'") - cmd.Dir = tmp + var line []byte + var tag string + var date time.Time + if err != nil { + s = results.Unavailable + goto CLEANUP + } + cmd = exec.Command("git", "log", "--tags", "-n 10", "--format='%S %cI'") + cmd.Dir = tmp cmd.Stdout = buff - cmd.Run() + cmd.Run() line, _, err = read.ReadLine() for err == nil { pieces = strings.Fields(string(line)) tag = pieces[0] - date, _ = time.Parse("2006-01-02T15:04:05-07:00", pieces[1]) + date, _ = time.Parse("2006-01-02T15:04:05-07:00", pieces[1]) r = results.NewResult(repoName, tag, "git|"+name, date) line, _, err = read.ReadLine() } if err != io.EOF || r == nil { s = results.NotFound } else { - s = results.OK - } + s = results.OK + } CLEANUP: - os.RemoveAll(tmp) + os.RemoveAll(tmp) return } diff --git a/providers/github/graphql.go b/providers/github/graphql.go index 5af467a..f43e3a4 100644 --- a/providers/github/graphql.go +++ b/providers/github/graphql.go @@ -85,13 +85,13 @@ type RepoQueryResult struct { } `json:"releases"` Refs struct { Nodes []struct { - Name string `json:"name"` - Target struct { - Date string `json:"committedDate"` - Tagger struct { - Date string `json:"date"` - } `json:"tagger"` - } `json:"target"` + Name string `json:"name"` + Target struct { + Date string `json:"committedDate"` + Tagger struct { + Date string `json:"date"` + } `json:"tagger"` + } `json:"target"` } `json:"nodes"` } `json:"refs"` } `json:"repository"` @@ -101,14 +101,14 @@ type RepoQueryResult struct { // Convert turns a RepoQueryResult into a Cuppa ResultSet func (rqr RepoQueryResult) Convert(name string) (rs *results.ResultSet) { rs = results.NewResultSet(name) - var err error + var err error for _, tag := range rqr.Data.Repository.Refs.Nodes { pre := false - found := false + found := false var published time.Time for _, node := range rqr.Data.Repository.Releases.Nodes { if node.Tag.Name == tag.Name { - found = true + found = true if node.IsPrerelease { pre = true } @@ -118,16 +118,16 @@ func (rqr RepoQueryResult) Convert(name string) (rs *results.ResultSet) { if pre { continue } - if !found { - if len(tag.Target.Date) > 0 { - published, _ = time.Parse(time.RFC3339, tag.Target.Date) - } else if len(tag.Target.Tagger.Date) > 0 { - published, err = time.Parse(time.RFC3339, tag.Target.Tagger.Date) - if err != nil { - published, _ = time.Parse("2006-01-02T15:04:05-07:00", tag.Target.Tagger.Date) - } - } - } + if !found { + if len(tag.Target.Date) > 0 { + published, _ = time.Parse(time.RFC3339, tag.Target.Date) + } else if len(tag.Target.Tagger.Date) > 0 { + published, err = time.Parse(time.RFC3339, tag.Target.Tagger.Date) + if err != nil { + published, _ = time.Parse("2006-01-02T15:04:05-07:00", tag.Target.Tagger.Date) + } + } + } r := results.NewResult(name, tag.Name, fmt.Sprintf(SourceFormat, name, tag.Name), published) rs.AddResult(r) } diff --git a/providers/kde/provider.go b/providers/kde/provider.go index 3805237..d6d9c02 100644 --- a/providers/kde/provider.go +++ b/providers/kde/provider.go @@ -34,12 +34,14 @@ const ( ListingURL = "https://download.kde.org/ls-lR.bz2" // ListingPrefix is the prefix of all paths in the KDE listing that is hidden by HTTP ListingPrefix = "/srv/archives/ftp/" + // SourceFormat3 is the string format for KDE sources with 3 pieces + SourceFormat3 = "https://download.kde.org/%s/%s/%s-%s.tar.xz" // SourceFormat4 is the string format for KDE sources with 4 pieces - SourceFormat4 = "https://download.kde.org/%s/%s/%s/%s-%s.tar.xz" + SourceFormat4 = "https://cdn.download.kde.org/%s/%s/%s/%s-%s.tar.xz" // SourceFormat5 is the string format for KDE sources with 5 pieces - SourceFormat5 = "https://download.kde.org/%s/%s/%s/%s/%s-%s.tar.xz" + SourceFormat5 = "https://cdn.download.kde.org/%s/%s/%s/%s/%s-%s.tar.xz" // SourceFormat6 is the string format for KDE sources with 6 pieces - SourceFormat6 = "https://download.kde.org/%s/%s/%s/%s/%s/%s-%s.tar.xz" + SourceFormat6 = "https://cdn.download.kde.org/%s/%s/%s/%s/%s/%s-%s.tar.xz" ) // TarballRegex matches KDE sources @@ -83,7 +85,7 @@ func (c Provider) Match(query string) string { return "" } pieces := strings.Split(sm[1], "/") - if len(pieces) < 4 || len(pieces) > 6 { + if len(pieces) < 3 || len(pieces) > 6 { return "" } return sm[1] @@ -105,6 +107,8 @@ func (c Provider) Releases(name string) (rs *results.ResultSet, s results.Status name = strings.Join(pieces2[0:len(pieces2)-1], "-") var searchPrefix string switch len(pieces) { + case 3: + searchPrefix = ListingPrefix + strings.Join(pieces[0:len(pieces)-1], "/") + ":\n" case 4: searchPrefix = ListingPrefix + strings.Join(pieces[0:len(pieces)-2], "/") + ":\n" case 5, 6: @@ -128,13 +132,26 @@ func (c Provider) Releases(name string) (rs *results.ResultSet, s results.Status break } fields := strings.Fields(line) - version := fields[len(fields)-1] - if version[0] > 57 || version[0] < 48 { + fd := fields[len(fields)-1] + parts := strings.Split(fd, "-") + last := parts[len(parts)-1] + parts = strings.Split(last, ".") + var vRaw []string + for _, p := range parts { + if p[0] > 57 || p[0] < 48 { + break + } + vRaw = append(vRaw, p) + } + version := strings.Join(vRaw, ".") + if len(version) == 0 || version[0] > 57 || version[0] < 48 { continue } updated, _ := time.Parse("2006-01-02 15:04", strings.Join(fields[len(fields)-3:len(fields)-2], " ")) var location string switch len(pieces) { + case 3: + location = fmt.Sprintf(SourceFormat3, pieces[0], version, name, version) case 4: location = fmt.Sprintf(SourceFormat4, pieces[0], pieces[1], version, name, version) case 5: