1+ // biome-ignore-all lint/performance/useTopLevelRegex: Existing git URL parsing regexes are kept inline for readability.
12import { execFile } from "node:child_process" ;
23import { promisify } from "node:util" ;
34
@@ -11,13 +12,20 @@ export interface GitHubRepositoryReference {
1112 url : string ;
1213}
1314
14- export async function readGitOriginRemote ( cwd : string , signal ?: AbortSignal ) : Promise < string | null > {
15+ export async function readGitOriginRemote (
16+ cwd : string ,
17+ signal ?: AbortSignal ,
18+ ) : Promise < string | null > {
1519 try {
16- const { stdout } = await execFileAsync ( "git" , [ "config" , "--get" , "remote.origin.url" ] , {
17- cwd,
18- timeout : 5_000 ,
19- signal,
20- } ) ;
20+ const { stdout } = await execFileAsync (
21+ "git" ,
22+ [ "config" , "--get" , "remote.origin.url" ] ,
23+ {
24+ cwd,
25+ timeout : 5_000 ,
26+ signal,
27+ } ,
28+ ) ;
2129 const remote = stdout . trim ( ) ;
2230 return remote . length > 0 ? remote : null ;
2331 } catch ( error ) {
@@ -30,9 +38,13 @@ function isAbortError(error: unknown): boolean {
3038 return error instanceof Error && error . name === "AbortError" ;
3139}
3240
33- export function parseGitHubRepositoryUrl ( value : string ) : GitHubRepositoryReference | null {
41+ export function parseGitHubRepositoryUrl (
42+ value : string ,
43+ ) : GitHubRepositoryReference | null {
3444 const input = value . trim ( ) ;
35- const shorthand = input . match ( / ^ g i t @ g i t h u b \. c o m : ( [ ^ / \s ] + ) \/ ( [ ^ / \s ] + ?) (?: \. g i t ) ? $ / ) ;
45+ const shorthand = input . match (
46+ / ^ g i t @ g i t h u b \. c o m : ( [ ^ / \s ] + ) \/ ( [ ^ / \s ] + ?) (?: \. g i t ) ? $ / ,
47+ ) ;
3648
3749 if ( shorthand ) {
3850 return toGitHubRepositoryReference ( shorthand [ 1 ] , shorthand [ 2 ] ) ;
@@ -49,7 +61,11 @@ export function parseGitHubRepositoryUrl(value: string): GitHubRepositoryReferen
4961 return null ;
5062 }
5163
52- if ( parsed . protocol !== "https:" && parsed . protocol !== "http:" && parsed . protocol !== "ssh:" ) {
64+ if (
65+ parsed . protocol !== "https:" &&
66+ parsed . protocol !== "http:" &&
67+ parsed . protocol !== "ssh:"
68+ ) {
5369 return null ;
5470 }
5571
@@ -64,7 +80,10 @@ export function parseGitHubRepositoryUrl(value: string): GitHubRepositoryReferen
6480 return toGitHubRepositoryReference ( owner , name ) ;
6581}
6682
67- function toGitHubRepositoryReference ( owner : string | undefined , name : string | undefined ) : GitHubRepositoryReference | null {
83+ function toGitHubRepositoryReference (
84+ owner : string | undefined ,
85+ name : string | undefined ,
86+ ) : GitHubRepositoryReference | null {
6887 if ( ! owner || ! name || owner . includes ( "/" ) || name . includes ( "/" ) ) {
6988 return null ;
7089 }
0 commit comments