Skip to content

Commit b1d585c

Browse files
felladrinAndrea Falzetti
authored and
Andrea Falzetti
committed
Add Gitpod-related actions to JetBrains IDEs
1 parent 2814f38 commit b1d585c

21 files changed

+533
-4
lines changed

components/gitpod-protocol/java/src/main/java/io/gitpod/gitpodprotocol/api/GitpodServer.java

+12
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ public interface GitpodServer {
3737

3838
@JsonRequest
3939
CompletableFuture<WorkspaceInstancePort> openPort(String workspaceId, WorkspaceInstancePort port);
40+
41+
@JsonRequest
42+
CompletableFuture<String> takeSnapshot(TakeSnapshotOptions options);
43+
44+
@JsonRequest
45+
CompletableFuture<Void> waitForSnapshot(String snapshotId);
46+
47+
@JsonRequest
48+
CompletableFuture<SetWorkspaceTimeoutResult> setWorkspaceTimeout(String workspaceId, String duration);
49+
50+
@JsonRequest
51+
CompletableFuture<Void> stopWorkspace(String workspaceId);
4052
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.gitpodprotocol.api.entities;
6+
7+
public enum Error {
8+
NOT_FOUND(404),
9+
SNAPSHOT_ERROR(630);
10+
11+
private int errCode;
12+
13+
Error(int errCode) {
14+
this.errCode = errCode;
15+
}
16+
17+
public int getErrCode() {
18+
return errCode;
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.gitpodprotocol.api.entities;
6+
7+
public class SetWorkspaceTimeoutResult {
8+
private String[] resetTimeoutOnWorkspaces;
9+
10+
public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces) {
11+
this.resetTimeoutOnWorkspaces = resetTimeoutOnWorkspaces;
12+
}
13+
14+
public String[] getResetTimeoutOnWorkspaces() {
15+
return resetTimeoutOnWorkspaces;
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.gitpodprotocol.api.entities;
6+
7+
public class TakeSnapshotOptions {
8+
private String workspaceId;
9+
private String layoutData;
10+
private boolean dontWait;
11+
12+
public TakeSnapshotOptions(final String workspaceId, final String layoutData, final Boolean dontWait) {
13+
this.workspaceId = workspaceId;
14+
this.layoutData = layoutData;
15+
this.dontWait = dontWait;
16+
}
17+
18+
public TakeSnapshotOptions(final String workspaceId, final Boolean dontWait) {
19+
this.workspaceId = workspaceId;
20+
this.dontWait = dontWait;
21+
}
22+
23+
public String getLayoutData() {
24+
return layoutData;
25+
}
26+
27+
public void setLayoutData(String layoutData) {
28+
this.layoutData = layoutData;
29+
}
30+
31+
public String getWorkspaceId() {
32+
return workspaceId;
33+
}
34+
35+
public void setWorkspaceId(String workspaceId) {
36+
this.workspaceId = workspaceId;
37+
}
38+
39+
public boolean isDontWait() {
40+
return dontWait;
41+
}
42+
43+
public void setDontWait(boolean dontWait) {
44+
this.dontWait = dontWait;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.gitpodprotocol.api.entities;
6+
7+
public enum WorkspaceTimeoutDuration {
8+
DURATION_SHORT("short"),
9+
DURATION_LONG("long"),
10+
DURATION_EXTENDED("extended"),
11+
DURATION_180M("180m"); // for backwards compatibility since the IDE uses this
12+
13+
private String value;
14+
15+
WorkspaceTimeoutDuration(String value) {
16+
this.value = value;
17+
}
18+
19+
public String toString() {
20+
return value;
21+
}
22+
}

components/ide/jetbrains/backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/GitpodManager.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.gitpod.jetbrains.remote
66

7+
import com.intellij.ide.BrowserUtil
78
import com.intellij.ide.plugins.PluginManagerCore
89
import com.intellij.notification.NotificationAction
910
import com.intellij.notification.NotificationGroupManager
@@ -53,6 +54,7 @@ import java.util.concurrent.CancellationException
5354
import java.util.concurrent.CompletableFuture
5455
import javax.websocket.DeploymentException
5556

57+
@Suppress("UnstableApiUsage", "OPT_IN_USAGE")
5658
@Service
5759
class GitpodManager : Disposable {
5860

@@ -258,9 +260,12 @@ class GitpodManager : Disposable {
258260
val tokenResponse = retry(3) {
259261
val request = Token.GetTokenRequest.newBuilder()
260262
.setHost(info.gitpodApi.host)
263+
.addScope("function:openPort")
261264
.addScope("function:sendHeartBeat")
265+
.addScope("function:setWorkspaceTimeout")
266+
.addScope("function:stopWorkspace")
267+
.addScope("function:takeSnapshot")
262268
.addScope("function:trackEvent")
263-
.addScope("function:openPort")
264269
.setKind("gitpod")
265270
.build()
266271

@@ -393,4 +398,10 @@ class GitpodManager : Disposable {
393398
metricsJob.cancel()
394399
}
395400
}
401+
402+
/** Opens the give URL in the Browser and records an event indicating it was open from a custom IntelliJ Action. */
403+
fun openUrlFromAction(url: String) {
404+
trackEvent("jb_perform_action_open_url", mapOf("url" to url))
405+
BrowserUtil.browse(url)
406+
}
396407
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
import org.apache.http.client.utils.URIBuilder
12+
13+
class AccessControlAction : AnAction() {
14+
private val manager = service<GitpodManager>()
15+
16+
override fun actionPerformed(event: AnActionEvent) {
17+
manager.pendingInfo.thenAccept { workspaceInfo ->
18+
URIBuilder(workspaceInfo.gitpodHost).setPath("integrations").build().toString().let { url ->
19+
manager.openUrlFromAction(url)
20+
}
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class CommunityChatAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.openUrlFromAction("https://www.gitpod.io/chat")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class ContextAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.pendingInfo.thenAccept { workspaceInfo ->
17+
manager.openUrlFromAction(workspaceInfo.workspaceContextUrl)
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class DashboardAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.pendingInfo.thenAccept { workspaceInfo ->
17+
manager.openUrlFromAction(workspaceInfo.gitpodHost)
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class DocumentationAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.openUrlFromAction("https://www.gitpod.io/docs")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import com.intellij.openapi.diagnostic.thisLogger
11+
import io.gitpod.gitpodprotocol.api.entities.WorkspaceTimeoutDuration
12+
import io.gitpod.jetbrains.remote.GitpodManager
13+
import com.intellij.notification.NotificationType
14+
15+
class ExtendWorkspaceTimeoutAction : AnAction() {
16+
private val manager = service<GitpodManager>()
17+
18+
override fun actionPerformed(event: AnActionEvent) {
19+
manager.pendingInfo.thenAccept { workspaceInfo ->
20+
manager.trackEvent("jb_execute_command_gitpod_workspace", mapOf(
21+
"action" to "extend-timeout"
22+
))
23+
24+
manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, WorkspaceTimeoutDuration.DURATION_180M.toString()).whenComplete { result, e ->
25+
var message: String
26+
var notificationType: NotificationType
27+
28+
if (e != null) {
29+
message = "Cannot extend workspace timeout: ${e.message}"
30+
notificationType = NotificationType.ERROR
31+
thisLogger().error("gitpod: failed to extend workspace timeout", e)
32+
} else {
33+
if (result.resetTimeoutOnWorkspaces.isNotEmpty()) {
34+
message = "Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces."
35+
notificationType = NotificationType.WARNING
36+
} else {
37+
message = "Workspace timeout has been extended to three hours."
38+
notificationType = NotificationType.INFORMATION
39+
}
40+
}
41+
42+
val notification = manager.notificationGroup.createNotification(message, notificationType)
43+
notification.notify(null)
44+
}
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class FollowUsOnTwitterAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.openUrlFromAction("https://twitter.com/gitpod")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
12+
class ReportIssueAction : AnAction() {
13+
private val manager = service<GitpodManager>()
14+
15+
override fun actionPerformed(event: AnActionEvent) {
16+
manager.openUrlFromAction("https://github.com/gitpod-io/gitpod/issues/new/choose")
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote.actions
6+
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.components.service
10+
import io.gitpod.jetbrains.remote.GitpodManager
11+
import org.apache.http.client.utils.URIBuilder
12+
13+
class SettingsAction : AnAction() {
14+
private val manager = service<GitpodManager>()
15+
16+
override fun actionPerformed(event: AnActionEvent) {
17+
manager.pendingInfo.thenAccept { workspaceInfo ->
18+
URIBuilder(workspaceInfo.gitpodHost).setPath("settings").build().toString().let { url ->
19+
manager.openUrlFromAction(url)
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)