kopia lustrzana https://github.com/c9/core
61 wiersze
1.7 KiB
JavaScript
61 wiersze
1.7 KiB
JavaScript
define(function(require, exports, module) {
|
|
"use strict";
|
|
|
|
var Url = require("url");
|
|
|
|
var providers = {
|
|
"bitbucket.org": "bitbucket",
|
|
"github.com": "github"
|
|
};
|
|
var defaultProvider = "unknown";
|
|
|
|
module.exports = function(url) {
|
|
var m = url.match(/^(git)@([\w\.\d\-\_]+)(?:\/|:)([\w\.\d\-\_\/]+)/);
|
|
if (m) {
|
|
return {
|
|
protocol: "ssh:",
|
|
scm: "git",
|
|
provider: providers[m[2]] || defaultProvider,
|
|
auth: m[1],
|
|
hostname: m[2],
|
|
pathname: m[3]
|
|
};
|
|
}
|
|
|
|
var parsed = Url.parse(url);
|
|
|
|
if (
|
|
parsed &&
|
|
parsed.protocol &&
|
|
parsed.protocol.match(/^(git|http|https|ssh):$/) &&
|
|
parsed.hostname &&
|
|
parsed.slashes &&
|
|
parsed.pathname
|
|
) {
|
|
var scm;
|
|
var provider = providers[parsed.hostname] || defaultProvider;
|
|
switch (provider) {
|
|
case "github":
|
|
scm = "git";
|
|
break;
|
|
case "bitbucket":
|
|
scm = parsed.pathname.match(/\.git$/) ? "git": "hg";
|
|
break;
|
|
default:
|
|
scm = parsed.pathname.match(/\.git$/) ? "git": "hg";
|
|
}
|
|
return {
|
|
protocol: parsed.protocol,
|
|
scm: scm,
|
|
provider: provider,
|
|
auth: parsed.auth || "",
|
|
hostname: parsed.hostname,
|
|
pathname: parsed.pathname.replace(/^\/+/, ""),
|
|
full: url
|
|
};
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
};
|
|
}); |