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

INS-2633: fix self-hosted git url compatibility #5968

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/insomnia/src/ui/routes/git-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ type CloneGitActionResult = Response | {
errors?: string[];
};

export function parseGitToHttpsURL(s: string) {
// try to convert any git URL to https URL
let parsed = fromUrl(s)?.https() || '';

// fallback for self-hosted git servers, see https://github.com/Kong/insomnia/issues/5967
// and https://github.com/npm/hosted-git-info/issues/11
if (parsed === '') {
let temp = s;
// handle "shorter scp-like syntax"
temp = temp.replace(/^git@([^:]+):/, 'https://$1/');
// handle proper SSH URLs
temp = temp.replace(/^ssh:\/\//, 'https://');

// final URL fallback for any other git URL
temp = new URL(temp).href;
parsed = temp;
}

return parsed;
}

export const cloneGitRepoAction: ActionFunction = async ({
request,
params,
Expand Down Expand Up @@ -324,7 +345,7 @@ export const cloneGitRepoAction: ActionFunction = async ({
vcsSegmentEventProperties('git', 'clone')
);
repoSettingsPatch.needsFullClone = true;
repoSettingsPatch.uri = fromUrl(repoSettingsPatch.uri)?.https() || '';
repoSettingsPatch.uri = parseGitToHttpsURL(repoSettingsPatch.uri);
let fsClient = MemClient.createClient();

const providerName = getOauth2FormatName(repoSettingsPatch.credentials);
Expand Down