Skip to content

Commit

Permalink
GIT - Support for https url for user and repo info - Fix #149
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaur-bndes committed Jul 13, 2022
1 parent 147ee6b commit 8290da4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
50 changes: 45 additions & 5 deletions src/lib/utils/git_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
assertEquals,
assertMatch,
assertThrows,
assertThrowsAsync
assertRejects
} from "https://deno.land/std/testing/asserts.ts";

import GitUtils from "./git_utils.ts";
Expand Down Expand Up @@ -63,6 +63,46 @@ Deno.test(`GitUtils - parseGitPath('[email protected]:sist-pme/pme.git#develo
assertEquals(gitPath.repo, 'pme')
})

Deno.test(`GitUtils - parseGitPath('[email protected]:sist-pme/pme.git')`, () => {
let gitPath = GitUtils.parseGitPath('[email protected]:sist-pme/pme.git')
assertEquals(gitPath.url, '[email protected]: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('[email protected]:jmoalves/levain.git'), 'git_github.com_jmoalves_levain')
assertEquals(GitUtils.localBaseDir('[email protected]:jmoalves/levain.git#develop'), 'git_github.com_jmoalves_levain_develop')
Expand All @@ -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')
},
Expand All @@ -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')
},
Expand All @@ -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')
},
Expand Down Expand Up @@ -175,7 +215,7 @@ Deno.test({
const folder = TestHelper.folderThatAlwaysExists
const gitUtils = new GitUtils()

await assertThrowsAsync(
await assertRejects(
async () => {
await gitUtils.pull(folder)
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/git_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ConsoleFeedback from "./console_feedback.ts";

export default class GitUtils {
static readonly GIT_REG_EXP = /(?<url>.*\.git)(:?#(?<branch>.+))?$/
static readonly GITHUB_REG_EXP = /^git@.*:(?<user>[^/]+)\/(?<repo>[^.]+)\.git$/
static readonly GITHUB_REG_EXP = /^(git@.*:|https:\/\/.*\/)(?<user>[^/]+)\/(?<repo>[^.]+)\.git$/

readonly gitCmd: string;

Expand Down

0 comments on commit 8290da4

Please sign in to comment.