From 2c75f68f7074479580e5da16055cd3e5e9d4d2fc Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Thu, 9 Nov 2023 10:53:23 -0500 Subject: [PATCH] Adds patch storage confirmation --- src/constants.ts | 1 + src/plus/utils.ts | 29 +++++++++++++++++++++- .../webviews/patchDetails/patchDetailsWebview.ts | 9 +++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 815947c..9689be5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -837,6 +837,7 @@ export type GlobalStorage = { // Keep the pre-release version separate from the released version preVersion: string; 'views:welcome:visible': boolean; + 'confirm:draft:storage': boolean; } & { [key in `confirm:ai:tos:${AIProviders}`]: boolean } & { [key in `provider:authentication:skip:${string}`]: boolean; }; diff --git a/src/plus/utils.ts b/src/plus/utils.ts index d210e00..acb552c 100644 --- a/src/plus/utils.ts +++ b/src/plus/utils.ts @@ -1,4 +1,5 @@ -import { window } from 'vscode'; +import type { MessageItem } from 'vscode'; +import { env, Uri, window } from 'vscode'; import type { Container } from '../container'; import { isSubscriptionPaidPlan } from './gk/account/subscription'; @@ -107,3 +108,29 @@ export async function ensureAccount(title: string, container: Container): Promis return true; } + +export async function confirmDraftStorage(container: Container): Promise { + if (container.storage.get('confirm:draft:storage', false)) return true; + + const accept: MessageItem = { title: 'Yes' }; + const decline: MessageItem = { title: 'No', isCloseAffordance: true }; + const moreInfo: MessageItem = { title: 'More Info' }; + const result = await window.showInformationMessage( + `Creating a Cloud Patch will store code on GitKraken's servers.\n\nDo you want to continue?`, + { modal: true }, + accept, + decline, + moreInfo, + ); + + if (result === accept) { + void container.storage.store('confirm:draft:storage', true); + return true; + } + + if (result === moreInfo) { + void env.openExternal(Uri.parse('https://help.gitkraken.com/gitlens/security')); + } + + return false; +} diff --git a/src/plus/webviews/patchDetails/patchDetailsWebview.ts b/src/plus/webviews/patchDetails/patchDetailsWebview.ts index 18c301d..a0a224a 100644 --- a/src/plus/webviews/patchDetails/patchDetailsWebview.ts +++ b/src/plus/webviews/patchDetails/patchDetailsWebview.ts @@ -28,7 +28,7 @@ import { onIpc } from '../../../webviews/protocol'; import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController'; import type { WebviewShowOptions } from '../../../webviews/webviewsController'; import { showPatchesView } from '../../drafts/actions'; -import { ensureAccount } from '../../utils'; +import { confirmDraftStorage, ensureAccount } from '../../utils'; import type { ShowInCommitGraphCommandArgs } from '../graph/protocol'; import type { ApplyPatchParams, @@ -311,7 +311,12 @@ export class PatchDetailsWebviewProvider return; } - if (!(await ensureAccount('Cloud Patches require a GitKraken account.', this.container))) return; + if ( + !(await ensureAccount('Cloud Patches require a GitKraken account.', this.container)) || + !(await confirmDraftStorage(this.container)) + ) { + return; + } const changeset = this._context.draft.changesets?.[0]; if (changeset == null) return;