diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 2c1af6afecbad4..80fed5ff440ddf 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -1110,6 +1110,11 @@ For example: `:warning:` will be replaced with `⚠️`. Some cloud providers offer services to receive metadata about the current instance, for example [AWS Instance metadata](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html) or [GCP VM metadata](https://cloud.google.com/compute/docs/metadata/overview). You can control if Renovate should try to access these services with the `useCloudMetadataServices` config option. +## userAgent + +If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. +Otherwise, it will default to `RenovateBot/${renovateVersion} (https://github.com/renovatebot/renovate)`. + ## username You may need to set a `username` if you: diff --git a/docs/usage/self-hosted-experimental.md b/docs/usage/self-hosted-experimental.md index fcf3c95a94e57e..1dc8fd40f5f6a0 100644 --- a/docs/usage/self-hosted-experimental.md +++ b/docs/usage/self-hosted-experimental.md @@ -32,10 +32,6 @@ Skipping the check will speed things up, but may result in versions being return If set to any value, Renovate will always paginate requests to GitHub fully, instead of stopping after 10 pages. -## `RENOVATE_USER_AGENT` - -If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests. - ## `RENOVATE_X_AUTODISCOVER_REPO_ORDER` diff --git a/lib/config/global.ts b/lib/config/global.ts index 21b2b56cc25f8d..c713f8635fd0ba 100644 --- a/lib/config/global.ts +++ b/lib/config/global.ts @@ -33,6 +33,7 @@ export class GlobalConfig { 'platform', 'endpoint', 'httpCacheTtlDays', + 'userAgent', ]; private static config: RepoGlobalConfig = {}; diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 995e05b93cbb90..76ae38a7e33266 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -47,6 +47,14 @@ const options: RenovateOptions[] = [ default: true, globalOnly: true, }, + { + name: 'userAgent', + description: + 'If set to any string, Renovate will use this as the `user-agent` it sends with HTTP requests.', + type: 'string', + default: null, + globalOnly: true, + }, { name: 'allowPostUpgradeCommandTemplating', description: diff --git a/lib/config/types.ts b/lib/config/types.ts index 2e55575c98927a..ff309df752a66d 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -159,6 +159,7 @@ export interface RepoGlobalConfig { privateKey?: string; privateKeyOld?: string; httpCacheTtlDays?: number; + userAgent?: string; } export interface LegacyAdminConfig { diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index b93c659497e729..7c505db6ef4bf3 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -3,6 +3,7 @@ import merge from 'deepmerge'; import got, { Options, RequestError } from 'got'; import type { SetRequired } from 'type-fest'; import { infer as Infer, type ZodError, ZodType } from 'zod'; +import { GlobalConfig } from '../../config/global'; import { HOST_DISABLED } from '../../constants/error-messages'; import { pkg } from '../../expose.cjs'; import { logger } from '../../logger'; @@ -50,7 +51,7 @@ function applyDefaultHeaders(options: Options): void { options.headers = { ...options.headers, 'user-agent': - process.env.RENOVATE_USER_AGENT ?? + GlobalConfig.get('userAgent') ?? `RenovateBot/${renovateVersion} (https://github.com/renovatebot/renovate)`, }; }