From 8290da49e02a30ec14b7777fb304f094f9a99b11 Mon Sep 17 00:00:00 2001 From: "Joao Mauricio de O. Alves" Date: Wed, 13 Jul 2022 11:00:13 -0300 Subject: [PATCH] GIT - Support for https url for user and repo info - Fix #149 --- src/lib/utils/git_utils.test.ts | 50 +++++++++++++++++++++++++++++---- src/lib/utils/git_utils.ts | 2 +- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/lib/utils/git_utils.test.ts b/src/lib/utils/git_utils.test.ts index dbbca73f..ec14a866 100644 --- a/src/lib/utils/git_utils.test.ts +++ b/src/lib/utils/git_utils.test.ts @@ -3,7 +3,7 @@ import { assertEquals, assertMatch, assertThrows, - assertThrowsAsync + assertRejects } from "https://deno.land/std/testing/asserts.ts"; import GitUtils from "./git_utils.ts"; @@ -63,6 +63,46 @@ Deno.test(`GitUtils - parseGitPath('git@gitlab.bndes.net:sist-pme/pme.git#develo assertEquals(gitPath.repo, 'pme') }) +Deno.test(`GitUtils - parseGitPath('git@gitlab.bndes.net:sist-pme/pme.git')`, () => { + let gitPath = GitUtils.parseGitPath('git@gitlab.bndes.net:sist-pme/pme.git') + assertEquals(gitPath.url, 'git@gitlab.bndes.net:sist-pme/pme.git') + assertEquals(gitPath.branch, undefined) + assertEquals(gitPath.user, 'sist-pme') + assertEquals(gitPath.repo, 'pme') +}) + +Deno.test(`GitUtils - parseGitPath('https://github.com/jmoalves/levain.git#develop')`, () => { + let gitPath = GitUtils.parseGitPath('https://github.com/jmoalves/levain.git#develop') + assertEquals(gitPath.url, 'https://github.com/jmoalves/levain.git') + assertEquals(gitPath.branch, 'develop') + assertEquals(gitPath.user, 'jmoalves') + assertEquals(gitPath.repo, 'levain') +}) + +Deno.test(`GitUtils - parseGitPath('https://github.com/jmoalves/levain.git')`, () => { + let gitPath = GitUtils.parseGitPath('https://github.com/jmoalves/levain.git') + assertEquals(gitPath.url, 'https://github.com/jmoalves/levain.git') + assertEquals(gitPath.branch, undefined) + assertEquals(gitPath.user, 'jmoalves') + assertEquals(gitPath.repo, 'levain') +}) + +Deno.test(`GitUtils - parseGitPath('https://gitlab.bndes.net/sist-pme/pme.git#develop')`, () => { + let gitPath = GitUtils.parseGitPath('https://gitlab.bndes.net/sist-pme/pme.git#develop') + assertEquals(gitPath.url, 'https://gitlab.bndes.net/sist-pme/pme.git') + assertEquals(gitPath.branch, 'develop') + assertEquals(gitPath.user, 'sist-pme') + assertEquals(gitPath.repo, 'pme') +}) + +Deno.test(`GitUtils - parseGitPath('https://gitlab.bndes.net/sist-pme/pme.git')`, () => { + let gitPath = GitUtils.parseGitPath('https://gitlab.bndes.net/sist-pme/pme.git') + assertEquals(gitPath.url, 'https://gitlab.bndes.net/sist-pme/pme.git') + assertEquals(gitPath.branch, undefined) + assertEquals(gitPath.user, 'sist-pme') + assertEquals(gitPath.repo, 'pme') +}) + Deno.test(`GitUtils - localBaseDir()`, () => { assertEquals(GitUtils.localBaseDir('git@github.com:jmoalves/levain.git'), 'git_github.com_jmoalves_levain') assertEquals(GitUtils.localBaseDir('git@github.com:jmoalves/levain.git#develop'), 'git_github.com_jmoalves_levain_develop') @@ -87,7 +127,7 @@ Deno.test('GitUtils.localBaseDir should throw error if url is invalid', () => { }) Deno.test('GitUtils.clone should throw error if url is invalid', async () => { - await assertThrowsAsync( + await assertRejects( async () => { await new GitUtils().clone('thisSourceDoesNotExist', 'thisDstDoesNotExist') }, @@ -112,7 +152,7 @@ Deno.test('GitUtils.localBaseDir should throw error if url is invalid', () => { ) }) Deno.test('GitUtils.clone should throw error if url is invalid', async () => { - await assertThrowsAsync( + await assertRejects( async () => { await new GitUtils().clone('thisSourceDoesNotExist', 'thisDstDoesNotExist') }, @@ -137,7 +177,7 @@ Deno.test('GitUtils.localBaseDir should throw error if url is invalid', () => { ) }) Deno.test('GitUtils.clone should throw error if url is invalid', async () => { - await assertThrowsAsync( + await assertRejects( async () => { await new GitUtils().clone('thisSourceDoesNotExist', 'thisDstDoesNotExist') }, @@ -175,7 +215,7 @@ Deno.test({ const folder = TestHelper.folderThatAlwaysExists const gitUtils = new GitUtils() - await assertThrowsAsync( + await assertRejects( async () => { await gitUtils.pull(folder) }, diff --git a/src/lib/utils/git_utils.ts b/src/lib/utils/git_utils.ts index 8e541a2c..e16574b9 100644 --- a/src/lib/utils/git_utils.ts +++ b/src/lib/utils/git_utils.ts @@ -9,7 +9,7 @@ import ConsoleFeedback from "./console_feedback.ts"; export default class GitUtils { static readonly GIT_REG_EXP = /(?.*\.git)(:?#(?.+))?$/ - static readonly GITHUB_REG_EXP = /^git@.*:(?[^/]+)\/(?[^.]+)\.git$/ + static readonly GITHUB_REG_EXP = /^(git@.*:|https:\/\/.*\/)(?[^/]+)\/(?[^.]+)\.git$/ readonly gitCmd: string;