-
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 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -18,12 +18,16 @@ 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] | ||||||
val diffs: DiffUriPattern | ||||||
val files: FileUriPattern | ||||||
def supportsForking: Boolean = true | ||||||
def supportsLabels: Boolean = true | ||||||
|
||||||
|
@@ -38,35 +42,64 @@ 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" withQueryParams Map( | ||||||
"baseVersion" -> s"GT$from", | ||||||
"targetVersion" -> s"GT$to" | ||||||
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. suggestion: You can also use the operator to add query params _ / "branchCompare" +? ("baseVersion", s"GT$from") +? ("targetVersion", s"GT$to") 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. Ooh, nice one! Updated with fca39d4 👍 |
||||||
) | ||||||
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 +116,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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done with 905250c !