From 8147db04435010c54f519c43ec3d3c1da1f5531c Mon Sep 17 00:00:00 2001 From: RenkuBot <53332360+RenkuBot@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:49:02 +0200 Subject: [PATCH 1/2] chore: Update cats-core, cats-free from 2.9.0 to 2.10.0 (#1658) --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 6803f8e41d..7e7282cc2d 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -5,7 +5,7 @@ object Dependencies { object V { val ammonite = "2.4.1" - val catsCore = "2.9.0" + val catsCore = "2.10.0" val catsEffect = "3.5.1" val catsEffectScalaTest = "1.5.0" val circeCore = "0.14.5" From 4a21ddf7f65e0de3d5a28937ec4442adb78ecf0e Mon Sep 17 00:00:00 2001 From: Jakub Chrobasik Date: Tue, 15 Aug 2023 16:08:35 +0200 Subject: [PATCH 2/2] fix: SYNC_REPO_METADATA to use GL project's name not payload's (#1662) --- .../processor/NewValuesCalculator.scala | 11 +++------ .../processor/PayloadDataExtractor.scala | 17 +++----------- .../syncrepometadata/processor/model.scala | 6 +---- .../processor/EventProcessorSpec.scala | 2 +- .../processor/Generators.scala | 9 ++++---- .../processor/NewValuesCalculatorSpec.scala | 23 ++----------------- .../processor/PayloadDataExtractorSpec.scala | 7 +----- .../UpdateCommandsCalculatorSpec.scala | 22 +++++++++--------- 8 files changed, 26 insertions(+), 71 deletions(-) diff --git a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculator.scala b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculator.scala index 35d901b8ce..543dfa2fb1 100644 --- a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculator.scala +++ b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculator.scala @@ -34,7 +34,7 @@ private object NewValuesCalculator extends NewValuesCalculator { glData: DataExtract.GL, maybePayloadData: Option[DataExtract.Payload] ): NewValues = NewValues( - maybeNewName(tsData, glData, maybePayloadData), + maybeNewName(tsData, glData), Option.when(tsData.visibility != glData.visibility)(glData.visibility), maybeNewDateModified(tsData, glData), maybeNewDesc(tsData, glData, maybePayloadData), @@ -42,13 +42,8 @@ private object NewValuesCalculator extends NewValuesCalculator { maybeNewImages(tsData, glData, maybePayloadData) ) - private def maybeNewName(tsData: DataExtract.TS, - glData: DataExtract.GL, - maybePayloadData: Option[DataExtract.Payload] - ) = { - val potentiallyNewName = maybePayloadData.getOrElse(glData).name - Option.when(tsData.name != potentiallyNewName)(potentiallyNewName) - } + private def maybeNewName(tsData: DataExtract.TS, glData: DataExtract.GL) = + Option.when(tsData.name != glData.name)(glData.name) private def maybeNewDateModified(tsData: DataExtract.TS, glData: DataExtract.GL) = tsData.maybeDateModified -> glData.maybeDateModified match { diff --git a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractor.scala b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractor.scala index 52baea29e6..e366bcbd8c 100644 --- a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractor.scala +++ b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractor.scala @@ -26,7 +26,6 @@ import io.renku.cli.model.Ontologies.{Schema => CliSchema} import io.renku.eventlog.api.EventLogClient.EventPayload import io.renku.graph.model.images.Image import io.renku.graph.model.projects -import io.renku.jsonld.{Cursor, Property} import org.typelevel.log4cats.Logger private trait PayloadDataExtractor[F[_]] { @@ -56,30 +55,20 @@ private class PayloadDataExtractorImpl[F[_]: MonadThrow: Logger] extends Payload Option.empty[DataExtract.Payload].pure[F] case Some(jsonLD) => jsonLD.cursor - .as(decodeList(dataExtract(slug))) + .as[List[DataExtract.Payload]] .map(_.headOption) .fold(logWarn(slug), _.pure[F]) } - private def dataExtract(slug: projects.Slug): JsonLDDecoder[DataExtract.Payload] = + private implicit lazy val dataExtract: JsonLDDecoder[DataExtract.Payload] = JsonLDDecoder.entity(CliProject.entityTypes) { cur => for { - name <- cur.downField(CliSchema.name).as[Option[projects.Name]] >>= { - case None => decodingFailure(CliSchema.name, cur).asLeft - case Some(v) => v.asRight - } maybeDesc <- cur.downField(CliSchema.description).as[Option[projects.Description]] keywords <- cur.downField(CliSchema.keywords).as[Set[Option[projects.Keyword]]].map(_.flatten) images <- cur.downField(CliSchema.image).as[List[Image]].map(_.sortBy(_.position).map(_.uri)) - } yield DataExtract.Payload(slug, name, maybeDesc, keywords, images) + } yield DataExtract.Payload(maybeDesc, keywords, images) } - private def decodingFailure(propName: Property, cur: Cursor) = - DecodingFailure( - DecodingFailure.Reason.CustomReason(show"no '$propName' property in the payload"), - cur.jsonLD.toJson.hcursor - ) - private def logError(slug: projects.Slug): Throwable => F[Option[JsonLD]] = Logger[F] .error(_)(show"$categoryName: cannot process data from the payload for $slug") diff --git a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/model.scala b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/model.scala index d69bbd74a7..e6c637c21f 100644 --- a/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/model.scala +++ b/triples-generator/src/main/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/model.scala @@ -26,8 +26,6 @@ import io.renku.triplesstore.SparqlQuery import java.time.Instant private sealed trait DataExtract { - val slug: projects.Slug - val name: projects.Name val maybeDateModified: Option[projects.DateModified] val maybeDesc: Option[projects.Description] val keywords: Set[projects.Keyword] @@ -55,9 +53,7 @@ private object DataExtract { override val maybeDateModified: Option[projects.DateModified] = List(updatedAt, lastActivityAt).max.map(projects.DateModified.apply) } - final case class Payload(slug: projects.Slug, - name: projects.Name, - maybeDesc: Option[projects.Description], + final case class Payload(maybeDesc: Option[projects.Description], keywords: Set[projects.Keyword], images: List[ImageUri] ) extends DataExtract { diff --git a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/EventProcessorSpec.scala b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/EventProcessorSpec.scala index 89d88699b5..9a6a89097f 100644 --- a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/EventProcessorSpec.scala +++ b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/EventProcessorSpec.scala @@ -102,7 +102,7 @@ class EventProcessorSpec extends AsyncFlatSpec with AsyncIOSpec with should.Matc eventPayloads[IO].map(_.generateOne) >>= { payload => givenPayloadFinding(event.slug, returning = payload.some.pure[IO]) - val maybePayloadData = payloadDataExtracts(having = event.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption givenPayloadDataExtraction(event.slug, payload, returning = maybePayloadData.pure[IO]) val updates = updateCommands.generateList() diff --git a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/Generators.scala b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/Generators.scala index f8091de455..b1e3d3a634 100644 --- a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/Generators.scala +++ b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/Generators.scala @@ -22,7 +22,7 @@ import cats.syntax.all._ import io.renku.eventlog.api.events.Generators.redoProjectTransformationEvents import io.renku.generators.CommonGraphGenerators.sparqlQueries import io.renku.generators.Generators.Implicits._ -import io.renku.graph.model.RenkuTinyTypeGenerators.{imageUris, projectDescriptions, projectKeywords, projectModifiedDates, projectNames, projectSlugs, projectResourceIds, projectVisibilities} +import io.renku.graph.model.RenkuTinyTypeGenerators.{imageUris, projectDescriptions, projectKeywords, projectModifiedDates, projectNames, projectResourceIds, projectSlugs, projectVisibilities} import io.renku.graph.model.{entities, projects} import org.scalacheck.Gen @@ -48,12 +48,11 @@ private object Generators { maybeImage <- imageUris.toGeneratorOfOptions } yield DataExtract.GL(having, name, visibility, updatedAt, lastActivityAt, maybeDesc, keywords, maybeImage) - def payloadDataExtracts(having: projects.Slug = projectSlugs.generateOne): Gen[DataExtract.Payload] = for { - name <- projectNames + lazy val payloadDataExtracts: Gen[DataExtract.Payload] = for { maybeDesc <- projectDescriptions.toGeneratorOfOptions keywords <- projectKeywords.toGeneratorOfSet(min = 0) imageUris <- imageUris.toGeneratorOfList() - } yield DataExtract.Payload(having, name, maybeDesc, keywords, imageUris) + } yield DataExtract.Payload(maybeDesc, keywords, imageUris) def tsDataFrom(project: entities.Project): DataExtract.TS = DataExtract.TS( @@ -84,7 +83,7 @@ private object Generators { } def payloadDataFrom(data: DataExtract.TS): DataExtract.Payload = - DataExtract.Payload(data.slug, data.name, data.maybeDesc, data.keywords, data.images) + DataExtract.Payload(data.maybeDesc, data.keywords, data.images) val sparqlUpdateCommands: Gen[UpdateCommand.Sparql] = sparqlQueries.map(UpdateCommand.Sparql) val eventUpdateCommands: Gen[UpdateCommand.Event] = redoProjectTransformationEvents.map(UpdateCommand.Event) diff --git a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculatorSpec.scala b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculatorSpec.scala index e4e16cd3d8..fe3936b65d 100644 --- a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculatorSpec.scala +++ b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/NewValuesCalculatorSpec.scala @@ -34,7 +34,7 @@ class NewValuesCalculatorSpec extends AnyWordSpec with should.Matchers with Opti "new name" should { - "be None if ts and gl names are the same - no payload case" in { + "be None if ts and gl names are the same" in { val tsData = tsDataExtracts().generateOne val glData = glDataFrom(tsData) @@ -42,16 +42,7 @@ class NewValuesCalculatorSpec extends AnyWordSpec with should.Matchers with Opti NewValuesCalculator.findNewValues(tsData, glData, maybePayloadData = None) shouldBe NewValues.empty } - "be None if ts and payload names are the same" in { - - val tsData = tsDataExtracts().generateOne - val glData = glDataFrom(tsData).copy(name = projectNames.generateOne) - val payloadData = payloadDataFrom(tsData) - - NewValuesCalculator.findNewValues(tsData, glData, payloadData.some) shouldBe NewValues.empty - } - - "be gl name if ts and gl contains different names - no payload case" in { + "be gl name if ts and gl contains different names" in { val tsData = tsDataExtracts().generateOne val glData = glDataFrom(tsData).copy(name = projectNames.generateOne) @@ -59,16 +50,6 @@ class NewValuesCalculatorSpec extends AnyWordSpec with should.Matchers with Opti NewValuesCalculator.findNewValues(tsData, glData, maybePayloadData = None) shouldBe NewValues.empty.copy(maybeName = glData.name.some) } - - "be payload name if all ts, gl and payload contains different names" in { - - val tsData = tsDataExtracts().generateOne - val glData = glDataFrom(tsData).copy(name = projectNames.generateOne) - val payloadData = payloadDataFrom(tsData).copy(name = projectNames.generateOne) - - NewValuesCalculator.findNewValues(tsData, glData, payloadData.some) shouldBe - NewValues.empty.copy(maybeName = payloadData.name.some) - } } "new visibility" should { diff --git a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractorSpec.scala b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractorSpec.scala index 870f180630..f426339de4 100644 --- a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractorSpec.scala +++ b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/PayloadDataExtractorSpec.scala @@ -53,12 +53,7 @@ class PayloadDataExtractorSpec (ioPayload >>= (extractor.extractPayloadData(testProject.slug, _))) .asserting( - _.value shouldBe DataExtract.Payload(testProject.slug, - testProject.name, - testProject.maybeDescription, - testProject.keywords, - testProject.images - ) + _.value shouldBe DataExtract.Payload(testProject.maybeDescription, testProject.keywords, testProject.images) ) } } diff --git a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/UpdateCommandsCalculatorSpec.scala b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/UpdateCommandsCalculatorSpec.scala index 595e24d43b..809f1779e1 100644 --- a/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/UpdateCommandsCalculatorSpec.scala +++ b/triples-generator/src/test/scala/io/renku/triplesgenerator/events/consumers/syncrepometadata/processor/UpdateCommandsCalculatorSpec.scala @@ -59,7 +59,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectNames.generateOne givenNewValuesFinding(tsData, glData, maybePayloadData, returning = NewValues.empty.copy(maybeName = newValue.some)) @@ -84,7 +84,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectVisibilities.generateOne givenNewValuesFinding(tsData, @@ -114,7 +114,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectModifiedDates(project.dateModified.value).generateSome givenNewValuesFinding(tsData, @@ -143,7 +143,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectDescriptions.generateSome givenNewValuesFinding(tsData, glData, maybePayloadData, returning = NewValues.empty.copy(maybeDesc = newValue.some)) @@ -171,7 +171,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption givenNewValuesFinding(tsData, glData, maybePayloadData, returning = NewValues.empty.copy(maybeDesc = Some(None))) val updatedTsData = tsData.copy(maybeDesc = None) @@ -198,7 +198,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectKeywords.generateSet(min = 1) givenNewValuesFinding(tsData, @@ -230,7 +230,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = Set.empty[projects.Keyword] givenNewValuesFinding(tsData, @@ -259,7 +259,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = imageUris.generateList(min = 1) givenNewValuesFinding(tsData, @@ -291,7 +291,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = List.empty[Image] givenNewValuesFinding(tsData, @@ -320,7 +320,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption val newValue = projectKeywords.generateSet(min = 1) givenNewValuesFinding(tsData, @@ -349,7 +349,7 @@ class UpdateCommandsCalculatorSpec val tsData = tsDataFrom(project) val glData = glDataExtracts(project.slug).generateOne - val maybePayloadData = payloadDataExtracts(project.slug).generateOption + val maybePayloadData = payloadDataExtracts.generateOption givenNewValuesFinding(tsData, glData, maybePayloadData, returning = NewValues.empty)