Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom SSH username #60

Merged
merged 2 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions dist/index.js
Expand Up @@ -43,7 +43,7 @@ var normalizeUrl__default = /*#__PURE__*/_interopDefaultLegacy(normalizeUrl);
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;
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 @@ -72,14 +72,15 @@ const parseUrl = (url, normalize = false) => {

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[4];
parsed.host = matched[4];
parsed.user = "git";
parsed.pathname = `/${matched[6]}`;
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
13 changes: 7 additions & 6 deletions dist/index.mjs
Expand Up @@ -36,7 +36,7 @@ import normalizeUrl from 'normalize-url';
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/;
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 @@ -65,14 +65,15 @@ const parseUrl = (url, normalize = false) => {

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[4];
parsed.host = matched[4];
parsed.user = "git";
parsed.pathname = `/${matched[6]}`;
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
13 changes: 7 additions & 6 deletions src/index.js
Expand Up @@ -35,7 +35,7 @@ import normalizeUrl from "normalize-url";
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/
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 @@ -64,14 +64,15 @@ const parseUrl = (url, normalize = false) => {

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE)
const matched = parsed.href.match(GIT_RE)

if (matched) {
parsed.protocols = ["ssh"]
parsed.protocol = "ssh"
parsed.resource = matched[4]
parsed.host = matched[4]
parsed.user = "git"
parsed.pathname = `/${matched[6]}`
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
Expand Up @@ -133,6 +133,23 @@ const INPUTS = [
, parse_failed: false
}
]
, [
["org-12345678@github.my-enterprise.com: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
}
]
, [
["git@github.com:halup/Cloud.API.Gateway.git", false]
, {
Expand Down