Skip to content

Commit 8a9fb4f

Browse files
authored
Use segment library to send events (#7)
* Fixes gitpod-io/gitpod#16512
1 parent 3b076b9 commit 8a9fb4f

26 files changed

+1059
-484
lines changed

.github/workflows/gitpod-web-docker.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,31 @@ jobs:
2323
node-version: 16
2424
cache: 'yarn'
2525
cache-dependency-path: '**/yarn.lock'
26+
2627
- name: Execute yarn
2728
run: |
2829
yarn --frozen-lockfile
30+
31+
- name: Update Segment
32+
working-directory: ./gitpod-web
33+
run: |
34+
set -e
35+
setSegmentKey="setpath([\"segmentKey\"]; \"${{ secrets.ANALITYCS_KEY }}\")"
36+
jqCommands="${setSegmentKey}"
37+
cat package.json | jq "${jqCommands}" > package.json.tmp
38+
mv package.json.tmp package.json
39+
2940
- name: Build
3041
run: |
3142
yarn run build:gitpod-web
43+
3244
- name: Docker build and push
3345
uses: docker/build-push-action@v3
3446
with:
3547
push: true
3648
context: gitpod-web
3749
tags: eu.gcr.io/gitpod-core-dev/build/ide/gitpod-code-web:commit-${{ github.sha }}
50+
3851
- name: Output the image tag to the GitHub Summary
3952
run: |
4053
echo "Successfully built the \`gitpod-web\` extension with the tag:" >> summary.md

.github/workflows/release-gitpod-remote.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ jobs:
1717
run: |
1818
yarn install --frozen-lockfile
1919
20+
- name: Update Segment
21+
working-directory: ./gitpod-remote
22+
run: |
23+
set -e
24+
setSegmentKey="setpath([\"segmentKey\"]; \"${{ secrets.ANALITYCS_KEY }}\")"
25+
jqCommands="${setSegmentKey}"
26+
cat package.json | jq "${jqCommands}" > package.json.tmp
27+
mv package.json.tmp package.json
28+
2029
- name: Package extension
2130
id: package_vsix
2231
run: |

gitpod-remote/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"*"
3737
],
3838
"main": "./out/extension.js",
39+
"segmentKey": "YErmvd89wPsrCuGcVnF2XAl846W9WIGl",
3940
"contributes": {
4041
"commands": [
4142
{

gitpod-remote/src/extension.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GitpodExtensionContext, registerTasks, setupGitpodContext, registerIpcH
66
import * as path from 'path';
77
import * as vscode from 'vscode';
88
import { configureMachineSettings } from './machineSettings';
9-
import { registerPortCommands, tunnelPorts } from './ports';
9+
import { tunnelPorts } from './ports';
1010
import { GitpodPortViewProvider } from './portViewProvider';
1111
import { initializeRemoteExtensions, installInitialExtensions, ISyncExtension } from './remoteExtensionInit';
1212

@@ -17,10 +17,10 @@ export async function activate(context: vscode.ExtensionContext) {
1717
return;
1818
}
1919

20+
registerCommands(gitpodContext);
2021
registerTasks(gitpodContext);
2122
installInitialExtensions(gitpodContext);
2223

23-
registerPortCommands(gitpodContext);
2424
const portViewProvider = new GitpodPortViewProvider(gitpodContext);
2525
context.subscriptions.push(vscode.window.registerWebviewViewProvider(GitpodPortViewProvider.viewType, portViewProvider, { webviewOptions: { retainContextWhenHidden: true } }));
2626

@@ -45,14 +45,6 @@ export async function activate(context: vscode.ExtensionContext) {
4545
// and gitpod.gitpod to disable auto tunneling from the current local machine.
4646
vscode.commands.executeCommand('gitpod.api.autoTunnel', gitpodContext.info.gitpodHost, gitpodContext.info.instanceId, false);
4747

48-
// For collecting logs, will be called by gitpod-desktop extension;
49-
context.subscriptions.push(vscode.commands.registerCommand('__gitpod.getGitpodRemoteLogsUri', () => {
50-
return context.logUri;
51-
}));
52-
53-
// Initialize remote extensions
54-
context.subscriptions.push(vscode.commands.registerCommand('__gitpod.initializeRemoteExtensions', (extensions: ISyncExtension[]) => initializeRemoteExtensions(extensions, gitpodContext!)));
55-
5648
// TODO
5749
// - auth?
5850
// - .gitpod.yml validations
@@ -62,17 +54,14 @@ export async function activate(context: vscode.ExtensionContext) {
6254
await gitpodContext.active;
6355
}
6456

65-
export function deactivate() {
66-
if (!gitpodContext) {
67-
return;
68-
}
69-
return gitpodContext.dispose();
57+
export async function deactivate() {
58+
await gitpodContext?.dispose();
7059
}
7160

7261
/**
7362
* configure CLI in regular terminals
7463
*/
75-
export function registerCLI(context: GitpodExtensionContext): void {
64+
function registerCLI(context: GitpodExtensionContext): void {
7665
context.environmentVariableCollection.replace('EDITOR', 'code');
7766
context.environmentVariableCollection.replace('VISUAL', 'code');
7867
context.environmentVariableCollection.replace('GP_OPEN_EDITOR', 'code');
@@ -86,3 +75,22 @@ export function registerCLI(context: GitpodExtensionContext): void {
8675
}
8776
context.environmentVariableCollection.replace('GITPOD_REMOTE_CLI_IPC', ipcHookCli);
8877
}
78+
79+
function registerCommands(context: GitpodExtensionContext) {
80+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.openInBrowser', () => {
81+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_change_vscode_type', {
82+
...context.getWorkspaceTelemetryProperties(),
83+
targetUiKind: 'web'
84+
});
85+
const url = context.info.workspaceUrl;
86+
return vscode.env.openExternal(vscode.Uri.parse(url));
87+
}));
88+
89+
// For collecting logs, will be called by gitpod-desktop extension;
90+
context.subscriptions.push(vscode.commands.registerCommand('__gitpod.getGitpodRemoteLogsUri', () => {
91+
return context.logUri;
92+
}));
93+
94+
// Initialize remote extensions
95+
context.subscriptions.push(vscode.commands.registerCommand('__gitpod.initializeRemoteExtensions', (extensions: ISyncExtension[]) => initializeRemoteExtensions(extensions, gitpodContext!)));
96+
}

gitpod-remote/src/portViewProvider.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import * as vscode from 'vscode';
55
import { GitpodExtensionContext, ExposedServedGitpodWorkspacePort, GitpodWorkspacePort, isExposedServedGitpodWorkspacePort, isExposedServedPort, PortInfo, TunnelDescriptionI } from 'gitpod-shared';
66
import { PortsStatus } from '@gitpod/supervisor-api-grpc/lib/status_pb';
7+
import { TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
78

89
const PortCommands = <const>['tunnelNetwork', 'tunnelHost', 'makePublic', 'makePrivate', 'preview', 'openBrowser', 'retryAutoExpose', 'urlCopy', 'queryPortData'];
910

1011
type PortCommand = typeof PortCommands[number];
1112

13+
interface PortItem { port: GitpodWorkspacePort }
14+
1215
const supportedCommands = [...PortCommands].filter(e => e !== 'preview');
1316

1417
export class GitpodPortViewProvider implements vscode.WebviewViewProvider {
@@ -25,7 +28,48 @@ export class GitpodPortViewProvider implements vscode.WebviewViewProvider {
2528
private readonly onDidChangePortsEmitter = new vscode.EventEmitter<Map<number, GitpodWorkspacePort>>();
2629
readonly onDidChangePorts = this.onDidChangePortsEmitter.event;
2730

28-
constructor(private readonly context: GitpodExtensionContext) { }
31+
constructor(private readonly context: GitpodExtensionContext) {
32+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePrivate', ({ port }: PortItem) => {
33+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
34+
...context.getWorkspaceTelemetryProperties(),
35+
action: 'private'
36+
});
37+
context?.setPortVisibility(port.status.localPort, 'private');
38+
}));
39+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePublic', ({ port }: PortItem) => {
40+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
41+
...context.getWorkspaceTelemetryProperties(),
42+
action: 'public'
43+
});
44+
context?.setPortVisibility(port.status.localPort, 'public');
45+
}));
46+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.preview', ({ port }: PortItem) => {
47+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
48+
...context.getWorkspaceTelemetryProperties(),
49+
action: 'preview'
50+
});
51+
vscode.commands.executeCommand('simpleBrowser.api.open', port.externalUrl.toString(), {
52+
viewColumn: vscode.ViewColumn.Beside,
53+
preserveFocus: true
54+
});
55+
}));
56+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.openBrowser', ({ port }: PortItem) => {
57+
context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
58+
...context.getWorkspaceTelemetryProperties(),
59+
action: 'openBrowser'
60+
});
61+
vscode.env.openExternal(vscode.Uri.parse(port.localUrl));
62+
}));
63+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.tunnelNetwork', ({ port }: PortItem) => {
64+
context.supervisor.setTunnelVisibility(port.portNumber, port.portNumber, TunnelVisiblity.NETWORK);
65+
}));
66+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.tunnelHost', async ({ port }: PortItem) =>
67+
context.supervisor.setTunnelVisibility(port.portNumber, port.portNumber, TunnelVisiblity.HOST)
68+
));
69+
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.retryAutoExpose', ({ port }: PortItem) => {
70+
context.supervisor.retryAutoExposePort(port.portNumber);
71+
}));
72+
}
2973

