Skip to content

Commit

Permalink
Merge pull request #167 from shiraji/shiraji/fix-commit-url
Browse files Browse the repository at this point in the history
Fix the problem with jumping commit pages
  • Loading branch information
shiraji committed Mar 21, 2024
2 parents 22e1821 + 357003c commit 2545c9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ListPullRequestTextAnnotationGutterProvider(
BrowserUtil.open(url)
} else {
val path = hostingService.urlPathFormat.format(gitPullRequestInfo.prNumber)
val url = model.createUrl(repository, hostingService, path)
val url = model.createPRUrl(repository, hostingService, path)

BrowserUtil.open("$webRepoUrl/$url")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class FindPullRequestModel(

fun createCommitUrl(repository: GitRepository, hostingServices: FindPullRequestHostingServices, webRepoUrl: String, revisionHash: VcsRevisionNumber): String {
val path = hostingServices.commitPathFormat.format(webRepoUrl, revisionHash)
return createUrl(repository, hostingServices, path)
return if (config.isJumpToFile()) {
val fileAnnotation = gitConfService.getFileAnnotation(repository, virtualFile) ?: return path
path + hostingServices.createFileAnchorValue(repository, fileAnnotation)
} else {
path
}
}

fun createPullRequestPath(repository: GitRepository, revisionHash: VcsRevisionNumber): String {
Expand Down Expand Up @@ -68,7 +73,7 @@ class FindPullRequestModel(
}

val path = targetHostingService.urlPathFormat.format(prNumber)
createUrl(repository, targetHostingService, path)
createPRUrl(repository, targetHostingService, path)
} else {
val commit = gitHistoryService.findCommitLog(project, repository, revisionHash)
val hostingServices = FindPullRequestHostingServices.values().firstOrNull {
Expand All @@ -77,14 +82,14 @@ class FindPullRequestModel(

if (hostingServices != null) {
val path = hostingServices.urlPathFormat.format(commit.getNumberFromCommitMessage(hostingServices.squashCommitMessage))
createUrl(repository, hostingServices, path)
createPRUrl(repository, hostingServices, path)
} else {
throw NoPullRequestFoundException(debugMessage.toString())
}
}
}

fun createUrl(repository: GitRepository, hostingServices: FindPullRequestHostingServices, path: String): String {
fun createPRUrl(repository: GitRepository, hostingServices: FindPullRequestHostingServices, path: String): String {
return if (config.isJumpToFile()) {
val fileAnnotation = gitConfService.getFileAnnotation(repository, virtualFile) ?: return path
path + hostingServices.urlPathForDiff + hostingServices.createFileAnchorValue(repository, fileAnnotation)
Expand Down

0 comments on commit 2545c9f

Please sign in to comment.