@geut/git-url-parse
Advanced tools
Comparing version 3.0.2 to 3.0.3
{ | ||
"name": "@geut/git-url-parse", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Function to parse a git url and generates template url for the git compare preview.", | ||
@@ -36,3 +36,3 @@ "type": "module", | ||
}, | ||
"gitHead": "af64612aa7afc8f5fe735a9d46f18727998d23a9" | ||
"gitHead": "401a8bfc1f4cfbe0df0e63df9dec43b11ae6dfef" | ||
} |
@@ -10,16 +10,20 @@ import { promisify } from 'util' | ||
github: { | ||
template: 'https://github.com/[full_name]/compare/[prev]...[next]', | ||
releaseTemplate: 'https://github.com/[full_name]/releases/tags/[next]', | ||
compareTemplate: 'https://github.com/[full_name]/compare/[prev]...[next]', | ||
branch: 'HEAD' | ||
}, | ||
bitbucket: { | ||
template: 'https://bitbucket.org/[full_name]/branches/compare/[prev]%0D[next]#diff', | ||
releaseTemplate: 'https://github.com/[full_name]/commits/tag/[next]', | ||
compareTemplate: 'https://bitbucket.org/[full_name]/branches/compare/[prev]%0D[next]#diff', | ||
branch: 'HEAD' | ||
}, | ||
gitlab: { | ||
template: 'https://gitlab.com/[full_name]/compare?from=[prev]&to=[next]', | ||
branch: 'master' | ||
releaseTemplate: 'https://github.com/[full_name]/-/tags/[next]', | ||
compareTemplate: 'https://gitlab.com/[full_name]/compare?from=[prev]&to=[next]', | ||
branch: 'main' | ||
} | ||
} | ||
export async function gitUrlParse ({ url }) { | ||
export async function gitUrlParse ({ url, cwd }) { | ||
let result | ||
@@ -30,3 +34,3 @@ | ||
} else { | ||
const path = findUp.sync('.git', { type: 'directory', cwd: process.cwd() }) | ||
const path = findUp.sync('.git', { type: 'directory', cwd: cwd || process.cwd() }) | ||
@@ -46,9 +50,12 @@ if (!path) { | ||
let { template, branch } = providers[Object.keys(providers).find(p => result.source.includes(p))] | ||
template = template.replace('[full_name]', result.full_name) | ||
const { releaseTemplate, compareTemplate, branch } = providers[Object.keys(providers).find(p => result.source.includes(p))] | ||
result.template = template | ||
result.branch = branch | ||
return result | ||
return Object.assign( | ||
result, | ||
{ | ||
branch, | ||
releaseTemplate: releaseTemplate.replace('[full_name]', result.full_name), | ||
compareTemplate: compareTemplate.replace('[full_name]', result.full_name) | ||
} | ||
) | ||
} |
3627
47