3074
// @ts-ignore
3175
resolveWebviewView(webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext<unknown>, token: vscode.CancellationToken): void | Thenable<void> {
@@ -121,9 +165,9 @@ export class GitpodPortViewProvider implements vscode.WebviewViewProvider {
121165
if (!port) { return; }
122166
if (message.command === 'urlCopy' && port.status.exposed) {
123167
await vscode.env.clipboard.writeText(port.status.exposed.url);
124-
this.context.fireAnalyticsEvent({
125-
eventName: 'vscode_execute_command_gitpod_ports',
126-
properties: { action: 'urlCopy' }
168+
this.context.telemetryService.sendTelemetryEvent('vscode_execute_command_gitpod_ports', {
169+
...this.context.getWorkspaceTelemetryProperties(),
170+
action: 'urlCopy'
127171
});
128172
return;
129173
}

gitpod-remote/src/ports.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
* Copyright (c) Gitpod. All rights reserved.
33
*--------------------------------------------------------------------------------------------*/
44
import * as vscode from 'vscode';
5-
import { GitpodExtensionContext, GitpodWorkspacePort } from 'gitpod-shared';
65
import { PortsStatus } from '@gitpod/supervisor-api-grpc/lib/status_pb';
7-
import { TunnelVisiblity } from '@gitpod/supervisor-api-grpc/lib/port_pb';
86

97
export async function tunnelPorts(supervisorPortList: PortsStatus.AsObject[]) {
108
for (const port of supervisorPortList) {
@@ -13,48 +11,3 @@ export async function tunnelPorts(supervisorPortList: PortsStatus.AsObject[]) {
1311
}
1412
}
1513
}
16-
17-
interface PortItem { port: GitpodWorkspacePort }
18-
19-
export function registerPortCommands(context: GitpodExtensionContext) {
20-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePrivate', ({ port }: PortItem) => {
21-
context.fireAnalyticsEvent({
22-
eventName: 'vscode_execute_command_gitpod_ports',
23-
properties: { action: 'private' }
24-
});
25-
context?.setPortVisibility(port.status.localPort, 'private');
26-
}));
27-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.makePublic', ({ port }: PortItem) => {
28-
context.fireAnalyticsEvent({
29-
eventName: 'vscode_execute_command_gitpod_ports',
30-
properties: { action: 'public' }
31-
});
32-
context?.setPortVisibility(port.status.localPort, 'public');
33-
}));
34-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.tunnelNetwork', ({ port }: PortItem) => {
35-
context?.supervisor.setTunnelVisibility(port.portNumber, port.portNumber, TunnelVisiblity.NETWORK);
36-
}));
37-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.tunnelHost', async ({ port }: PortItem) =>
38-
context?.supervisor.setTunnelVisibility(port.portNumber, port.portNumber, TunnelVisiblity.HOST)
39-
));
40-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.preview', ({ port }: PortItem) => {
41-
context.fireAnalyticsEvent({
42-
eventName: 'vscode_execute_command_gitpod_ports',
43-
properties: { action: 'preview' }
44-
});
45-
vscode.commands.executeCommand('simpleBrowser.api.open', port.externalUrl.toString(), {
46-
viewColumn: vscode.ViewColumn.Beside,
47-
preserveFocus: true
48-
});
49-
}));
50-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.openBrowser', ({ port }: PortItem) => {
51-
context.fireAnalyticsEvent({
52-
eventName: 'vscode_execute_command_gitpod_ports',
53-
properties: { action: 'openBrowser' }
54-
});
55-
vscode.env.openExternal(vscode.Uri.parse(port.localUrl));
56-
}));
57-
context.subscriptions.push(vscode.commands.registerCommand('gitpod.ports.retryAutoExpose', ({ port }: PortItem) => {
58-
context.supervisor.retryAutoExposePort(port.portNumber);
59-
}));
60-
}

0 commit comments

Comments
 (0)