Skip to content

Commit

Permalink
compatibility update
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpessu committed Sep 3, 2024
1 parent e7490a3 commit 2fb3207
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pluginGroup = com.github.adrienpessu.sarifviewer
pluginName = SARIF-viewer
pluginRepositoryUrl = https://github.com/adrienpessu/SARIF-viewer
# SemVer format -> https://semver.org
pluginVersion = 1.2.1
pluginVersion = 1.2.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
pluginUntilBuild = 241.*
pluginUntilBuild = 242.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.github.adrienpessu.sarifviewer.utils.GitHubInstance
import com.intellij.openapi.components.Service
import com.intellij.util.alsoIfNull
import java.net.HttpURLConnection
import java.net.URL
import java.net.URI


@Service(Service.Level.PROJECT)
Expand Down Expand Up @@ -117,7 +117,8 @@ class SarifService {

fun getPullRequests(github: GitHubInstance, repositoryFullName: String, branchName: String = "main"): List<*>? {
val head = "${repositoryFullName.split("/")[0]}:$branchName"
val connection = URL("${github.apiBase}/repos/$repositoryFullName/pulls?state=open&head=$head")
val connection = URI("${github.apiBase}/repos/$repositoryFullName/pulls?state=open&head=$head")
.toURL()
.openConnection() as HttpURLConnection

connection.apply {
Expand Down Expand Up @@ -145,7 +146,8 @@ class SarifService {
): String {

val s = "${github.apiBase}/repos/$repositoryFullName/code-scanning/analyses?ref=$branchName"
val connection = URL(s)
val connection = URI(s)
.toURL()
.openConnection() as HttpURLConnection

connection.apply {
Expand Down Expand Up @@ -188,7 +190,8 @@ class SarifService {
}

private fun getSarifFromGitHub(github: GitHubInstance, repositoryFullName: String, analysisId: Int): String {
val connection = URL("${github.apiBase}/repos/$repositoryFullName/code-scanning/analyses/$analysisId")
val connection = URI("${github.apiBase}/repos/$repositoryFullName/code-scanning/analyses/$analysisId")
.toURL()
.openConnection() as HttpURLConnection

connection.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.adrienpessu.sarifviewer.utils

import org.jetbrains.annotations.VisibleForTesting
import java.net.URL
import java.net.URI

data class GitHubInstance(val hostname: String, val apiBase: String = "https://$hostname/api/v3") {
// Keep this out of the constructor so that it doesn't accidentally end up in a toString() output
var token: String = ""

fun extractRepoNwo(remoteUrl: String?): String? {
if (remoteUrl?.startsWith("https") == true) {
return URL(remoteUrl).path.replace(Regex("^/"), "").replace(Regex(".git$"), "")
return URI(remoteUrl).path.replace(Regex("^/"), "").replace(Regex(".git$"), "")
} else if (remoteUrl?.startsWith("git@") == true) {
return remoteUrl.replace(Regex("^git@$hostname:"), "").replace(Regex(".git$"), "")
}
Expand All @@ -21,12 +21,13 @@ data class GitHubInstance(val hostname: String, val apiBase: String = "https://$

@VisibleForTesting
fun extractHostname(remoteUrl: String?): String? {
if (remoteUrl?.startsWith("https") == true) {
return URL(remoteUrl).host
return if (remoteUrl?.startsWith("https") == true) {
URI(remoteUrl).host
} else if (remoteUrl?.startsWith("git@") == true) {
return remoteUrl.substringAfter("git@").substringBefore(":")
remoteUrl.substringAfter("git@").substringBefore(":")
} else {
null
}
return null
}

fun fromRemoteUrl(remoteUrl: String): GitHubInstance? {
Expand Down

0 comments on commit 2fb3207

Please sign in to comment.