-
Notifications
You must be signed in to change notification settings - Fork 502
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
Refactor UpdateInfoUrlFinder
, enhance ForgeType
#3145
Changes from all commits
b42866b
d52d95e
13380eb
fca39d4
905250c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018-2023 Scala Steward contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.scalasteward.core.forge | ||
|
||
import org.http4s.Uri | ||
import org.scalasteward.core.application.Config.ForgeCfg | ||
|
||
/** ForgeRepo encapsulates two concepts that are commonly considered together - the URI of a repo, | ||
* and the 'type' of forge that url represents. Given a URI, once we know it's a GitHub or GitLab | ||
* forge, etc, then we can know how to construct many of the urls for common resources existing at | ||
* that repo host- for instance, the url to view a particular file, or to diff two commits. | ||
*/ | ||
case class ForgeRepo(forgeType: ForgeType, repoUrl: Uri) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: 👏🏼 👏🏼 👏🏼 This comment follows the conventionalcomments.org standard |
||
def diffUrlFor(from: String, to: String): Uri = forgeType.diffs.forDiff(from, to)(repoUrl) | ||
|
||
def fileUrlFor(fileName: String): Uri = forgeType.files.forFile(fileName)(repoUrl) | ||
} | ||
|
||
object ForgeRepo { | ||
def fromRepoUrl(repoUrl: Uri)(implicit config: ForgeCfg): Option[ForgeRepo] = for { | ||
repoForgeType <- ForgeType.fromRepoUrl(repoUrl) | ||
} yield ForgeRepo(repoForgeType, repoUrl) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,12 +18,26 @@ package org.scalasteward.core.forge | |||||
|
||||||
import cats.Eq | ||||||
import cats.syntax.all._ | ||||||
import org.http4s.Uri | ||||||
import org.http4s.syntax.literals._ | ||||||
import org.scalasteward.core.application.Config.ForgeCfg | ||||||
import org.scalasteward.core.forge.ForgeType._ | ||||||
import org.scalasteward.core.util.unexpectedString | ||||||
|
||||||
sealed trait ForgeType extends Product with Serializable { | ||||||
def publicWebHost: Option[String] | ||||||
|
||||||
/** Defines how to construct 'diff' urls for this forge type - ie a url that will show the | ||||||
* difference between two git tags. These can be very useful for understanding the difference | ||||||
* between two releases of the same artifact. | ||||||
*/ | ||||||
val diffs: DiffUriPattern | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quibble: Can we add some ScalaDocs here to explain what this method should do? This comment follows the conventionalcomments.org standard There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, done with 905250c ! |
||||||
|
||||||
/** Defines how to construct 'file' urls for this forge type - ie a url that will display a | ||||||
* specific file's contents. This is useful for linking to Release Notes, etc, in a Scala Steward | ||||||
* PR description. | ||||||
*/ | ||||||
val files: FileUriPattern | ||||||
def supportsForking: Boolean = true | ||||||
def supportsLabels: Boolean = true | ||||||
|
||||||
|
@@ -38,35 +52,61 @@ sealed trait ForgeType extends Product with Serializable { | |||||
} | ||||||
|
||||||
object ForgeType { | ||||||
trait DiffUriPattern { def forDiff(from: String, to: String): Uri => Uri } | ||||||
trait FileUriPattern { def forFile(fileName: String): Uri => Uri } | ||||||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
scala-steward/modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala Lines 88 to 89 in 13380eb
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
|
||||||
case object AzureRepos extends ForgeType { | ||||||
override val publicWebHost: Some[String] = Some("dev.azure.com") | ||||||
override def supportsForking: Boolean = false | ||||||
val diffs: DiffUriPattern = (from, to) => | ||||||
_ / "branchCompare" +? ("baseVersion", s"GT$from") +? ("targetVersion", s"GT$to") | ||||||
val files: FileUriPattern = | ||||||
fileName => | ||||||
_.withQueryParam( | ||||||
"path", | ||||||
fileName | ||||||
) // Azure's canonical value for the path is prefixed with a slash? | ||||||
} | ||||||
|
||||||
case object Bitbucket extends ForgeType { | ||||||
override val publicWebHost: Some[String] = Some("bitbucket.org") | ||||||
override def supportsLabels: Boolean = false | ||||||
val publicApiBaseUrl = uri"https://api.bitbucket.org/2.0" | ||||||
val diffs: DiffUriPattern = (from, to) => _ / "compare" / s"$to..$from" withFragment "diff" | ||||||
val files: FileUriPattern = fileName => _ / "src" / "master" / fileName | ||||||
} | ||||||
|
||||||
/** Note Bitbucket Server will be End Of Service Life on 15th February 2024: | ||||||
* | ||||||
* https://www.atlassian.com/software/bitbucket/enterprise | ||||||
* https://www.atlassian.com/migration/assess/journey-to-cloud | ||||||
*/ | ||||||
case object BitbucketServer extends ForgeType { | ||||||
override val publicWebHost: None.type = None | ||||||
override def supportsForking: Boolean = false | ||||||
override def supportsLabels: Boolean = false | ||||||
val diffs: DiffUriPattern = Bitbucket.diffs | ||||||
val files: FileUriPattern = fileName => _ / "browse" / fileName | ||||||
} | ||||||
|
||||||
case object GitHub extends ForgeType { | ||||||
override val publicWebHost: Some[String] = Some("github.com") | ||||||
val publicApiBaseUrl = uri"https://api.github.com" | ||||||
val diffs: DiffUriPattern = (from, to) => _ / "compare" / s"$from...$to" | ||||||
val files: FileUriPattern = fileName => _ / "blob" / "master" / fileName | ||||||
} | ||||||
|
||||||
case object GitLab extends ForgeType { | ||||||
override val publicWebHost: Some[String] = Some("gitlab.com") | ||||||
val publicApiBaseUrl = uri"https://gitlab.com/api/v4" | ||||||
val diffs: DiffUriPattern = GitHub.diffs | ||||||
val files: FileUriPattern = GitHub.files | ||||||
} | ||||||
|
||||||
case object Gitea extends ForgeType { | ||||||
override val publicWebHost: Option[String] = None | ||||||
val diffs: DiffUriPattern = GitHub.diffs | ||||||
val files: FileUriPattern = fileName => _ / "src" / "branch" / "master" / fileName | ||||||
} | ||||||
|
||||||
val all: List[ForgeType] = List(AzureRepos, Bitbucket, BitbucketServer, GitHub, GitLab, Gitea) | ||||||
|
@@ -83,6 +123,16 @@ object ForgeType { | |||||
def fromPublicWebHost(host: String): Option[ForgeType] = | ||||||
all.find(_.publicWebHost.contains_(host)) | ||||||
|
||||||
/** Attempts to guess, based on the uri host and the config used to launch Scala Steward, what | ||||||
* type of forge hosts the repo at the supplied uri. | ||||||
*/ | ||||||
def fromRepoUrl(repoUrl: Uri)(implicit config: ForgeCfg): Option[ForgeType] = | ||||||
repoUrl.host.flatMap { repoHost => | ||||||
Option | ||||||
.when(config.apiHost.host.contains(repoHost))(config.tpe) | ||||||
.orElse(fromPublicWebHost(repoHost.value)) | ||||||
} | ||||||
|
||||||
implicit val forgeTypeEq: Eq[ForgeType] = | ||||||
Eq.fromUniversalEquals | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: 👏🏼 👏🏼
This comment follows the conventionalcomments.org standard