Skip to content

Commit

Permalink
feat: support custom user in ssh url
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Aug 3, 2022
1 parent 881ecb4 commit 9500430
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var normalizeUrl__default = /*#__PURE__*/_interopDefaultLegacy(normalizeUrl);
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;

const throwErr = msg => {
const err = new Error(msg);
Expand Down Expand Up @@ -77,10 +77,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[1];
parsed.host = matched[1];
parsed.user = "git";
parsed.pathname = `/${matched[2]}`;
parsed.resource = matched[2];
parsed.host = matched[2];
parsed.user = matched[1];
parsed.pathname = `/${matched[3]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
Expand Down
10 changes: 5 additions & 5 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import normalizeUrl from 'normalize-url';
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;

const throwErr = msg => {
const err = new Error(msg);
Expand Down Expand Up @@ -70,10 +70,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[1];
parsed.host = matched[1];
parsed.user = "git";
parsed.pathname = `/${matched[2]}`;
parsed.resource = matched[2];
parsed.host = matched[2];
parsed.user = matched[1];
parsed.pathname = `/${matched[3]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import normalizeUrl from "normalize-url";
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/

const throwErr = msg => {
const err = new Error(msg)
Expand Down Expand Up @@ -69,10 +69,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"]
parsed.protocol = "ssh"
parsed.resource = matched[1]
parsed.host = matched[1]
parsed.user = "git"
parsed.pathname = `/${matched[2]}`
parsed.resource = matched[2]
parsed.host = matched[2]
parsed.user = matched[1]
parsed.pathname = `/${matched[3]}`
parsed.parse_failed = false
} else {
throwErr("URL parsing failed.")
Expand Down
17 changes: 17 additions & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ const INPUTS = [
, parse_failed: false
}
]
, [
["[email protected]:my-org/my-repo.git", false],
{
protocols: [ 'ssh' ]
, protocol: 'ssh'
, port: ''
, resource: 'github.my-enterprise.com'
, host: 'github.my-enterprise.com'
, user: 'org-12345678'
, password: ''
, pathname: '/my-org/my-repo.git'
, hash: ''
, search: ''
, query: {}
, parse_failed: false
}
]
, [
["[email protected]:halup/Cloud.API.Gateway.git", false]
, {
Expand Down

0 comments on commit 9500430

Please sign in to comment.