From 3b1c5fcbd646c9182b9ac4d48018a2215bf4cd64 Mon Sep 17 00:00:00 2001 From: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> Date: Wed, 12 Apr 2023 11:10:38 +0100 Subject: [PATCH] batches: surface batch change rollout window in JSContext (#50471) #48217 and #48963 require the `batchChangesRolloutWindows` configuration to be available in the frontend. This PR surfaces the value via the `jscontext` object preloaded when the UI starts. ## Test plan * Start up a Sourcegraph instance with `sg start batches` * If the rollout window is configured in the Site Config, then logging `window.context` should include the configured values in the `batchChangesRolloutWindows` field. ![CleanShot 2023-04-07 at 12 50 12@2x](https://user-images.githubusercontent.com/25608335/230604199-adecb401-29fe-4cd5-b94f-f4f5d7da157d.png) * If not, the value of `batchChangesRolloutWindows` will be null. ![CleanShot 2023-04-07 at 12 49 46@2x](https://user-images.githubusercontent.com/25608335/230604227-c1013cf0-19a5-462f-81f9-20c5883e1f48.png) --- client/web/dev/utils/create-js-context.ts | 1 + client/web/src/integration/jscontext.ts | 1 + client/web/src/jscontext.ts | 4 +++- cmd/frontend/internal/app/jscontext/jscontext.go | 8 +++++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/web/dev/utils/create-js-context.ts b/client/web/dev/utils/create-js-context.ts index 99008e54c7514..2bc14e8d19116 100644 --- a/client/web/dev/utils/create-js-context.ts +++ b/client/web/dev/utils/create-js-context.ts @@ -76,6 +76,7 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st }, embeddingsEnabled: false, primaryLoginProvidersCount: 5, + batchChangesRolloutWindows: null, // Site-config overrides default JS context ...siteConfig, } diff --git a/client/web/src/integration/jscontext.ts b/client/web/src/integration/jscontext.ts index b5b417d794ecf..04a0ead15dae8 100644 --- a/client/web/src/integration/jscontext.ts +++ b/client/web/src/integration/jscontext.ts @@ -58,4 +58,5 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st localFilePickerAvailable: false, srcServeGitUrl: 'http://127.0.0.1:3434', primaryLoginProvidersCount: 5, + batchChangesRolloutWindows: null, }) diff --git a/client/web/src/jscontext.ts b/client/web/src/jscontext.ts index 93defa129edcf..9a8f83dc489f8 100644 --- a/client/web/src/jscontext.ts +++ b/client/web/src/jscontext.ts @@ -1,5 +1,5 @@ import { AuthenticatedUser } from '@sourcegraph/shared/src/auth' -import { SiteConfiguration } from '@sourcegraph/shared/src/schema/site.schema' +import { SiteConfiguration, BatchChangeRolloutWindow } from '@sourcegraph/shared/src/schema/site.schema' import { TemporarySettingsResult } from './graphql-operations' @@ -183,6 +183,8 @@ export interface SourcegraphContext extends Pick, 'e batchChangesWebhookLogsEnabled: boolean + batchChangesRolloutWindows: BatchChangeRolloutWindow[] | null + /** Whether executors are enabled on the site. */ executorsEnabled: boolean diff --git a/cmd/frontend/internal/app/jscontext/jscontext.go b/cmd/frontend/internal/app/jscontext/jscontext.go index 8d57c12d3e1e4..b0cc90bfe1068 100644 --- a/cmd/frontend/internal/app/jscontext/jscontext.go +++ b/cmd/frontend/internal/app/jscontext/jscontext.go @@ -171,9 +171,10 @@ type JSContext struct { Branding *schema.Branding `json:"branding"` - BatchChangesEnabled bool `json:"batchChangesEnabled"` - BatchChangesDisableWebhooksWarning bool `json:"batchChangesDisableWebhooksWarning"` - BatchChangesWebhookLogsEnabled bool `json:"batchChangesWebhookLogsEnabled"` + BatchChangesEnabled bool `json:"batchChangesEnabled"` + BatchChangesDisableWebhooksWarning bool `json:"batchChangesDisableWebhooksWarning"` + BatchChangesWebhookLogsEnabled bool `json:"batchChangesWebhookLogsEnabled"` + BatchChangesRolloutWindows *[]*schema.BatchChangeRolloutWindow `json:"batchChangesRolloutWindows"` ExecutorsEnabled bool `json:"executorsEnabled"` CodeIntelAutoIndexingEnabled bool `json:"codeIntelAutoIndexingEnabled"` @@ -353,6 +354,7 @@ func NewJSContextFromRequest(req *http.Request, db database.DB) JSContext { BatchChangesEnabled: enterprise.BatchChangesEnabledForUser(ctx, db) == nil, BatchChangesDisableWebhooksWarning: conf.Get().BatchChangesDisableWebhooksWarning, BatchChangesWebhookLogsEnabled: webhooks.LoggingEnabled(conf.Get()), + BatchChangesRolloutWindows: conf.Get().BatchChangesRolloutWindows, ExecutorsEnabled: conf.ExecutorsEnabled(), CodeIntelAutoIndexingEnabled: conf.CodeIntelAutoIndexingEnabled(),