1- import URL from 'node:url' ;
21import { setTimeout } from 'timers/promises' ;
32import is from '@sindresorhus/is' ;
43import pMap from 'p-map' ;
54import semver from 'semver' ;
65import {
7- CONFIG_GIT_URL_UNAVAILABLE ,
86 REPOSITORY_ACCESS_FORBIDDEN ,
97 REPOSITORY_ARCHIVED ,
108 REPOSITORY_CHANGED ,
@@ -20,7 +18,6 @@ import { coerceArray } from '../../../util/array';
2018import { noLeadingAtSymbol , parseJson } from '../../../util/common' ;
2119import { getEnv } from '../../../util/env' ;
2220import * as git from '../../../util/git' ;
23- import * as hostRules from '../../../util/host-rules' ;
2421import { memCacheProvider } from '../../../util/http/cache/memory-http-cache-provider' ;
2522import type { GitlabHttpOptions } from '../../../util/http/gitlab' ;
2623import { setBaseUrl } from '../../../util/http/gitlab' ;
@@ -29,11 +26,7 @@ import { parseInteger } from '../../../util/number';
2926import * as p from '../../../util/promises' ;
3027import { regEx } from '../../../util/regex' ;
3128import { sanitize } from '../../../util/sanitize' ;
32- import {
33- ensureTrailingSlash ,
34- getQueryString ,
35- parseUrl ,
36- } from '../../../util/url' ;
29+ import { ensureTrailingSlash , getQueryString } from '../../../util/url' ;
3730import type {
3831 AutodiscoverConfig ,
3932 BranchStatusConfig ,
@@ -42,7 +35,6 @@ import type {
4235 EnsureCommentRemovalConfig ,
4336 EnsureIssueConfig ,
4437 FindPRConfig ,
45- GitUrlOption ,
4638 Issue ,
4739 MergePRConfig ,
4840 PlatformParams ,
@@ -74,7 +66,13 @@ import type {
7466 MergeMethod ,
7567 RepoResponse ,
7668} from './types' ;
77- import { DRAFT_PREFIX , DRAFT_PREFIX_DEPRECATED , prInfo } from './utils' ;
69+ import {
70+ DRAFT_PREFIX ,
71+ DRAFT_PREFIX_DEPRECATED ,
72+ defaults ,
73+ getRepoUrl ,
74+ prInfo ,
75+ } from './utils' ;
7876export { extractRulesFromCodeOwnersLines } from './code-owners' ;
7977
8078let config : {
@@ -99,12 +97,6 @@ export function resetPlatform(): void {
9997 setBaseUrl ( defaults . endpoint ) ;
10098}
10199
102- const defaults = {
103- hostType : 'gitlab' ,
104- endpoint : 'https://gitlab.com/api/v4/' ,
105- version : '0.0.0' ,
106- } ;
107-
108100export const id = 'gitlab' ;
109101
110102let draftPrefix = DRAFT_PREFIX ;
@@ -264,62 +256,6 @@ export async function getJsonFile(
264256 return parseJson ( raw , fileName ) ;
265257}
266258
267- function getRepoUrl (
268- repository : string ,
269- gitUrl : GitUrlOption | undefined ,
270- res : HttpResponse < RepoResponse > ,
271- ) : string {
272- if ( gitUrl === 'ssh' ) {
273- if ( ! res . body . ssh_url_to_repo ) {
274- throw new Error ( CONFIG_GIT_URL_UNAVAILABLE ) ;
275- }
276- logger . debug ( `Using ssh URL: ${ res . body . ssh_url_to_repo } ` ) ;
277- return res . body . ssh_url_to_repo ;
278- }
279-
280- const opts = hostRules . find ( {
281- hostType : defaults . hostType ,
282- url : defaults . endpoint ,
283- } ) ;
284- const env = getEnv ( ) ;
285-
286- if (
287- gitUrl === 'endpoint' ||
288- is . nonEmptyString ( env . GITLAB_IGNORE_REPO_URL ) ||
289- res . body . http_url_to_repo === null
290- ) {
291- if ( res . body . http_url_to_repo === null ) {
292- logger . debug ( 'no http_url_to_repo found. Falling back to old behavior.' ) ;
293- }
294- if ( env . GITLAB_IGNORE_REPO_URL ) {
295- logger . warn (
296- 'GITLAB_IGNORE_REPO_URL environment variable is deprecated. Please use "gitUrl" option.' ,
297- ) ;
298- }
299-
300- // TODO: null check (#22198)
301- const { protocol, host, pathname } = parseUrl ( defaults . endpoint ) ! ;
302- const newPathname = pathname . slice ( 0 , pathname . indexOf ( '/api' ) ) ;
303- const url = URL . format ( {
304- protocol :
305- /* v8 ignore next: should never happen */
306- protocol . slice ( 0 , - 1 ) || 'https' ,
307- // TODO: types (#22198)
308- auth : `oauth2:${ opts . token ! } ` ,
309- host,
310- pathname : `${ newPathname } /${ repository } .git` ,
311- } ) ;
312- logger . debug ( `Using URL based on configured endpoint, url:${ url } ` ) ;
313- return url ;
314- }
315-
316- logger . debug ( `Using http URL: ${ res . body . http_url_to_repo } ` ) ;
317- const repoUrl = URL . parse ( `${ res . body . http_url_to_repo } ` ) ;
318- // TODO: types (#22198)
319- repoUrl . auth = `oauth2:${ opts . token ! } ` ;
320- return URL . format ( repoUrl ) ;
321- }
322-
323259// Initialize GitLab by getting base branch
324260export async function initRepo ( {
325261 repository,
0 commit comments