-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
215 additions
and
52 deletions.
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
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
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
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
modules/core/src/main/scala/org/scalasteward/core/application/ReposFilesLoader.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,50 @@ | ||
/* | ||
* 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.application | ||
|
||
import cats.effect.Sync | ||
import cats.syntax.all._ | ||
import fs2.Stream | ||
import org.http4s.Uri | ||
import org.scalasteward.core.data.Repo | ||
import org.scalasteward.core.io.FileAlg | ||
import org.scalasteward.core.util.Nel | ||
import org.typelevel.log4cats.Logger | ||
|
||
final class ReposFilesLoader[F[_]](implicit | ||
fileAlg: FileAlg[F], | ||
logger: Logger[F], | ||
F: Sync[F] | ||
) { | ||
def loadAll(reposFiles: Nel[Uri]): Stream[F, Repo] = | ||
Stream.emits(reposFiles.toList).evalMap(loadRepos).flatMap(Stream.emits) | ||
|
||
private def loadRepos(reposFile: Uri): F[List[Repo]] = | ||
for { | ||
_ <- logger.debug(s"Loading repos from $reposFile") | ||
content <- fileAlg.readUri(reposFile) | ||
repos <- Stream.fromIterator(content.linesIterator, 4096).mapFilter(Repo.parse).compile.toList | ||
_ <- | ||
if (repos.nonEmpty) F.unit | ||
else { | ||
val msg = s"No repos found in ${reposFile.renderString}. " + | ||
s"Check the formatting of that file. " + | ||
s"""The format is "- $$owner/$$repo" or "- $$owner/$$repo:$$branch".""" | ||
logger.warn(msg) | ||
} | ||
} yield repos | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
modules/core/src/test/scala/org/scalasteward/core/application/ReposFilesLoaderTest.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,31 @@ | ||
package org.scalasteward.core.application | ||
|
||
import munit.CatsEffectSuite | ||
import org.scalasteward.core.data.Repo | ||
import org.scalasteward.core.git.Branch | ||
import org.scalasteward.core.mock.MockContext.context.reposFilesLoader | ||
import org.scalasteward.core.mock.{MockConfig, MockState} | ||
import org.scalasteward.core.util.Nel | ||
|
||
class ReposFilesLoaderTest extends CatsEffectSuite { | ||
test("non-empty repos file") { | ||
val initialState = MockState.empty.addUris(MockConfig.reposFile -> "- a/b\n- c/d:e") | ||
val obtained = | ||
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState) | ||
assertIO(obtained, List(Repo("a", "b"), Repo("c", "d", Some(Branch("e"))))) | ||
} | ||
|
||
test("malformed repos file") { | ||
val initialState = MockState.empty.addUris(MockConfig.reposFile -> " - a/b") | ||
val obtained = | ||
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState) | ||
assertIO(obtained, List.empty) | ||
} | ||
|
||
test("non-existing repos file") { | ||
val initialState = MockState.empty | ||
val obtained = | ||
reposFilesLoader.loadAll(Nel.one(MockConfig.reposFile)).compile.toList.runA(initialState) | ||
assertIO(obtained.attempt.map(_.isLeft), true) | ||
} | ||
} |
Oops, something went wrong.