-
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
Merged
alejandrohdezma
merged 5 commits into
scala-steward-org:main
from
rtyley:refactor-UpdateInfoUrlFinder
Aug 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b42866b
Refactor: replace conditionals with polymorphism on `ForgeType`
rtyley d52d95e
Refactor: introduce `ForgeRepo` as a parameter object
rtyley 13380eb
Refactor: introduce `Version.Update` as a parameter object
rtyley fca39d4
Use concise `+?` operator to construct url params
rtyley 905250c
Add Scaladoc on `ForgeType`'s new `diffs` & `files` fields
rtyley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/core/src/main/scala/org/scalasteward/core/forge/ForgeRepo.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
modules/core/src/test/scala/org/scalasteward/core/forge/ForgeRepoTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.scalasteward.core.forge | ||
|
||
import munit.FunSuite | ||
import org.http4s.Uri | ||
import org.http4s.implicits._ | ||
import org.scalasteward.core.forge.ForgeType._ | ||
|
||
/** As much as possible, uris in this test suite should aim to be real, clickable, uris that | ||
* actually go to real pages, allowing developers working against this test suite to verify that | ||
* the url patterns constructed here actually _are_ valid, and match what forges are currently | ||
* using in the real world. | ||
*/ | ||
Comment on lines
+8
to
+12
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 is gold! This comment follows the conventionalcomments.org standard |
||
class ForgeRepoTest extends FunSuite { | ||
|
||
def check( | ||
repo: ForgeRepo, | ||
expectedReadme: Uri, | ||
diffTags: (String, String), | ||
expectedDiff: Uri | ||
): Unit = { | ||
assertEquals(repo.fileUrlFor("README.md"), expectedReadme) | ||
assertEquals(repo.diffUrlFor(diffTags._1, diffTags._2), expectedDiff) | ||
} | ||
|
||
test("GitHub url patterns") { | ||
check( | ||
ForgeRepo(GitHub, uri"https://github.com/scala-steward-org/scala-steward-action"), | ||
uri"https://github.com/scala-steward-org/scala-steward-action/blob/master/README.md", | ||
"v2.55.0" -> "v2.56.0", | ||
uri"https://github.com/scala-steward-org/scala-steward-action/compare/v2.55.0...v2.56.0" | ||
) | ||
} | ||
|
||
test("GitLab url patterns") { | ||
check( | ||
ForgeRepo(GitLab, uri"https://gitlab.com/gitlab-org/gitlab"), | ||
uri"https://gitlab.com/gitlab-org/gitlab/blob/master/README.md", | ||
"v15.11.8-ee" -> "v15.11.9-ee", | ||
uri"https://gitlab.com/gitlab-org/gitlab/compare/v15.11.8-ee...v15.11.9-ee" | ||
) | ||
} | ||
|
||
test("Gitea url patterns") { | ||
check( | ||
ForgeRepo(Gitea, uri"https://gitea.com/lunny/levelqueue"), | ||
uri"https://gitea.com/lunny/levelqueue/src/branch/master/README.md", | ||
"v0.1.0" -> "v0.2.0", | ||
uri"https://gitea.com/lunny/levelqueue/compare/v0.1.0...v0.2.0" | ||
) | ||
} | ||
|
||
test("Azure url patterns") { | ||
check( | ||
ForgeRepo( | ||
AzureRepos, | ||
uri"https://dev.azure.com/rtyley/scala-steward-testing/_git/scala-steward-testing" | ||
), | ||
uri"https://dev.azure.com/rtyley/scala-steward-testing/_git/scala-steward-testing?path=README.md", | ||
"v1.0.0" -> "v1.0.1", | ||
uri"https://dev.azure.com/rtyley/scala-steward-testing/_git/scala-steward-testing/branchCompare?baseVersion=GTv1.0.0&targetVersion=GTv1.0.1" | ||
) | ||
} | ||
|
||
test("BitBucket url patterns") { | ||
check( | ||
ForgeRepo(Bitbucket, uri"https://bitbucket.org/rtyley/scala-steward-test-repo"), | ||
uri"https://bitbucket.org/rtyley/scala-steward-test-repo/src/master/README.md", | ||
"v1.0.0" -> "v1.0.1", | ||
uri"https://bitbucket.org/rtyley/scala-steward-test-repo/compare/v1.0.1..v1.0.0#diff" | ||
) | ||
} | ||
|
||
test("BitBucket Server url patterns") { | ||
check( | ||
ForgeRepo(BitbucketServer, uri"https://bitbucket-server.on-prem.com/foo/bar"), | ||
uri"https://bitbucket-server.on-prem.com/foo/bar/browse/README.md", | ||
"v1.0.0" -> "v1.0.1", | ||
uri"https://bitbucket-server.on-prem.com/foo/bar/compare/v1.0.1..v1.0.0#diff" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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