Skip to content

Commit

Permalink
Add Gitpod-related actions to JetBrains IDEs
Browse files Browse the repository at this point in the history
  • Loading branch information
felladrin authored and Andrea Falzetti committed Sep 6, 2022
1 parent dc9fbe4 commit 7ebeabc
Show file tree
Hide file tree
Showing 21 changed files with 516 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public interface GitpodServer {

@JsonRequest
CompletableFuture<WorkspaceInstancePort> openPort(String workspaceId, WorkspaceInstancePort port);

@JsonRequest
CompletableFuture<String> takeSnapshot(TakeSnapshotOptions options);

@JsonRequest
CompletableFuture<Void> waitForSnapshot(String snapshotId);

@JsonRequest
CompletableFuture<SetWorkspaceTimeoutResult> setWorkspaceTimeout(String workspaceId, String duration);

@JsonRequest
CompletableFuture<Void> stopWorkspace(String workspaceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.gitpodprotocol.api.entities;

public enum Error {
SNAPSHOT_ERROR(630);

private int errCode;

Error(int errCode) {
this.errCode = errCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.gitpodprotocol.api.entities;

public class SetWorkspaceTimeoutResult {
private String[] resetTimeoutOnWorkspaces;

public SetWorkspaceTimeoutResult(String[] resetTimeoutOnWorkspaces) {
this.resetTimeoutOnWorkspaces = resetTimeoutOnWorkspaces;
}

public String[] getResetTimeoutOnWorkspaces() {
return resetTimeoutOnWorkspaces;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.gitpodprotocol.api.entities;

public class TakeSnapshotOptions {
private String workspaceId;
private String layoutData;
private boolean dontWait;

public TakeSnapshotOptions(final String workspaceId, final String layoutData, final Boolean dontWait) {
this.workspaceId = workspaceId;
this.layoutData = layoutData;
this.dontWait = dontWait;
}

public TakeSnapshotOptions(final String workspaceId, final Boolean dontWait) {
this.workspaceId = workspaceId;
this.dontWait = dontWait;
}

public String getLayoutData() {
return layoutData;
}

public void setLayoutData(String layoutData) {
this.layoutData = layoutData;
}

public String getWorkspaceId() {
return workspaceId;
}

public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}

public boolean isDontWait() {
return dontWait;
}

public void setDontWait(boolean dontWait) {
this.dontWait = dontWait;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.gitpodprotocol.api.entities;

public enum WorkspaceTimeoutDuration {
DURATION_SHORT("short"),
DURATION_LONG("long"),
DURATION_EXTENDED("extended"),
DURATION_180M("180m"); // for backwards compatibility since the IDE uses this

private String value;

WorkspaceTimeoutDuration(String value) {
this.value = value;
}

public String toString() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.gitpod.jetbrains.remote

import com.intellij.ide.BrowserUtil
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationGroupManager
Expand Down Expand Up @@ -53,6 +54,7 @@ import java.util.concurrent.CancellationException
import java.util.concurrent.CompletableFuture
import javax.websocket.DeploymentException

@Suppress("UnstableApiUsage", "OPT_IN_USAGE")
@Service
class GitpodManager : Disposable {

Expand Down Expand Up @@ -261,6 +263,7 @@ class GitpodManager : Disposable {
.addScope("function:sendHeartBeat")
.addScope("function:trackEvent")
.addScope("function:openPort")
.addScope("function:setWorkspaceTimeout")
.setKind("gitpod")
.build()

Expand Down Expand Up @@ -393,4 +396,10 @@ class GitpodManager : Disposable {
metricsJob.cancel()
}
}

/** Opens the give URL in the Browser and records an event indicating it was open from a custom IntelliJ Action. */
fun openUrlFromAction(url: String) {
trackEvent("jb_perform_action_open_url", mapOf("url" to url))
BrowserUtil.browse(url)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager
import org.apache.http.client.utils.URIBuilder

class AccessControlAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.pendingInfo.thenAccept { workspaceInfo ->
URIBuilder(workspaceInfo.gitpodHost).setPath("integrations").build().toString().let { url ->
manager.openUrlFromAction(url)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class CommunityChatAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.openUrlFromAction("https://www.gitpod.io/chat")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class ContextAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.pendingInfo.thenAccept { workspaceInfo ->
manager.openUrlFromAction(workspaceInfo.workspaceContextUrl)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class DashboardAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.pendingInfo.thenAccept { workspaceInfo ->
manager.openUrlFromAction(workspaceInfo.gitpodHost)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class DocumentationAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.openUrlFromAction("https://www.gitpod.io/docs")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
import io.gitpod.gitpodprotocol.api.entities.WorkspaceTimeoutDuration
import io.gitpod.jetbrains.remote.GitpodManager
import com.intellij.notification.NotificationType

class ExtendWorkspaceTimeoutAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.pendingInfo.thenAccept { workspaceInfo ->
manager.trackEvent("jb_execute_command_gitpod_workspace", mapOf(
"action" to "extend-timeout"
))

manager.client.server.setWorkspaceTimeout(workspaceInfo.workspaceId, WorkspaceTimeoutDuration.DURATION_180M.toString()).whenComplete { result, e ->
var message: String
var notificationType: NotificationType

if (e != null) {
message = "Cannot extend workspace timeout: ${e.message}"
notificationType = NotificationType.ERROR
thisLogger().error("gitpod: failed to extend workspace timeout", e)
} else {
if (result.resetTimeoutOnWorkspaces.isNotEmpty()) {
message = "Workspace timeout has been extended to three hours. This reset the workspace timeout for other workspaces."
notificationType = NotificationType.WARNING
} else {
message = "Workspace timeout has been extended to three hours."
notificationType = NotificationType.INFORMATION
}
}

val notification = manager.notificationGroup.createNotification(message, notificationType)
notification.notify(null)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class FollowUsOnTwitterAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.openUrlFromAction("https://twitter.com/gitpod")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager

class ReportIssueAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.openUrlFromAction("https://github.com/gitpod-io/gitpod/issues/new/choose")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.jetbrains.remote.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import io.gitpod.jetbrains.remote.GitpodManager
import org.apache.http.client.utils.URIBuilder

class SettingsAction : AnAction() {
private val manager = service<GitpodManager>()

override fun actionPerformed(event: AnActionEvent) {
manager.pendingInfo.thenAccept { workspaceInfo ->
URIBuilder(workspaceInfo.gitpodHost).setPath("settings").build().toString().let { url ->
manager.openUrlFromAction(url)
}
}
}
}
Loading

0 comments on commit 7ebeabc

Please sign in to comment.