Skip to content

Commit

Permalink
feat(config/self-hosted): userAgent (#28737)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
RahulGautamSingh and rarkins committed Apr 29, 2024
1 parent c682422 commit 5558b0d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/usage/self-hosted-configuration.md
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions docs/usage/self-hosted-experimental.md
Expand Up @@ -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`

<!-- prettier-ignore -->
Expand Down
1 change: 1 addition & 0 deletions lib/config/global.ts
Expand Up @@ -33,6 +33,7 @@ export class GlobalConfig {
'platform',
'endpoint',
'httpCacheTtlDays',
'userAgent',
];

private static config: RepoGlobalConfig = {};
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Expand Up @@ -159,6 +159,7 @@ export interface RepoGlobalConfig {
privateKey?: string;
privateKeyOld?: string;
httpCacheTtlDays?: number;
userAgent?: string;
}

export interface LegacyAdminConfig {
Expand Down
3 changes: 2 additions & 1 deletion lib/util/http/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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)`,
};
}
Expand Down

0 comments on commit 5558b0d

Please sign in to comment.