Skip to content

Commit

Permalink
Add in product changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Jul 14, 2022
1 parent bab83b6 commit e3ad31e
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 4 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"onCommand:gitpod.syncProvider.remove",
"onCommand:gitpod.exportLogs",
"onCommand:gitpod.api.autoTunnel",
"onCommand:gitpod.releaseNote",
"onCommand:gitpod.cleanReleaseNoteCache",
"onAuthenticationRequest:gitpod",
"onUri"
],
Expand Down Expand Up @@ -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"
}
]
},
Expand All @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down
164 changes: 164 additions & 0 deletions src/releaseNote.ts
Original file line number Diff line number Diff line change
@@ -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<string>(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(/<script>.*?<\/script>/gms, '')
.replace(/<Badge.*?text="(.*?)".*?\/>/gim, '`$1`')
.replace(/<Contributors usernames="(.*?)" \/>/gim, (_, p1) => {
const users = p1
.split(',')
.map((e: string) => `[${e}](https://github.com/${e})`);
return `Contributors: ${users.join(', ')}`;
})
.replace(/<p>(.*?)<\/p>/gm, '$1')
.replace(/^[\n]+/m, '');
if (!info) {
return content;
}

return [
`# ${info.title}`,
'> See also https://gitpod.io/changelog',
`![${info.alt ?? 'image'}](https://www.gitpod.io/images/changelog/${info.image})`,
content,
].join('\n\n');
}

public async updateHtml(date?: string) {
if (!date) {
date = await getLastPublish();
}
const mdContent = await this.loadChangelog(date);
const html = await vscode.commands.executeCommand('markdown.api.render', mdContent) as string;
this.panel.webview.html = html;
if (!this.lastRead || date > this.lastRead) {
await this.context.globalState.update(LAST_READ_RELEASE_DATE, date);
this.lastRead = date;
}
}

public static createOrShow(context: vscode.ExtensionContext) {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined;

if (ReleaseNotePanel.currentPanel) {
ReleaseNotePanel.currentPanel.panel.reveal(column);
return;
}

const panel = vscode.window.createWebviewPanel(
ReleaseNotePanel.viewType,
'Gitpod Release Note',
column || vscode.ViewColumn.One,
{ enableScripts: true },
);

ReleaseNotePanel.currentPanel = new ReleaseNotePanel(context, panel);
}

public static revive(context: vscode.ExtensionContext, panel: vscode.WebviewPanel) {
ReleaseNotePanel.currentPanel = new ReleaseNotePanel(context, panel);
}

private constructor(
private readonly context: vscode.ExtensionContext,
panel: vscode.WebviewPanel
) {
this.lastRead = this.context.globalState.get<string>(LAST_READ_RELEASE_DATE);
this.panel = panel;

this.updateHtml();

this.panel.onDidDispose(() => this.dispose(), null, this._disposables);
this.panel.onDidChangeViewState(
() => {
if (this.panel.visible) {
this.updateHtml();
}
},
null,
this._disposables
);
}

public dispose() {
ReleaseNotePanel.currentPanel = undefined;
this.panel.dispose();
while (this._disposables.length) {
const x = this._disposables.pop();
if (x) {
x.dispose();
}
}
}
}
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@gitpod/gitpod-protocol@^0.1.5-main.3838":
version "0.1.5-main.3838"
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.3838.tgz#06c0237a919c3758acca0e0257090892b35414a6"
integrity sha512-7OC73XcZgilmOKxjVPPygkkbsVugumjF3tBvLuLPt1LJbmws48X5KUqtlhnws3epwcfrU3JJXS2uJRxSizS9pQ==
"@gitpod/gitpod-protocol@main":
version "0.1.5-main.3890"
resolved "https://registry.yarnpkg.com/@gitpod/gitpod-protocol/-/gitpod-protocol-0.1.5-main.3890.tgz#11b4c4b7df69acd746340f80b9e433efa2c950ec"
integrity sha512-P2LJXlIaUPLluhctS0sit5FEj9FjUPM2J57wIFTGPPQN+CNf+hz628Gg9klfpGJRgF/d7B/1ByTEdq9yXF95UQ==
dependencies:
"@types/react" "17.0.32"
ajv "^6.5.4"
Expand Down Expand Up @@ -177,6 +177,11 @@
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.6.tgz#674a69493ef2c849b95eafe69167ea59079eb504"
integrity sha512-pYVNNJ+winC4aek+lZp93sIKxnXt5qMkuKmaqS3WGuTq0Bw1ZDYNBgzG5kkdtwcv+GmYJGo3yEg6z2cKKAiEdw==

"@types/js-yaml@^4.0.5":
version "4.0.5"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.5.tgz#738dd390a6ecc5442f35e7f03fa1431353f7e138"
integrity sha512-FhpRzf927MNQdRZP0J5DLIdTXhjLYzeUTmLAu69mnVksLH9CJY3IuSeEgbKUki7GQZm0WqDkGzyxju2EZGD2wA==

"@types/json-schema@*", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
Expand Down

0 comments on commit e3ad31e

Please sign in to comment.