File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { debugFn } from '@socketsecurity/registry/lib/debug'
22import { getOwn } from '@socketsecurity/registry/lib/objects'
3+ import { parseUrl } from '@socketsecurity/registry/lib/url'
34
45import constants from '../../constants.mts'
56import { DiffAction } from './arborist/types.mts'
@@ -15,13 +16,10 @@ import type {
1516import type { Spinner } from '@socketsecurity/registry/lib/spinner'
1617
1718function getUrlOrigin ( input : string ) : string {
18- try {
19- // TODO: URL.parse is available in Node 22.1.0. We can use it when we drop Node 18.
20- // https://nodejs.org/docs/latest-v22.x/api/url.html#urlparseinput-base
21- // return URL.parse(input)?.origin ?? ''
22- return new URL ( input ) . origin ?? ''
23- } catch { }
24- return ''
19+ // TODO: URL.parse is available in Node 22.1.0. We can use it when we drop Node 18.
20+ // https://nodejs.org/docs/latest-v22.x/api/url.html#urlparseinput-base
21+ // return URL.parse(input)?.origin ?? ''
22+ return parseUrl ( input ) ?. origin ?? ''
2523}
2624
2725export type GetAlertsMapFromArboristOptions = {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
1414 writeJson ,
1515} from '@socketsecurity/registry/lib/fs'
1616import { spawn } from '@socketsecurity/registry/lib/spawn'
17+ import { parseUrl } from '@socketsecurity/registry/lib/url'
1718
1819import constants , { UNKNOWN_ERROR } from '../constants.mts'
1920
@@ -251,7 +252,14 @@ export async function setGitRemoteGithubRepoUrl(
251252 token : string ,
252253 cwd = process . cwd ( ) ,
253254) : Promise < boolean > {
254- const { host } = new URL ( constants . ENV . GITHUB_SERVER_URL )
255+ const { GITHUB_SERVER_URL } = constants . ENV
256+ const urlObj = parseUrl ( GITHUB_SERVER_URL )
257+ const host = urlObj ?. host
258+ if ( ! host ) {
259+ debugFn ( 'error' , 'invalid: GITHUB_SERVER_URL env var' )
260+ debugDir ( 'inspect' , { GITHUB_SERVER_URL } )
261+ return false
262+ }
255263 const url = `https://x-access-token:${ token } @${ host } /${ owner } /${ repo } `
256264 const stdioIgnoreOptions : SpawnOptions = {
257265 cwd,
You can’t perform that action at this time.
0 commit comments