Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cdn url to have a more stable download source #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions providers/git/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
40 changes: 20 additions & 20 deletions providers/github/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down
29 changes: 23 additions & 6 deletions providers/kde/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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:
Expand Down