From e3ad31ef2fee460b4e13a555f219d6efaca55eb3 Mon Sep 17 00:00:00 2001 From: mustard Date: Thu, 14 Jul 2022 09:48:59 +0800 Subject: [PATCH] Add in product changelog --- package.json | 14 ++++ src/extension.ts | 3 + src/releaseNote.ts | 164 +++++++++++++++++++++++++++++++++++++++++++++ yarn.lock | 13 ++-- 4 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 src/releaseNote.ts diff --git a/package.json b/package.json index 0ffdcc6c..fbd36099 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,8 @@ "onCommand:gitpod.syncProvider.remove", "onCommand:gitpod.exportLogs", "onCommand:gitpod.api.autoTunnel", + "onCommand:gitpod.releaseNote", + "onCommand:gitpod.cleanReleaseNoteCache", "onAuthenticationRequest:gitpod", "onUri" ], @@ -87,6 +89,16 @@ "command": "gitpod.exportLogs", "category": "Gitpod", "title": "Export all logs" + }, + { + "command": "gitpod.releaseNote", + "category": "Gitpod", + "title": "Show Release Note" + }, + { + "command": "gitpod.cleanReleaseNoteCache", + "category": "Gitpod", + "title": "Debug Clean Release Note Cache" } ] }, @@ -104,6 +116,7 @@ "@types/analytics-node": "^3.1.9", "@types/crypto-js": "4.1.1", "@types/google-protobuf": "^3.7.4", + "@types/js-yaml": "^4.0.5", "@types/node": "16.x", "@types/node-fetch": "^2.5.12", "@types/ssh2": "^0.5.52", @@ -129,6 +142,7 @@ "@gitpod/local-app-api-grpcweb": "main", "@improbable-eng/grpc-web-node-http-transport": "^0.14.0", "analytics-node": "^6.0.0", + "js-yaml": "^4.1.0", "node-fetch": "2.6.7", "pkce-challenge": "^3.0.0", "ssh2": "^1.10.0", diff --git a/src/extension.ts b/src/extension.ts index 22c9b956..0108db31 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,6 +12,7 @@ import { enableSettingsSync, updateSyncContext } from './settingsSync'; import { GitpodServer } from './gitpodServer'; import TelemetryReporter from './telemetryReporter'; import { exportLogs } from './exportLogs'; +import { registerReleaseNoteView } from './releaseNote'; const EXTENSION_ID = 'gitpod.gitpod-desktop'; const FIRST_INSTALL_KEY = 'gitpod-desktop.firstInstall'; @@ -93,6 +94,8 @@ export async function activate(context: vscode.ExtensionContext) { await context.globalState.update(FIRST_INSTALL_KEY, true); telemetry.sendTelemetryEvent('gitpod_desktop_installation', { kind: 'install' }); } + + registerReleaseNoteView(context); } export async function deactivate() { diff --git a/src/releaseNote.ts b/src/releaseNote.ts new file mode 100644 index 00000000..5079556a --- /dev/null +++ b/src/releaseNote.ts @@ -0,0 +1,164 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Gitpod. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import fetch from 'node-fetch'; +import * as vscode from 'vscode'; +import { load } from 'js-yaml'; + +const LAST_READ_RELEASE_DATE = 'gitpod-desktop.releaseNote'; + +export function registerReleaseNoteView(context: vscode.ExtensionContext) { + context.subscriptions.push( + vscode.commands.registerCommand('gitpod.releaseNote', () => { + ReleaseNotePanel.createOrShow(context); + }) + ); + + // TODO(hw): Remove + context.subscriptions.push( + vscode.commands.registerCommand('gitpod.cleanReleaseNoteCache', async () => { + await context.globalState.update(LAST_READ_RELEASE_DATE, undefined); + }) + ); + + const lastRead = context.globalState.get(LAST_READ_RELEASE_DATE); + shouldShowReleaseNote(lastRead).then(shouldShow => { + if (shouldShow) { + ReleaseNotePanel.createOrShow(context); + } + }); +} + +async function getLastPublish() { + // TODO(hw): fetch from somewhere + return '2022-07-04'; +} + +async function shouldShowReleaseNote(lastRead: string | undefined) { + const date = await getLastPublish(); + console.log(`lastSeen: ${lastRead}, latest publish: ${date} => ${date !== lastRead ? 'show' : 'not-show'} ===============hwen.shouldShow`); + return date !== lastRead; +} + +class ReleaseNotePanel { + public static currentPanel: ReleaseNotePanel | undefined; + public static readonly viewType = 'gitpodReleaseNote'; + private readonly panel: vscode.WebviewPanel; + private lastRead: string | undefined; + private _disposables: vscode.Disposable[] = []; + + private async loadChangelog(date: string) { + // TODO(hw): fetch from somewhere + console.log(date, fetch, 'ignore'); + const resp = await fetch(`https://raw.githubusercontent.com/gitpod-io/website/main/src/lib/contents/changelog/${date}.md`); + if (!resp.ok) { + throw new Error(`Getting GitHub account info failed: ${resp.statusText}`); + } + const md = await resp.text(); + + const parseInfo = (md: string) => { + if (!md.startsWith('---')) { + return; + } + const lines = md.split('\n'); + const end = lines.indexOf('---', 1); + const content = lines.slice(1, end).join('\n'); + return load(content) as { title: string; date: string; image: string; alt: string; excerpt: string }; + }; + const info = parseInfo(md); + + const content = md + .replace(/---.*?---/gms, '') + .replace(/