Skip to content
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

Fix Azure URL generation #345

Merged
merged 2 commits into from
Sep 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# GitLink Changelog

## Unreleased
- Fix Azure URL generation

## 4.5.1 - 2024-09-03

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = uk.co.ben_gibson.git.link
pluginName = GitLink
# SemVer format -> https://semver.org
pluginVersion = 4.5.1
pluginVersion = 4.5.2

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ val GitRemote.httpUrl : URL? get() {
var url = firstUrl ?: return null

url = url.trim()
.removeSuffix(".git")

// Azure supports a .git suffix on the repo name, so don't remove it.
if (!url.contains("dev.azure")) {
url = url.removeSuffix(".git")
}

// Do not try to remove the port if the URL uses the SSH protocol in the SCP syntax e.g.
// '[email protected]:foo.git' as it does not support port definitions. Attempting to remove the port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class AzureUrlFactory: UrlFactory {
val basePathParts = baseUrl.path
.toString()
.removePrefix("v3/")
.plus(".git") // Azure expects .git after the repo name
.split("/")
.toMutableList()

Expand Down
6 changes: 5 additions & 1 deletion src/test/kotlin/uk/co/ben_gibson/git/link/git/RemoteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class RemoteTest {
Arguments.of(
"xy://custom.gitlab.url/group/project.git",
"http://custom.gitlab.url/group/project"
)
),
Arguments.of(
"http://[email protected]/ben-gibson/test/_git/test.git",
"http://dev.azure.com/ben-gibson/test/_git/test.git"
),
)
}

Expand Down
22 changes: 11 additions & 11 deletions src/test/kotlin/uk/co/ben_gibson/git/link/url/AzureTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class AzureTest {
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH, LINE_SELECTION),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GBmaster&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1"
"https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1"
),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
UrlOptions.UrlOptionsFileAtBranch(FILE, BRANCH),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GBmaster&path=src%2FFoo.java"
"https://dev.azure.com/ben-gibson/_git/test?version=GBmaster&path=src%2FFoo.java"
),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
UrlOptions.UrlOptionsFileAtCommit(FILE, "main", COMMIT, LINE_SELECTION),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1"
"https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java&line=10&lineEnd=21&lineStartColumn=1&lineEndColumn=1"
),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
Expand All @@ -47,7 +47,7 @@ class AzureTest {
"main",
COMMIT
),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2Ffoo%2Fresources"
"https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2Ffoo%2Fresources"
),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
Expand All @@ -56,36 +56,36 @@ class AzureTest {
"main",
COMMIT
),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=%2F"),
"https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=%2F"),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
UrlOptions.UrlOptionsFileAtCommit(FILE, "main", COMMIT),
"https://dev.azure.com/ben-gibson/_git/test.git?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java"
"https://dev.azure.com/ben-gibson/_git/test?version=GCb032a0707beac9a2f24b1b7d97ee4f7156de182c&path=src%2FFoo.java"
),
Arguments.of(
REMOTE_BASE_URL_WITH_GIT,
UrlOptions.UrlOptionsCommit(COMMIT, "main"),
"https://dev.azure.com/ben-gibson/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
"https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
),
Arguments.of(
REMOTE_BASE_URL_WITHOUT_GIT,
UrlOptions.UrlOptionsCommit(COMMIT, "main"),
"https://dev.azure.com/ben-gibson/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
"https://dev.azure.com/ben-gibson/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
),
Arguments.of(
REMOTE_BASE_URL_WITH_COMPANY_AND_GIT,
UrlOptions.UrlOptionsCommit(COMMIT, "main"),
"https://dev.azure.com/company/project/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
"https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
),
Arguments.of(
REMOTE_BASE_URL_WITH_COMPANY_WITHOUT_GIT,
UrlOptions.UrlOptionsCommit(COMMIT, "main"),
"https://dev.azure.com/company/project/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
"https://dev.azure.com/company/project/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
),
Arguments.of(
URL.fromString("https://ssh.dev.azure.com/v3/ben-gibson/test/test"),
UrlOptions.UrlOptionsCommit(COMMIT, "main"),
"https://dev.azure.com/ben-gibson/test/_git/test.git/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
"https://dev.azure.com/ben-gibson/test/_git/test/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c"
)
)
}
Expand Down
Loading