renovate 44.164.3 → 44.164.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/util/git/auth.js
CHANGED
|
@@ -55,6 +55,7 @@ function getAuthenticationRules(gitUrl, hostType, token) {
|
|
|
55
55
|
if (!sshPort || isEmptyString(sshPort)) sshPort = "7999";
|
|
56
56
|
}
|
|
57
57
|
const url = { ...insteadUrl };
|
|
58
|
+
if (hasUser && url.source === "bitbucket.org") url.source = "bitbucket";
|
|
58
59
|
const protocol = regEx(/^https?$/).test(url.protocol) ? url.protocol : "https";
|
|
59
60
|
url.token = hasUser ? token : `ssh:${token}`;
|
|
60
61
|
authenticationRules.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","names":[],"sources":["../../../lib/util/git/auth.ts"],"sourcesContent":["import { isEmptyString } from '@sindresorhus/is';\nimport { PLATFORM_HOST_TYPES } from '../../constants/platforms.ts';\nimport { logger } from '../../logger/index.ts';\nimport type { HostRule } from '../../types/index.ts';\nimport { detectPlatform } from '../common.ts';\nimport type { ResolvedChildEnv } from '../exec/utils.ts';\nimport { find, getAll } from '../host-rules.ts';\nimport { regEx } from '../regex.ts';\nimport { createURLFromHostOrURL, isHttpUrl } from '../url.ts';\nimport { addGitConfigEnvironmentVariables } from './config.ts';\nimport type { AuthenticationRule } from './types.ts';\nimport { getTokenCredentials, parseGitUrl } from './url.ts';\n\nconst platformHostTypes = new Set<string>(PLATFORM_HOST_TYPES);\n\nconst githubApiUrls = new Set([\n 'github.com',\n 'api.github.com',\n 'https://api.github.com',\n 'https://api.github.com/',\n]);\n\n/**\n * Append Git authentication configuration to a resolved child environment.\n * @returns a new environment without modifying the input\n */\nexport function getGitAuthenticatedEnvironmentVariables(\n environmentVariables: Readonly<ResolvedChildEnv>,\n originalGitUrl: string,\n { token, username, password, hostType, matchHost }: HostRule,\n): ResolvedChildEnv {\n if (!token && !(username && password)) {\n logger.warn(\n { host: matchHost },\n `Could not create environment variable for host as neither token or username and password was set`,\n );\n return { ...environmentVariables };\n }\n\n let authenticationRules: AuthenticationRule[];\n if (token) {\n authenticationRules = getAuthenticationRulesWithToken(\n originalGitUrl,\n hostType,\n token,\n );\n } else {\n const encodedUsername = encodeURIComponent(username!);\n const encodedPassword = encodeURIComponent(password!);\n\n authenticationRules = getAuthenticationRules(\n originalGitUrl,\n hostType,\n `${encodedUsername}:${encodedPassword}`,\n );\n }\n\n return addGitConfigEnvironmentVariables(\n environmentVariables,\n authenticationRules.map((rule) => ({\n key: `url.${rule.url}.insteadOf`,\n value: rule.insteadOf,\n })),\n );\n}\n\nfunction getAuthenticationRulesWithToken(\n url: string,\n hostType: string | undefined | null,\n authToken: string,\n): AuthenticationRule[] {\n const type = hostType ?? detectPlatform(url);\n const platform =\n hostType && platformHostTypes.has(hostType)\n ? hostType\n : detectPlatform(url);\n return getAuthenticationRules(\n url,\n type,\n getTokenCredentials(platform, authToken),\n );\n}\n\n/**\n * Generates the authentication rules for later git usage for the given host\n * @link https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/\n * @param gitUrl Git repository URL\n * @param hostType Git host type\n * @param token Authentication token or `username:password` string\n */\nexport function getAuthenticationRules(\n gitUrl: string,\n hostType: string | undefined | null,\n token: string,\n): AuthenticationRule[] {\n const authenticationRules = [];\n const hasUser = token.split(':').length > 1;\n const insteadUrl = parseGitUrl(gitUrl);\n let sshPort = insteadUrl.port;\n\n if (hostType === 'bitbucket-server') {\n // For Bitbucket Server/Data Center, `source` must be `bitbucket-server`\n // to generate HTTP(s) URLs correctly.\n // https://github.com/IonicaBizau/git-url-parse/blob/28828546c148d58bbcff61409915a4e1e8f7eb11/lib/index.js#L304\n insteadUrl.source = 'bitbucket-server';\n\n // sshPort is string, wrong type!\n // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/72361\n // https://github.com/IonicaBizau/parse-path/blob/87f71f273da90f85f6845937a70b7c032eeae4e3/lib/index.js#L45\n // v8 ignore next -- TODO: add test #40625\n if (!sshPort || isEmptyString(sshPort)) {\n // By default, bitbucket-server SSH port is 7999.\n // For non-default port, the generated auth config will likely be incorrect.\n sshPort = '7999';\n }\n }\n\n const url = { ...insteadUrl };\n const protocol = regEx(/^https?$/).test(url.protocol)\n ? url.protocol\n : 'https';\n\n // ssh protocol with user if empty\n url.token = hasUser ? token : `ssh:${token}`;\n authenticationRules.push({\n url: url.toString(protocol),\n // only edge case, need to stringify ourself because the exact syntax is not supported by the library\n // https://github.com/IonicaBizau/git-url-parse/blob/246c9119fb42c2ea1c280028fe77c53eb34c190c/lib/index.js#L246\n insteadOf: `ssh://git@${insteadUrl.resource}${\n sshPort ? `:${sshPort}` : ''\n }/${insteadUrl.full_name}${insteadUrl.git_suffix ? '.git' : ''}`,\n });\n\n // alternative ssh protocol with user if empty\n url.token = hasUser ? token : `git:${token}`;\n authenticationRules.push({\n url: url.toString(protocol),\n insteadOf: { ...insteadUrl, port: sshPort }.toString('ssh'),\n });\n\n // https protocol with no user as default fallback\n url.token = token;\n authenticationRules.push({\n url: url.toString(protocol),\n insteadOf: insteadUrl.toString(protocol),\n });\n\n return authenticationRules;\n}\n\nexport function getGitEnvironmentVariables(\n environmentVariables: Readonly<ResolvedChildEnv>,\n hostTypes: readonly string[] = [],\n): ResolvedChildEnv {\n let gitEnvironmentVariables: ResolvedChildEnv = { ...environmentVariables };\n\n // hard-coded logic to use authentication for github.com based on the githubToken for api.github.com\n const gitHubHostRule = find({\n hostType: 'github',\n url: 'https://api.github.com/',\n });\n\n if (gitHubHostRule?.token) {\n gitEnvironmentVariables = getGitAuthenticatedEnvironmentVariables(\n gitEnvironmentVariables,\n 'https://github.com/',\n gitHubHostRule,\n );\n }\n\n // Manager-scoped rules are opt-in so unrelated credentials are not exposed to Git.\n const gitAllowedHostTypes = new Set<string>([\n ...PLATFORM_HOST_TYPES,\n ...hostTypes,\n ]);\n\n // filter rules without `matchHost` and `token` or username and password and github api github rules\n const hostRules = getAll()\n .filter((r) => r.matchHost && (r.token ?? (r.username && r.password)))\n .filter((r) => !gitHubHostRule || !githubApiUrls.has(r.matchHost!));\n\n // for each hostRule without hostType we add additional authentication variables to the environmentVariables\n // for each hostRule with hostType we add additional authentication variables to the environmentVariables\n for (const hostRule of hostRules) {\n if (!hostRule.hostType || gitAllowedHostTypes.has(hostRule.hostType)) {\n gitEnvironmentVariables = addAuthFromHostRule(\n hostRule,\n gitEnvironmentVariables,\n );\n }\n }\n return gitEnvironmentVariables;\n}\n\nfunction addAuthFromHostRule(\n hostRule: HostRule,\n environmentVariables: Readonly<ResolvedChildEnv>,\n): ResolvedChildEnv {\n const httpUrl = createURLFromHostOrURL(hostRule.matchHost!)?.toString();\n if (isHttpUrl(httpUrl)) {\n logger.trace(`Adding Git authentication for ${httpUrl} using token auth.`);\n return getGitAuthenticatedEnvironmentVariables(\n environmentVariables,\n httpUrl!,\n hostRule,\n );\n }\n\n logger.debug(\n `Could not parse registryUrl ${hostRule.matchHost!} or not using http(s). Ignoring`,\n );\n return { ...environmentVariables };\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,oBAAoB,IAAI,IAAY,mBAAmB;AAE7D,MAAM,gCAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,SAAgB,wCACd,sBACA,gBACA,EAAE,OAAO,UAAU,UAAU,UAAU,aACrB;CAClB,IAAI,CAAC,SAAS,EAAE,YAAY,WAAW;EACrC,OAAO,KACL,EAAE,MAAM,UAAU,GAClB,kGACF;EACA,OAAO,EAAE,GAAG,qBAAqB;CACnC;CAEA,IAAI;CACJ,IAAI,OACF,sBAAsB,gCACpB,gBACA,UACA,KACF;MAKA,sBAAsB,uBACpB,gBACA,UACA,GANsB,mBAAmB,QAMxB,EAAE,GALG,mBAAmB,QAKL,GACtC;CAGF,OAAO,iCACL,sBACA,oBAAoB,KAAK,UAAU;EACjC,KAAK,OAAO,KAAK,IAAI;EACrB,OAAO,KAAK;CACd,EAAE,CACJ;AACF;AAEA,SAAS,gCACP,KACA,UACA,WACsB;CACtB,MAAM,OAAO,YAAY,eAAe,GAAG;CAC3C,MAAM,WACJ,YAAY,kBAAkB,IAAI,QAAQ,IACtC,WACA,eAAe,GAAG;CACxB,OAAO,uBACL,KACA,MACA,oBAAoB,UAAU,SAAS,CACzC;AACF;;;;;;;;AASA,SAAgB,uBACd,QACA,UACA,OACsB;CACtB,MAAM,sBAAsB,CAAC;CAC7B,MAAM,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS;CAC1C,MAAM,aAAa,YAAY,MAAM;CACrC,IAAI,UAAU,WAAW;CAEzB,IAAI,aAAa,oBAAoB;EAInC,WAAW,SAAS;;EAMpB,IAAI,CAAC,WAAW,cAAc,OAAO,GAGnC,UAAU;CAEd;CAEA,MAAM,MAAM,EAAE,GAAG,WAAW;
|
|
1
|
+
{"version":3,"file":"auth.js","names":[],"sources":["../../../lib/util/git/auth.ts"],"sourcesContent":["import { isEmptyString } from '@sindresorhus/is';\nimport { PLATFORM_HOST_TYPES } from '../../constants/platforms.ts';\nimport { logger } from '../../logger/index.ts';\nimport type { HostRule } from '../../types/index.ts';\nimport { detectPlatform } from '../common.ts';\nimport type { ResolvedChildEnv } from '../exec/utils.ts';\nimport { find, getAll } from '../host-rules.ts';\nimport { regEx } from '../regex.ts';\nimport { createURLFromHostOrURL, isHttpUrl } from '../url.ts';\nimport { addGitConfigEnvironmentVariables } from './config.ts';\nimport type { AuthenticationRule } from './types.ts';\nimport { getTokenCredentials, parseGitUrl } from './url.ts';\n\nconst platformHostTypes = new Set<string>(PLATFORM_HOST_TYPES);\n\nconst githubApiUrls = new Set([\n 'github.com',\n 'api.github.com',\n 'https://api.github.com',\n 'https://api.github.com/',\n]);\n\n/**\n * Append Git authentication configuration to a resolved child environment.\n * @returns a new environment without modifying the input\n */\nexport function getGitAuthenticatedEnvironmentVariables(\n environmentVariables: Readonly<ResolvedChildEnv>,\n originalGitUrl: string,\n { token, username, password, hostType, matchHost }: HostRule,\n): ResolvedChildEnv {\n if (!token && !(username && password)) {\n logger.warn(\n { host: matchHost },\n `Could not create environment variable for host as neither token or username and password was set`,\n );\n return { ...environmentVariables };\n }\n\n let authenticationRules: AuthenticationRule[];\n if (token) {\n authenticationRules = getAuthenticationRulesWithToken(\n originalGitUrl,\n hostType,\n token,\n );\n } else {\n const encodedUsername = encodeURIComponent(username!);\n const encodedPassword = encodeURIComponent(password!);\n\n authenticationRules = getAuthenticationRules(\n originalGitUrl,\n hostType,\n `${encodedUsername}:${encodedPassword}`,\n );\n }\n\n return addGitConfigEnvironmentVariables(\n environmentVariables,\n authenticationRules.map((rule) => ({\n key: `url.${rule.url}.insteadOf`,\n value: rule.insteadOf,\n })),\n );\n}\n\nfunction getAuthenticationRulesWithToken(\n url: string,\n hostType: string | undefined | null,\n authToken: string,\n): AuthenticationRule[] {\n const type = hostType ?? detectPlatform(url);\n const platform =\n hostType && platformHostTypes.has(hostType)\n ? hostType\n : detectPlatform(url);\n return getAuthenticationRules(\n url,\n type,\n getTokenCredentials(platform, authToken),\n );\n}\n\n/**\n * Generates the authentication rules for later git usage for the given host\n * @link https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/\n * @param gitUrl Git repository URL\n * @param hostType Git host type\n * @param token Authentication token or `username:password` string\n */\nexport function getAuthenticationRules(\n gitUrl: string,\n hostType: string | undefined | null,\n token: string,\n): AuthenticationRule[] {\n const authenticationRules = [];\n const hasUser = token.split(':').length > 1;\n const insteadUrl = parseGitUrl(gitUrl);\n let sshPort = insteadUrl.port;\n\n if (hostType === 'bitbucket-server') {\n // For Bitbucket Server/Data Center, `source` must be `bitbucket-server`\n // to generate HTTP(s) URLs correctly.\n // https://github.com/IonicaBizau/git-url-parse/blob/28828546c148d58bbcff61409915a4e1e8f7eb11/lib/index.js#L304\n insteadUrl.source = 'bitbucket-server';\n\n // sshPort is string, wrong type!\n // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/72361\n // https://github.com/IonicaBizau/parse-path/blob/87f71f273da90f85f6845937a70b7c032eeae4e3/lib/index.js#L45\n // v8 ignore next -- TODO: add test #40625\n if (!sshPort || isEmptyString(sshPort)) {\n // By default, bitbucket-server SSH port is 7999.\n // For non-default port, the generated auth config will likely be incorrect.\n sshPort = '7999';\n }\n }\n\n const url = { ...insteadUrl };\n // git-url-parse would prefix `x-token-auth:` again on bitbucket.org\n if (hasUser && url.source === 'bitbucket.org') {\n url.source = 'bitbucket';\n }\n const protocol = regEx(/^https?$/).test(url.protocol)\n ? url.protocol\n : 'https';\n\n // ssh protocol with user if empty\n url.token = hasUser ? token : `ssh:${token}`;\n authenticationRules.push({\n url: url.toString(protocol),\n // only edge case, need to stringify ourself because the exact syntax is not supported by the library\n // https://github.com/IonicaBizau/git-url-parse/blob/246c9119fb42c2ea1c280028fe77c53eb34c190c/lib/index.js#L246\n insteadOf: `ssh://git@${insteadUrl.resource}${\n sshPort ? `:${sshPort}` : ''\n }/${insteadUrl.full_name}${insteadUrl.git_suffix ? '.git' : ''}`,\n });\n\n // alternative ssh protocol with user if empty\n url.token = hasUser ? token : `git:${token}`;\n authenticationRules.push({\n url: url.toString(protocol),\n insteadOf: { ...insteadUrl, port: sshPort }.toString('ssh'),\n });\n\n // https protocol with no user as default fallback\n url.token = token;\n authenticationRules.push({\n url: url.toString(protocol),\n insteadOf: insteadUrl.toString(protocol),\n });\n\n return authenticationRules;\n}\n\nexport function getGitEnvironmentVariables(\n environmentVariables: Readonly<ResolvedChildEnv>,\n hostTypes: readonly string[] = [],\n): ResolvedChildEnv {\n let gitEnvironmentVariables: ResolvedChildEnv = { ...environmentVariables };\n\n // hard-coded logic to use authentication for github.com based on the githubToken for api.github.com\n const gitHubHostRule = find({\n hostType: 'github',\n url: 'https://api.github.com/',\n });\n\n if (gitHubHostRule?.token) {\n gitEnvironmentVariables = getGitAuthenticatedEnvironmentVariables(\n gitEnvironmentVariables,\n 'https://github.com/',\n gitHubHostRule,\n );\n }\n\n // Manager-scoped rules are opt-in so unrelated credentials are not exposed to Git.\n const gitAllowedHostTypes = new Set<string>([\n ...PLATFORM_HOST_TYPES,\n ...hostTypes,\n ]);\n\n // filter rules without `matchHost` and `token` or username and password and github api github rules\n const hostRules = getAll()\n .filter((r) => r.matchHost && (r.token ?? (r.username && r.password)))\n .filter((r) => !gitHubHostRule || !githubApiUrls.has(r.matchHost!));\n\n // for each hostRule without hostType we add additional authentication variables to the environmentVariables\n // for each hostRule with hostType we add additional authentication variables to the environmentVariables\n for (const hostRule of hostRules) {\n if (!hostRule.hostType || gitAllowedHostTypes.has(hostRule.hostType)) {\n gitEnvironmentVariables = addAuthFromHostRule(\n hostRule,\n gitEnvironmentVariables,\n );\n }\n }\n return gitEnvironmentVariables;\n}\n\nfunction addAuthFromHostRule(\n hostRule: HostRule,\n environmentVariables: Readonly<ResolvedChildEnv>,\n): ResolvedChildEnv {\n const httpUrl = createURLFromHostOrURL(hostRule.matchHost!)?.toString();\n if (isHttpUrl(httpUrl)) {\n logger.trace(`Adding Git authentication for ${httpUrl} using token auth.`);\n return getGitAuthenticatedEnvironmentVariables(\n environmentVariables,\n httpUrl!,\n hostRule,\n );\n }\n\n logger.debug(\n `Could not parse registryUrl ${hostRule.matchHost!} or not using http(s). Ignoring`,\n );\n return { ...environmentVariables };\n}\n"],"mappings":"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"}
|
package/dist/util/git/url.js
CHANGED
|
@@ -9,14 +9,18 @@ function parseGitUrl(url) {
|
|
|
9
9
|
return gitUrlParse(url);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Gives a token without a `:`
|
|
12
|
+
* Gives a token without a `:` the username and non-empty password expected by the given platform.
|
|
13
13
|
* Tokens containing a `:` and tokens of other platforms are returned unchanged.
|
|
14
14
|
*/
|
|
15
15
|
function getTokenCredentials(platform, token) {
|
|
16
16
|
if (token.includes(":")) return token;
|
|
17
17
|
switch (platform) {
|
|
18
18
|
case "gitlab": return `gitlab-ci-token:${token}`;
|
|
19
|
-
case "
|
|
19
|
+
case "azure":
|
|
20
|
+
case "github":
|
|
21
|
+
case "scm-manager": return `x-access-token:${token}`;
|
|
22
|
+
case "bitbucket":
|
|
23
|
+
case "bitbucket-server": return `x-token-auth:${token}`;
|
|
20
24
|
case "gitea":
|
|
21
25
|
case "forgejo": return `${token}:x-oauth-basic`;
|
|
22
26
|
default: return token;
|
|
@@ -33,7 +37,10 @@ function getHttpUrl(url, token) {
|
|
|
33
37
|
parsedUrl.user = "";
|
|
34
38
|
parsedUrl.token = token ?? "";
|
|
35
39
|
const platform = detectPlatform(parsedUrl.toString(protocol));
|
|
36
|
-
if (token)
|
|
40
|
+
if (token) {
|
|
41
|
+
parsedUrl.token = getTokenCredentials(platform, token);
|
|
42
|
+
if (parsedUrl.source === "bitbucket.org") parsedUrl.source = "bitbucket";
|
|
43
|
+
}
|
|
37
44
|
switch (platform) {
|
|
38
45
|
case "bitbucket-server":
|
|
39
46
|
// v8 ignore else -- TODO: add test #40625
|
package/dist/util/git/url.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","names":["hostRules.find"],"sources":["../../../lib/util/git/url.ts"],"sourcesContent":["import gitUrlParse from 'git-url-parse';\nimport { logger } from '../../logger/index.ts';\nimport { detectPlatform } from '../common.ts';\nimport * as hostRules from '../host-rules.ts';\nimport { regEx } from '../regex.ts';\nimport { parseUrl } from '../url.ts';\n\nexport function parseGitUrl(url: string): gitUrlParse.GitUrl {\n return gitUrlParse(url);\n}\n\n/**\n * Gives a token without a `:`
|
|
1
|
+
{"version":3,"file":"url.js","names":["hostRules.find"],"sources":["../../../lib/util/git/url.ts"],"sourcesContent":["import gitUrlParse from 'git-url-parse';\nimport { logger } from '../../logger/index.ts';\nimport { detectPlatform } from '../common.ts';\nimport * as hostRules from '../host-rules.ts';\nimport { regEx } from '../regex.ts';\nimport { parseUrl } from '../url.ts';\n\nexport function parseGitUrl(url: string): gitUrlParse.GitUrl {\n return gitUrlParse(url);\n}\n\n/**\n * Gives a token without a `:` the username and non-empty password expected by the given platform.\n * Tokens containing a `:` and tokens of other platforms are returned unchanged.\n */\nexport function getTokenCredentials(\n platform: string | null | undefined,\n token: string,\n): string {\n if (token.includes(':')) {\n return token;\n }\n switch (platform) {\n case 'gitlab':\n return `gitlab-ci-token:${token}`;\n case 'azure':\n case 'github':\n case 'scm-manager':\n return `x-access-token:${token}`;\n case 'bitbucket':\n case 'bitbucket-server':\n return `x-token-auth:${token}`;\n case 'gitea':\n case 'forgejo':\n return `${token}:x-oauth-basic`;\n default:\n return token;\n }\n}\n\nexport function getHttpUrl(url: string, token?: string): string {\n const parsedUrl = parseGitUrl(url);\n\n let { protocol } = parsedUrl;\n const origProtocol = protocol;\n\n // Convert non-https URLs to https and strip port\n if (!regEx(/^https?$/).test(protocol)) {\n parsedUrl.port = '443';\n protocol = 'https';\n }\n\n parsedUrl.user = '';\n parsedUrl.token = token ?? '';\n\n const platform = detectPlatform(parsedUrl.toString(protocol));\n if (token) {\n parsedUrl.token = getTokenCredentials(platform, token);\n // git-url-parse would prefix `x-token-auth:` again on bitbucket.org\n if (parsedUrl.source === 'bitbucket.org') {\n parsedUrl.source = 'bitbucket';\n }\n }\n\n switch (platform) {\n case 'bitbucket-server':\n // SSH URLs look like ssh://git@git.my.com:7999/project/repo.git\n // HTTPS URLs look like https://git.my.com/scm/project/repo.git\n // git-url-parse can't detect bitbucket-server from SSH URL\n // and thus doesn't know it should insert '/scm/'\n // v8 ignore else -- TODO: add test #40625\n if (origProtocol === 'ssh') {\n parsedUrl.source = 'bitbucket-server';\n }\n break;\n }\n\n const httpUrl = parseUrl(parsedUrl.toString(protocol));\n // v8 ignore if: git-url-parse always produces a parseable URL string\n if (!httpUrl) {\n throw new Error(`Failed to parse git URL: ${parsedUrl.toString(protocol)}`);\n }\n return httpUrl.href;\n}\n\nexport function getRemoteUrlWithToken(url: string, hostType?: string): string {\n let coercedUrl: string;\n\n try {\n coercedUrl = getHttpUrl(url);\n } catch {\n logger.warn({ url }, `Attempting to use non-git url for git operations`);\n\n coercedUrl = url;\n }\n\n const hostRule = hostRules.find({ url: coercedUrl, hostType });\n\n if (hostRule?.token) {\n logger.debug(`Found hostRules token for url ${url}`);\n\n return getHttpUrl(url, encodeURIComponent(hostRule.token));\n }\n\n if (hostRule?.username && hostRule?.password) {\n logger.debug(`Found hostRules username and password for url ${url}`);\n const encodedUsername = encodeURIComponent(hostRule.username);\n const encodedPassword = encodeURIComponent(hostRule.password);\n\n return getHttpUrl(url, `${encodedUsername}:${encodedPassword}`);\n }\n\n return url;\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,YAAY,KAAiC;CAC3D,OAAO,YAAY,GAAG;AACxB;;;;;AAMA,SAAgB,oBACd,UACA,OACQ;CACR,IAAI,MAAM,SAAS,GAAG,GACpB,OAAO;CAET,QAAQ,UAAR;EACE,KAAK,UACH,OAAO,mBAAmB;EAC5B,KAAK;EACL,KAAK;EACL,KAAK,eACH,OAAO,kBAAkB;EAC3B,KAAK;EACL,KAAK,oBACH,OAAO,gBAAgB;EACzB,KAAK;EACL,KAAK,WACH,OAAO,GAAG,MAAM;EAClB,SACE,OAAO;CACX;AACF;AAEA,SAAgB,WAAW,KAAa,OAAwB;CAC9D,MAAM,YAAY,YAAY,GAAG;CAEjC,IAAI,EAAE,aAAa;CACnB,MAAM,eAAe;CAGrB,IAAI,CAAC,MAAM,UAAU,CAAC,CAAC,KAAK,QAAQ,GAAG;EACrC,UAAU,OAAO;EACjB,WAAW;CACb;CAEA,UAAU,OAAO;CACjB,UAAU,QAAQ,SAAS;CAE3B,MAAM,WAAW,eAAe,UAAU,SAAS,QAAQ,CAAC;CAC5D,IAAI,OAAO;EACT,UAAU,QAAQ,oBAAoB,UAAU,KAAK;EAErD,IAAI,UAAU,WAAW,iBACvB,UAAU,SAAS;CAEvB;CAEA,QAAQ,UAAR;EACE,KAAK;;EAMH,IAAI,iBAAiB,OACnB,UAAU,SAAS;CAGzB;CAEA,MAAM,UAAU,SAAS,UAAU,SAAS,QAAQ,CAAC;;CAErD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,4BAA4B,UAAU,SAAS,QAAQ,GAAG;CAE5E,OAAO,QAAQ;AACjB;AAEA,SAAgB,sBAAsB,KAAa,UAA2B;CAC5E,IAAI;CAEJ,IAAI;EACF,aAAa,WAAW,GAAG;CAC7B,QAAQ;EACN,OAAO,KAAK,EAAE,IAAI,GAAG,kDAAkD;EAEvE,aAAa;CACf;CAEA,MAAM,WAAWA,KAAe;EAAE,KAAK;EAAY;CAAS,CAAC;CAE7D,IAAI,UAAU,OAAO;EACnB,OAAO,MAAM,iCAAiC,KAAK;EAEnD,OAAO,WAAW,KAAK,mBAAmB,SAAS,KAAK,CAAC;CAC3D;CAEA,IAAI,UAAU,YAAY,UAAU,UAAU;EAC5C,OAAO,MAAM,iDAAiD,KAAK;EAInE,OAAO,WAAW,KAAK,GAHC,mBAAmB,SAAS,QAGZ,EAAE,GAFlB,mBAAmB,SAAS,QAEO,GAAG;CAChE;CAEA,OAAO;AACT"}
|
package/package.json
CHANGED
package/renovate-schema.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$id": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
-
"title": "JSON schema for Renovate 44.164.
|
|
3
|
+
"title": "JSON schema for Renovate 44.164.4 config files (https://renovatebot.com/)",
|
|
4
4
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
5
|
-
"x-renovate-version": "44.164.
|
|
5
|
+
"x-renovate-version": "44.164.4",
|
|
6
6
|
"allowComments": true,
|
|
7
7
|
"type": "object",
|
|
8
8
|
"definitions": {
|