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 494f7eb commit bc7dead
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 3 deletions.
2 changes: 2 additions & 0 deletions extensions/gitpod-remote/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"openTwitter": "Gitpod: Follow us on Twitter",
"reportIssue": "Gitpod: Report Issue",
"stopWorkspace": "Gitpod: Stop Workspace",
"showReleaseNote": "Gitpod: Show Release Note",
"cleanReleaseNoteCache": "Gitpod: Debug Clean Release Note Cache",
"upgradeSubscription": "Gitpod: Upgrade Subscription",
"extendTimeout": "Gitpod: Extend Workspace Timeout",
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
Expand Down
4 changes: 3 additions & 1 deletion extensions/gitpod-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"prepare": "node scripts/inflate.js"
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/node": "16.x",
"@types/uuid": "^8.3.1",
"@types/ws": "^7.2.6"
Expand All @@ -20,8 +21,9 @@
"@gitpod/gitpod-protocol": "main",
"@gitpod/supervisor-api-grpc": "main",
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2",
"js-yaml": "^4.1.0",
"reconnecting-websocket": "^4.4.0",
"utf-8-validate": "^5.0.2",
"uuid": "^8.3.1",
"vscode-nls": "^5.0.0",
"ws": "^7.4.6",
Expand Down
2 changes: 2 additions & 0 deletions extensions/gitpod-shared/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as vscode from 'vscode';
import { registerActiveLanguageAnalytics, registerUsageAnalytics } from './analytics';
import { createGitpodExtensionContext, GitpodExtensionContext, registerDefaultLayout, registerNotifications, registerWorkspaceCommands, registerWorkspaceSharing, registerWorkspaceTimeout } from './features';
import { registerReleaseNoteView } from './releaseNote';

export { GitpodExtensionContext, registerTasks, SupervisorConnection, registerIpcHookCli } from './features';
export * from './gitpod-plugin-model';
Expand Down Expand Up @@ -32,6 +33,7 @@ export async function setupGitpodContext(context: vscode.ExtensionContext): Prom
registerWorkspaceTimeout(gitpodContext);
registerNotifications(gitpodContext);
registerDefaultLayout(gitpodContext);
registerReleaseNoteView(gitpodContext);
return gitpodContext;
}

Expand Down
317 changes: 317 additions & 0 deletions extensions/gitpod-shared/src/releaseNote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
/*---------------------------------------------------------------------------------------------
* 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: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}`,
`> Published at ${date}, 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 = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gitpod Release Note</title>
<style>
${DEFAULT_MARKDOWN_STYLES}
</style>
</head>
<body>
${html}
</body>
</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();
}
}
}
}

// Align with https://github.com/gitpod-io/openvscode-server/blob/494f7eba3615344ee634e6bec0b20a1903e5881d/src/vs/workbench/contrib/markdown/browser/markdownDocumentRenderer.ts#L14
export const DEFAULT_MARKDOWN_STYLES = `
body {
padding: 10px 20px;
line-height: 22px;
max-width: 882px;
margin: 0 auto;
}
body *:last-child {
margin-bottom: 0;
}
img {
max-width: 100%;
max-height: 100%;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:focus,
input:focus,
select:focus,
textarea:focus {
outline: 1px solid -webkit-focus-ring-color;
outline-offset: -1px;
}
hr {
border: 0;
height: 2px;
border-bottom: 2px solid;
}
h1 {
padding-bottom: 0.3em;
line-height: 1.2;
border-bottom-width: 1px;
border-bottom-style: solid;
}
h1, h2, h3 {
font-weight: normal;
}
table {
border-collapse: collapse;
}
table > thead > tr > th {
text-align: left;
border-bottom: 1px solid;
}
table > thead > tr > th,
table > thead > tr > td,
table > tbody > tr > th,
table > tbody > tr > td {
padding: 5px 10px;
}
table > tbody > tr + tr > td {
border-top-width: 1px;
border-top-style: solid;
}
blockquote {
margin: 0 7px 0 5px;
padding: 0 16px 0 10px;
border-left-width: 5px;
border-left-style: solid;
}
code {
font-family: "SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
}
pre code {
font-family: var(--vscode-editor-font-family);
font-weight: var(--vscode-editor-font-weight);
font-size: var(--vscode-editor-font-size);
line-height: 1.5;
}
code > div {
padding: 16px;
border-radius: 3px;
overflow: auto;
}
.monaco-tokenized-source {
white-space: pre;
}
/** Theming */
.vscode-light code > div {
background-color: rgba(220, 220, 220, 0.4);
}
.vscode-dark code > div {
background-color: rgba(10, 10, 10, 0.4);
}
.vscode-high-contrast code > div {
background-color: var(--vscode-textCodeBlock-background);
}
.vscode-high-contrast h1 {
border-color: rgb(0, 0, 0);
}
.vscode-light table > thead > tr > th {
border-color: rgba(0, 0, 0, 0.69);
}
.vscode-dark table > thead > tr > th {
border-color: rgba(255, 255, 255, 0.69);
}
.vscode-light h1,
.vscode-light hr,
.vscode-light table > tbody > tr + tr > td {
border-color: rgba(0, 0, 0, 0.18);
}
.vscode-dark h1,
.vscode-dark hr,
.vscode-dark table > tbody > tr + tr > td {
border-color: rgba(255, 255, 255, 0.18);
}
`;
10 changes: 10 additions & 0 deletions extensions/gitpod-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
"title": "%stopWorkspace%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.releaseNote",
"title": "%showReleaseNote%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.cleanReleaseNoteCache",
"title": "%cleanReleaseNoteCache%",
"enablement": "gitpod.inWorkspace == true && gitpod.workspaceOwned == true"
},
{
"command": "gitpod.open.settings",
"title": "%openSettings%",
Expand Down
4 changes: 3 additions & 1 deletion extensions/gitpod-web/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"openTwitter": "Gitpod: Follow us on Twitter",
"reportIssue": "Gitpod: Report Issue",
"stopWorkspace": "Gitpod: Stop Workspace",
"showReleaseNote": "Gitpod: Show Release Note",
"cleanReleaseNoteCache": "Gitpod: Debug Clean Release Note Cache",
"upgradeSubscription": "Gitpod: Upgrade Subscription",
"extendTimeout": "Gitpod: Extend Workspace Timeout",
"takeSnapshot": "Gitpod: Share Workspace Snapshot",
Expand All @@ -28,4 +30,4 @@
"openInStable": "Gitpod: Open in VS Code",
"openInInsiders": "Gitpod: Open in VS Code Insiders",
"openInBrowser": "Gitpod: Open in Browser"
}
}
Loading

0 comments on commit bc7dead

Please sign in to comment.