forked from daren.hsu/line_push
update
This commit is contained in:
+67
-7
@@ -131,16 +131,26 @@ function gitUrlParse(url) {
|
||||
urlInfo.name = splits[3];
|
||||
urlInfo.full_name = urlInfo.organization + '/' + urlInfo.owner + '/_git/' + urlInfo.name;
|
||||
}
|
||||
if (urlInfo.query && urlInfo.query['path']) {
|
||||
urlInfo.filepath = urlInfo.query['path'].replace(/^\/+/g, ''); // Strip leading slash (/)
|
||||
}
|
||||
if (urlInfo.query && urlInfo.query['version']) {
|
||||
// version=GB<branch>
|
||||
urlInfo.ref = urlInfo.query['version'].replace(/^GB/, ''); // remove GB
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
splits = urlInfo.name.split("/");
|
||||
var nameIndex = splits.length - 1;
|
||||
if (splits.length >= 2) {
|
||||
var dashIndex = splits.indexOf("-", 2);
|
||||
var blobIndex = splits.indexOf("blob", 2);
|
||||
var treeIndex = splits.indexOf("tree", 2);
|
||||
var commitIndex = splits.indexOf("commit", 2);
|
||||
nameIndex = blobIndex > 0 ? blobIndex - 1 : treeIndex > 0 ? treeIndex - 1 : commitIndex > 0 ? commitIndex - 1 : nameIndex;
|
||||
var srcIndex = splits.indexOf("src", 2);
|
||||
var rawIndex = splits.indexOf("raw", 2);
|
||||
nameIndex = dashIndex > 0 ? dashIndex - 1 : blobIndex > 0 ? blobIndex - 1 : treeIndex > 0 ? treeIndex - 1 : commitIndex > 0 ? commitIndex - 1 : srcIndex > 0 ? srcIndex - 1 : rawIndex > 0 ? rawIndex - 1 : nameIndex;
|
||||
|
||||
urlInfo.owner = splits.slice(0, nameIndex).join('/');
|
||||
urlInfo.name = splits[nameIndex];
|
||||
@@ -152,11 +162,12 @@ function gitUrlParse(url) {
|
||||
urlInfo.ref = "";
|
||||
urlInfo.filepathtype = "";
|
||||
urlInfo.filepath = "";
|
||||
if (splits.length > nameIndex + 2 && ["blob", "tree"].indexOf(splits[nameIndex + 1]) >= 0) {
|
||||
urlInfo.filepathtype = splits[nameIndex + 1];
|
||||
urlInfo.ref = splits[nameIndex + 2];
|
||||
if (splits.length > nameIndex + 3) {
|
||||
urlInfo.filepath = splits.slice(nameIndex + 3).join('/');
|
||||
var offsetNameIndex = splits.length > nameIndex && splits[nameIndex + 1] === "-" ? nameIndex + 1 : nameIndex;
|
||||
if (splits.length > offsetNameIndex + 2 && ["raw", "src", "blob", "tree"].indexOf(splits[offsetNameIndex + 1]) >= 0) {
|
||||
urlInfo.filepathtype = splits[offsetNameIndex + 1];
|
||||
urlInfo.ref = splits[offsetNameIndex + 2];
|
||||
if (splits.length > offsetNameIndex + 3) {
|
||||
urlInfo.filepath = splits.slice(offsetNameIndex + 3).join('/');
|
||||
}
|
||||
}
|
||||
urlInfo.organization = urlInfo.owner;
|
||||
@@ -170,7 +181,46 @@ function gitUrlParse(url) {
|
||||
urlInfo.full_name += urlInfo.name;
|
||||
}
|
||||
}
|
||||
// Bitbucket Server
|
||||
if (urlInfo.owner.startsWith("scm/")) {
|
||||
urlInfo.source = "bitbucket-server";
|
||||
urlInfo.owner = urlInfo.owner.replace("scm/", "");
|
||||
urlInfo.organization = urlInfo.owner;
|
||||
urlInfo.full_name = urlInfo.owner + "/" + urlInfo.name;
|
||||
}
|
||||
|
||||
var bitbucket = /(projects|users)\/(.*?)\/repos\/(.*?)((\/.*$)|$)/;
|
||||
var matches = bitbucket.exec(urlInfo.pathname);
|
||||
if (matches != null) {
|
||||
urlInfo.source = "bitbucket-server";
|
||||
if (matches[1] === "users") {
|
||||
urlInfo.owner = "~" + matches[2];
|
||||
} else {
|
||||
urlInfo.owner = matches[2];
|
||||
}
|
||||
|
||||
urlInfo.organization = urlInfo.owner;
|
||||
urlInfo.name = matches[3];
|
||||
|
||||
splits = matches[4].split("/");
|
||||
if (splits.length > 1) {
|
||||
if (["raw", "browse"].indexOf(splits[1]) >= 0) {
|
||||
urlInfo.filepathtype = splits[1];
|
||||
if (splits.length > 2) {
|
||||
urlInfo.filepath = splits.slice(2).join('/');
|
||||
}
|
||||
} else if (splits[1] === "commits" && splits.length > 2) {
|
||||
urlInfo.commit = splits[2];
|
||||
}
|
||||
}
|
||||
urlInfo.full_name = urlInfo.owner + "/" + urlInfo.name;
|
||||
|
||||
if (urlInfo.query.at) {
|
||||
urlInfo.ref = urlInfo.query.at;
|
||||
} else {
|
||||
urlInfo.ref = "";
|
||||
}
|
||||
}
|
||||
return urlInfo;
|
||||
}
|
||||
|
||||
@@ -200,7 +250,7 @@ gitUrlParse.stringify = function (obj, type) {
|
||||
case "http":
|
||||
case "https":
|
||||
var auth = obj.token ? buildToken(obj) : obj.user && (obj.protocols.includes('http') || obj.protocols.includes('https')) ? obj.user + "@" : "";
|
||||
return type + "://" + auth + obj.resource + port + "/" + obj.full_name + maybeGitSuffix;
|
||||
return type + "://" + auth + obj.resource + port + "/" + buildPath(obj) + maybeGitSuffix;
|
||||
default:
|
||||
return obj.href;
|
||||
}
|
||||
@@ -224,4 +274,14 @@ function buildToken(obj) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildPath(obj) {
|
||||
switch (obj.source) {
|
||||
case "bitbucket-server":
|
||||
return "scm/" + obj.full_name;
|
||||
default:
|
||||
return "" + obj.full_name;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = gitUrlParse;
|
||||
Reference in New Issue
Block a user