diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-10 12:21:40 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2014-07-10 12:21:40 +0000 |
commit | 4fddd77d7f8bdd97559b288c71860c814254fab1 (patch) | |
tree | dfe2f02f498a01e70c6c264c7776f2467c1a4e5d | |
parent | 10866da12f0896d7ddd0e562e0942a29a0f2f720 (diff) | |
download | upstream-monitor-4fddd77d7f8bdd97559b288c71860c814254fab1.tar.bz2 upstream-monitor-4fddd77d7f8bdd97559b288c71860c814254fab1.tar.xz |
github: new module for upstream provider
-rwxr-xr-x | aports-vercmp | 1 | ||||
-rw-r--r-- | upstream/github.lua | 78 |
2 files changed, 79 insertions, 0 deletions
diff --git a/aports-vercmp b/aports-vercmp index 5199fec..c5eefad 100755 --- a/aports-vercmp +++ b/aports-vercmp @@ -3,6 +3,7 @@ upstream_providers = { (require("upstream.gnome")), + (require("upstream.github")), (require("upstream.archlinux")), } diff --git a/upstream/github.lua b/upstream/github.lua new file mode 100644 index 0000000..f2bb16a --- /dev/null +++ b/upstream/github.lua @@ -0,0 +1,78 @@ + + +https = require("ssl.https") +json = require("cjson") +ml = require("ml") +apk = require("apk") + +local M = {} +--[[ +github api only lets us only do 60 requests per hour, and potensially +5000 if we register an application key. Instead of messing with oauth +we simply parse the html for now +local function find_newer(self) + local tagsurl = ("https://api.github.com/repos/%s/tags"):format(self.project) + print(("DEBUG: %s: github: %s"):format(self.pkg.pkgname, self.project)) + local jsondata, status = assert(https.request(tagsurl)) + local t + if jsondata then + t = json.decode(jsondata) + end + if status ~= 200 then + print(("github api error: %i\n url: %s\n message: %s\n doc: %s\n"):format(status, tagsurl, t.message, t.documentation_url)) + return nil + end + local latest = oldver or "0" + for k,v in pairs(t) do + print("DEBUG: github:", k, v.name) + if apk.version_compare(k, latest) == ">" then + latest = k + end + end + if latest == oldver then + latest = nil + end + return latest +end +]]-- + +local function find_newer(self) + local releasesurl = ("https://github.com/%s/releases"):format(self.project) + print(("DEBUG: %s: github: %s"):format(self.pkg.pkgname, self.project)) + local data, status = assert(https.request(releasesurl)) + local latest = self.pkg.pkgver + for v in string.gmatch(data, ('a href="/%s/archive/v?([0-9a-z._-]+)%%.tar.gz"'):format(self.project)) do + for _,s in pairs{ + {search="-rc", replace="_rc"}, + {search="-beta", replace="_beta"}, + {search="-alpha", replace="_alpha"}, + } do + v = string.gsub(v, s.search, s.replace) + end + if apk.version_compare(v, latest) == ">" then + latest = v + end + end + if latest == self.pkg.pkgver then + latest = nil + end + return latest +end + +function M.init(pkg) + for source in pkg:remote_sources() do + local project = string.match(source, + ".*::https://github.com/(.*)/archive/") + if project then + return { + provider_name = "github", + find_newer = find_newer, + pkg = pkg, + project = project, + } + end + end + return nil +end + +return M |