Skip to content

Commit

Permalink
✨ add GitOpenRemoteRepoAction
Browse files Browse the repository at this point in the history
  • Loading branch information
iml885203 committed Jun 22, 2024
1 parent 9781492 commit ecf7103
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 48 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ repositories {
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
// implementation(libs.exampleLibrary)
implementation(libs.jgit) {
exclude(group = "org.slf4j", module = "slf4j-api")
}
}

// Set the JVM language level used to build the project.
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
# libraries
exampleLibrary = "24.1.0"
jgit = "6.7.0.202309050840-r"

# plugins
kotlin = "1.9.24"
Expand All @@ -11,6 +12,7 @@ kover = "0.8.1"

[libraries]
exampleLibrary = { group = "com.example", name = "exampleLibrary", version.ref = "exampleLibrary" }
jgit = { group = "org.eclipse.jgit", name = "org.eclipse.jgit", version.ref = "jgit" }

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/com/github/iml885203/intellijgitopen/MyNotifier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.iml885203.intellijgitopen

import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project

object MyNotifier {
fun notifyError(project: Project, content: String) {
NotificationGroupManager.getInstance()
.getNotificationGroup("Git Open")
.createNotification(content, NotificationType.ERROR)
.notify(project)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.iml885203.intellijgitopen.actions

import com.github.iml885203.intellijgitopen.MyNotifier
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.diagnostic.thisLogger
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.errors.RepositoryNotFoundException
import org.eclipse.jgit.transport.RemoteConfig
import org.eclipse.jgit.transport.URIish
import java.io.File

class GitOpenRemoteRepoAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
try {
val remoteUrl = getRemoteUrl(project.basePath ?: return)
thisLogger().info("Remote URL: $remoteUrl")
BrowserUtil.browse(remoteUrl)
} catch (ex: RepositoryNotFoundException) {
MyNotifier.notifyError(project, "The Git repository could not be found at the specified location.")
}
}

private fun getRemoteUrl(projectPath: String): String {
val git = Git.open(File(projectPath))
val config = git.repository.config
val remoteConfig = RemoteConfig(config, "origin")
val uris: List<URIish> = remoteConfig.urIs
return uris[0].toString()
}
}

This file was deleted.

14 changes: 11 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<id>com.github.iml885203.intellijgitopen</id>
<name>IntelliJ-git-open</name>
<vendor>iml885203</vendor>
<name>Git Open</name>
<vendor>Logan</vendor>

<depends>com.intellij.modules.platform</depends>

<resource-bundle>messages.MyBundle</resource-bundle>

<extensions defaultExtensionNs="com.intellij">
<toolWindow factoryClass="com.github.iml885203.intellijgitopen.toolWindow.MyToolWindowFactory" id="MyToolWindow"/>
<notificationGroup id="Git Open"
displayType="BALLOON"
key="notification.group.name"/>
</extensions>

<applicationListeners>
<listener class="com.github.iml885203.intellijgitopen.listeners.MyApplicationActivationListener" topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>

<actions>
<action class="com.github.iml885203.intellijgitopen.actions.GitOpenRemoteRepoAction" id="com.github.iml885203.intellijgitopen.actions.GitOpenRemoteRepoAction" text="Git Open Remote Repo">
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt G"/>
</action>
</actions>
</idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
notification.group.name=Git open
projectService=Project service: {0}
randomLabel=The random number is: {0}
shuffle=Shuffle

0 comments on commit ecf7103

Please sign in to comment.