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

Add support for debian.org #29

Merged
merged 1 commit into from
Oct 16, 2018
Merged
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
36 changes: 36 additions & 0 deletions upstream/debian.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package upstream

import (
"fmt"
"net/url"
"regexp"

"github.com/go-errors/errors"
)

type debianVersion struct {
Version string `json:"version"`
}

type debianResponse struct {
Versions []debianVersion `json:"versions"`
}

type debian string

func (d debian) releasesURL() string {
// API documentation: https://sources.debian.org/doc/api/
return fmt.Sprintf("https://sources.debian.org/api/src/%s/", url.PathEscape(string(d)))
}

func (d debian) latestVersion() (Version, error) {
var res debianResponse
if err := fetchJSON(d, &res); err != nil {
return "", errors.WrapPrefix(err, "No debian release found for "+string(d), 0)
}
match := regexp.MustCompile("([^-]+)[-|~]").FindStringSubmatch(res.Versions[0].Version)
if len(match) > 0 {
return Version(match[1]), nil
}
return Version(res.Versions[0].Version), nil
}
68 changes: 68 additions & 0 deletions upstream/debian_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package upstream

import (
"net/http"
"testing"

"github.com/h2non/gock"
"github.com/simon04/aur-out-of-date/pkg"
)

func mockDebian() *gock.Response {
return gock.New("https://sources.debian.org").
Get("/api/src/babeltrace/").
Reply(http.StatusOK).
SetHeader("Content-Type", "application/json").
BodyString(`
{
"package": "babeltrace",
"path": "babeltrace",
"pathl": [
[
"babeltrace",
"/src/babeltrace/"
]
],
"suite": "",
"type": "package",
"versions": [
{
"area": "main",
"suites": [
"buster",
"sid"
],
"version": "1.5.6-1"
},
{
"area": "main",
"suites": [
"stretch"
],
"version": "1.5.1-1"
},
{
"area": "main",
"suites": [
"jessie",
"jessie-kfreebsd"
],
"version": "1.2.3-2"
}
]
}`)
}

func TestDebianSource1(t *testing.T) {
defer gock.Off()
mockDebian()

p := pkg.New("babeltrace", "0", "", "http://debian.backend.mirrors.debian.org/debian/pool/main/b/babeltrace/python3-babeltrace_1.5.6-1_hurd-i386.deb")
version, err := VersionForPkg(p)
if err != nil {
t.Error(err)
}
if version != "1.5.6" {
t.Errorf("Expecting version 1.5.6, but got %v", version)
}
}
6 changes: 6 additions & 0 deletions upstream/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func forURL(url string) (Version, error) {
if len(match) > 0 {
return gitLab{match[1], match[2], match[3]}.latestVersion()
}
case strings.Contains(url, "debian.org"):
// Example: http://ftp.debian.org/debian/pool/main/p/python3-defaults/python3-defaults_3.6.6-1.tar.gz
match := regexp.MustCompile("/debian/pool/(?:contrib|main|non-free)/[a-z]{1,4}/([^/#.]+)/[^/#]+(?:.tar|.deb)").FindStringSubmatch(url)
if len(match) > 0 {
return debian(match[1]).latestVersion()
}
}
return "", errors.Errorf("No release found for %s", url)
}
Expand Down