kawamataryo / copy-git-link

Provides a shortcut to copy permalink in their online Git repositories.
https://plugins.jetbrains.com/plugin/17756-copy-git-link
25 stars 13 forks source link

Nulls in link #29

Open kkolyan opened 3 months ago

kkolyan commented 3 months ago

In new IDEA version it generates URL with nulls instead of some critical URL parts: https://nullnull/null/blob/147b777baa25147742e85e1b9242051efe354e9f/GlipBot.postman_collection.json#L3

IntelliJ IDEA 2024.1 (Ultimate Edition)
Build #IU-241.14494.240, built on March 28, 2024
Licensed to RingCentral, Inc. /  
Subscription is active until January 3, 2025.
Runtime version: 17.0.10+8-b1207.12 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.4.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
Metal Rendering is ON
Registry:
  analyze.exceptions.on.the.fly=true
  ide.experimental.ui=true
  terminal.new.ui=true
  scala.erase.compiler.process.jdk.once=false
  org.toml.json.schema=false
Non-Bundled Plugins:
  net.sjrx.intellij.plugins.systemdunitfiles (223.240127.136)
  me.mbolotov.json.schema.generator (1.1)
  com.jetbrains.rust (241.25989.180)
  com.vermouthx.idea (1.16.0)
  org.jetbrains.plugins.go-template (241.14494.150)
  com.khmelyuk.multirun (1.14.1)
  com.markskelton.one-dark-theme (5.10.0)
  name.kropp.intellij.makefile (241.14494.150)
  org.jetbrains.plugins.go (241.14494.240)
  org.jetbrains.plugins.ruby (241.14494.240)
  Pythonid (241.14494.314)
  com.intellij.nativeDebug (241.14494.234)
  com.intellij.mermaid (0.0.21+IJ.232)
  ru.artyushov (1.5.0)
  com.intellij.ml.llm (241.14494.320)
  ru.meanmail.plugin.requirements (2022.4.1)
  com.intellij.bigdatatools.core (241.14494.240)
  com.github.kawamataryo.copygithublink (0.5.3)
  com.google.gct.core (24.4.3-api-version-223)
  com.intellij.bigdatatools.kafka (241.14494.158)
  com.jetbrains.php (241.14494.240)
  org.intellij.scala (2024.1.20)
Kotlin: 241.14494.240-IJ
yusefnapora commented 3 months ago

I'm also getting nulls in the URL, which in my case I think is related to having . characters in the path before the .git extension, as in this comment.

I looked a bit at the regex in https://github.com/kawamataryo/copy-git-link/blob/main/src/main/kotlin/com/github/kawamataryo/copygitlink/utils/utils.kt#L41 and it seems like you could simplify things by just grabbing everything after the host & port and then removing any .git suffix from the path afterwards. So something like:

fun getRepositoryPathFromRemoteUrl(
    remoteUrl: String,
): String {
    val result =
        Regex(".*(?:@|//)(.[^:/]*)(:?:[0-9]{1,4})?(.*)\$").matchEntire(
            remoteUrl
        )
    val path = result?.groupValues?.get(3)?.removeSuffix(".git") ?: ""
    return result?.groupValues?.get(1) + result?.groupValues?.get(2) + "/" + path
}

I don't have a kotlin environment set up on this machine, but if you like I could make a little PR to that effect this weekend.

dustinblue commented 2 weeks ago

Been having this null issue then realized there is built in support for this, at least PHPStorm. Highlight a line right-click, open in Github

image