Skip to content

Commit c526268

Browse files
committed
[jb-remote] hook git credential helper
1 parent b2eb980 commit c526268

File tree

5 files changed

+117
-23
lines changed

5 files changed

+117
-23
lines changed

components/ide/jetbrains/backend-plugin/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ platformVersion=213-EAP-SNAPSHOT
1616
platformDownloadSources=true
1717
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1818
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
19-
platformPlugins=
19+
platformPlugins=Git4Idea
2020
# Opt-out flag for bundling Kotlin standard library.
2121
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
2222
kotlin.stdlib.default.dependency=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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
6+
7+
import com.intellij.notification.NotificationAction
8+
import com.intellij.notification.NotificationGroupManager
9+
import com.intellij.notification.NotificationType
10+
import com.intellij.openapi.Disposable
11+
import com.intellij.openapi.components.Service
12+
import com.intellij.openapi.diagnostic.thisLogger
13+
import com.intellij.remoteDev.util.onTerminationOrNow
14+
import com.jetbrains.rd.util.lifetime.Lifetime
15+
import git4idea.config.GitVcsApplicationSettings
16+
import io.gitpod.jetbrains.remote.services.SupervisorInfoService
17+
import io.gitpod.supervisor.api.Notification.NotifyRequest
18+
import io.gitpod.supervisor.api.Notification.NotifyResponse
19+
import io.gitpod.supervisor.api.Notification.RespondRequest
20+
import io.gitpod.supervisor.api.Notification.SubscribeRequest
21+
import io.gitpod.supervisor.api.Notification.SubscribeResponse
22+
import io.gitpod.supervisor.api.NotificationServiceGrpc
23+
import io.grpc.stub.ClientCallStreamObserver
24+
import io.grpc.stub.ClientResponseObserver
25+
import io.grpc.stub.StreamObserver
26+
import kotlinx.coroutines.GlobalScope
27+
import kotlinx.coroutines.future.await
28+
import kotlinx.coroutines.isActive
29+
import kotlinx.coroutines.launch
30+
import java.util.concurrent.CancellationException
31+
import java.util.concurrent.CompletableFuture
32+
import kotlinx.coroutines.*
33+
34+
@Service
35+
class GitpodManager : Disposable {
36+
37+
init {
38+
GitVcsApplicationSettings.getInstance().isUseCredentialHelper = true
39+
}
40+
41+
private val lifetime = Lifetime.Eternal.createNested()
42+
43+
private val notificationGroup = NotificationGroupManager.getInstance().getNotificationGroup("Gitpod Notifications")
44+
private val notificationsJob = GlobalScope.launch {
45+
val notifications = NotificationServiceGrpc.newStub(SupervisorInfoService.channel)
46+
val futureNotifications = NotificationServiceGrpc.newFutureStub(SupervisorInfoService.channel)
47+
while (isActive) {
48+
try {
49+
val f = CompletableFuture<Void>()
50+
notifications.subscribe(SubscribeRequest.newBuilder().build(), object : ClientResponseObserver<SubscribeRequest, SubscribeResponse> {
51+
52+
override fun beforeStart(requestStream: ClientCallStreamObserver<SubscribeRequest>) {
53+
// TODO(ak): actually should be bound to cancellation of notifications job
54+
lifetime.onTerminationOrNow {
55+
requestStream.cancel(null, null)
56+
}
57+
}
58+
59+
override fun onNext(n: SubscribeResponse) {
60+
val request = n.request
61+
val type = when (request.level) {
62+
NotifyRequest.Level.ERROR -> NotificationType.ERROR
63+
NotifyRequest.Level.WARNING -> NotificationType.WARNING
64+
else -> NotificationType.INFORMATION
65+
}
66+
val notification = notificationGroup.createNotification(request.message, type)
67+
for (action in request.actionsList) {
68+
notification.addAction(NotificationAction.createSimple(action) {
69+
futureNotifications.respond(RespondRequest.newBuilder()
70+
.setRequestId(n.requestId)
71+
.setResponse(NotifyResponse.newBuilder().setAction(action).build())
72+
.build())
73+
})
74+
}
75+
notification.notify(null)
76+
}
77+
78+
override fun onError(t: Throwable) {
79+
f.completeExceptionally(t)
80+
}
81+
82+
override fun onCompleted() {
83+
f.complete(null)
84+
}
85+
})
86+
f.await()
87+
} catch (t: Throwable) {
88+
if (t is CancellationException) {
89+
throw t
90+
}
91+
thisLogger().error("gitpod: failed to stream notifications: ", t)
92+
}
93+
delay(1000L)
94+
}
95+
}
96+
init {
97+
lifetime.onTerminationOrNow {
98+
notificationsJob.cancel()
99+
}
100+
}
101+
102+
override fun dispose() {
103+
lifetime.terminate()
104+
}
105+
}

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

-16
This file was deleted.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object SupervisorInfoService {
1717
private const val SUPERVISOR_ADDRESS = "localhost:22999"
1818

1919
// there should be only one channel per an application to avoid memory leak
20-
private val channel = ManagedChannelBuilder.forTarget(SUPERVISOR_ADDRESS).usePlaintext().build()
20+
val channel = ManagedChannelBuilder.forTarget(SUPERVISOR_ADDRESS).usePlaintext().build()
2121

2222
data class Result(
2323
val infoResponse: io.gitpod.supervisor.api.Info.WorkspaceInfoResponse,

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111

1212
<!-- Product and plugin compatibility requirements -->
1313
<!-- https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
14-
<depends>com.intellij.modules.platform</depends>
14+
<dependencies>
15+
<plugin id="com.intellij.modules.platform"/>
16+
<plugin id="Git4Idea"/>
17+
</dependencies>
18+
19+
<extensions defaultExtensionNs="com.intellij">
20+
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.services.HeartbeatService" preload="true"/>
21+
<applicationService serviceImplementation="io.gitpod.jetbrains.remote.GitpodManager" preload="true"/>
22+
<notificationGroup id="Gitpod Notifications" displayType="STICKY_BALLOON" />
23+
</extensions>
1524

16-
<applicationListeners>
17-
<listener class="io.gitpod.jetbrains.remote.listeners.MyApplicationActivationListener"
18-
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
19-
</applicationListeners>
2025
</idea-plugin>

0 commit comments

Comments
 (0)