Skip to content

Add Gitpod-related actions to JetBrains IDEs #12621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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.gitpodprotocol.api.entities;

public enum Error {
NOT_FOUND(404),
SNAPSHOT_ERROR(630);

private int errCode;

Error(int errCode) {
this.errCode = errCode;
}

public int getErrCode() {
return 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 @@ -258,9 +260,12 @@ class GitpodManager : Disposable {
val tokenResponse = retry(3) {
val request = Token.GetTokenRequest.newBuilder()
.setHost(info.gitpodApi.host)
.addScope("function:openPort")
.addScope("function:sendHeartBeat")
.addScope("function:setWorkspaceTimeout")
.addScope("function:stopWorkspace")
.addScope("function:takeSnapshot")
.addScope("function:trackEvent")
.addScope("function:openPort")
.setKind("gitpod")
.build()

Expand Down Expand Up @@ -393,4 +398,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_execute_command_gitpod_open_link", 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