From b5ee7f79b2d0e54209d714a5eca640d338e17ac6 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sun, 22 May 2016 19:45:57 +0300 Subject: write-rockspec: infer git and hg urls from local repos --- src/luarocks/write_rockspec.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index abfca322..9b6593b6 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -3,6 +3,7 @@ local write_rockspec = {} package.loaded["luarocks.write_rockspec"] = write_rockspec +local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") @@ -111,6 +112,32 @@ local function detect_mit_license(data) return sum == 78656 end +local simple_scm_protocols = { + git = true, ["git+http"] = true, ["git+https"] = true, + hg = true, ["hg+http"] = true, ["hg+https"] = true +} + +local function detect_url_from_command(program, args, directory) + local command = fs.Q(cfg.variables[program:upper()]).. " "..args + local pipe = io.popen(fs.command_at(directory, fs.quiet_stderr(command))) + if not pipe then return nil end + local url = pipe:read("*a"):match("^([^\r\n]+)") + pipe:close() + if not url then return nil end + if not util.starts_with(url, program.."://") then + url = program.."+"..url + end + + if simple_scm_protocols[dir.split_url(url)] then + return url + end +end + +local function detect_scm_url(directory) + return detect_url_from_command("git", "config --get remote.origin.url", directory) or + detect_url_from_command("hg", "paths default", directory) +end + local function show_license(rockspec) local fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt") if not fd then return nil end @@ -290,6 +317,8 @@ function write_rockspec.run(...) else local_dir = nil end + else + rockspec.source.url = detect_scm_url(local_dir) or rockspec.source.url end if not local_dir then -- cgit v1.2.3-55-g6feb From 24fa7d2c2c8f9032b66a290be0d2d2623c6904b4 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Mon, 23 May 2016 14:01:37 +0300 Subject: write-rockspec: improve homepage detection * Perform detection later to take into account URL inferred from local scm repo. * Support more protocols instead of just 'git://'. * Support Bitbucket and Gitlab in addition to Github. * Strip trailing '.git'. --- src/luarocks/write_rockspec.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 9b6593b6..213d1b01 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -266,10 +266,6 @@ function write_rockspec.run(...) version = version or "scm" local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") - - if not flags["homepage"] and url_or_dir:match("^git://github.com") then - flags["homepage"] = "http://"..url_or_dir:match("^[^:]+://(.*)") - end local rockspec = { rockspec_format = flags["rockspec-format"], @@ -324,6 +320,19 @@ function write_rockspec.run(...) if not local_dir then local_dir = "." end + + if not flags["homepage"] then + local url_protocol, url_path = dir.split_url(rockspec.source.url) + + if simple_scm_protocols[url_protocol] then + for _, domain in ipairs({"github.com", "bitbucket.org", "gitlab.com"}) do + if util.starts_with(url_path, domain) then + rockspec.description.homepage = "https://"..url_path:gsub("%.git$", "") + break + end + end + end + end local libs = nil if flags["lib"] then -- cgit v1.2.3-55-g6feb