Skip to content

Commit

Permalink
Merge pull request #1403 from adpi2/revamp-project-settings
Browse files Browse the repository at this point in the history
Revamp project settings
  • Loading branch information
adpi2 authored May 23, 2024
2 parents aef5f5b + 2dcb14a commit 2e48d71
Show file tree
Hide file tree
Showing 39 changed files with 228 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ case class ArtifactSelection(
(
// default artifact (ex: akka-actors is the default for akka/akka)
project.settings.defaultArtifact.contains(artifact.artifactName),
// not deprecated
!project.settings.deprecatedArtifacts.contains(artifact.artifactName),
// project repository (ex: shapeless)
project.repository.value == artifact.artifactName.value,
// alphabetically
artifact.artifactName,
// stable version first
project.settings.defaultStableVersion && artifact.version.preRelease.isDefined,
project.settings.preferStableVersion && artifact.version.preRelease.isDefined,
artifact.version,
artifact.binaryVersion
)
}(
Ordering.Tuple6(
Ordering.Tuple7(
Ordering[Boolean],
Ordering[Boolean],
Ordering[Boolean],
Ordering[Artifact.Name].reverse,
Expand All @@ -42,18 +45,21 @@ case class ArtifactSelection(
(
// default artifact (ex: akka-actors is the default for akka/akka)
project.settings.defaultArtifact.contains(artifact.artifactName),
// not deprecated
!project.settings.deprecatedArtifacts.contains(artifact.artifactName),
// project repository (ex: shapeless)
project.repository.value == artifact.artifactName.value,
// alphabetically
artifact.artifactName,
// stable version first
project.settings.defaultStableVersion && artifact.version.preRelease.isDefined,
project.settings.preferStableVersion && artifact.version.preRelease.isDefined,
artifact.version,
artifact.binaryVersion
)
}(
Ordering
.Tuple6(
.Tuple7(
Ordering[Boolean],
Ordering[Boolean],
Ordering[Boolean],
Ordering[Artifact.Name].reverse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scaladex.core.model

final case class DocumentationPattern(label: String, pattern: String) {
def eval: Option[DocumentationLink] =
def asGlobal: Option[DocumentationLink] =
if (DocumentationPattern.placeholders.exists(pattern.contains)) None
else Some(DocumentationLink(label, pattern))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ case class GithubInfo(
topics: Set[String],
contributingGuide: Option[Url],
codeOfConduct: Option[Url],
chatroom: Option[Url],
openIssues: Seq[GithubIssue], // right now it's all issues, not only beginners issues
scalaPercentage: Option[Int],
license: Option[License],
Expand All @@ -57,7 +56,6 @@ case class GithubInfo(
openIssues = openIssues,
topics = topics.toSeq,
contributingGuide = contributingGuide,
chatroom = chatroom,
codeOfConduct = codeOfConduct,
stars = stars,
forks = forks,
Expand All @@ -84,7 +82,6 @@ object GithubInfo {
topics = Set(),
contributingGuide = None,
codeOfConduct = None,
chatroom = None,
openIssues = Seq(),
scalaPercentage = None,
license = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ case class Project(
.orElse(artifact.defaultScaladoc.map(DocumentationLink("Scaladoc", _)))

def globalDocumentation: Seq[DocumentationLink] =
settings.customScalaDoc.flatMap(DocumentationPattern("Scaladoc", _).eval).toSeq ++
settings.documentationLinks.flatMap(_.eval)
settings.customScalaDoc.flatMap(DocumentationPattern("Scaladoc", _).asGlobal).toSeq ++
settings.documentationLinks.flatMap(_.asGlobal)

def artifactDocumentation(artifact: Artifact): Seq[DocumentationLink] =
scaladoc(artifact).toSeq ++ settings.documentationLinks.map(_.eval(artifact))
Expand Down Expand Up @@ -84,21 +84,19 @@ object Project {
githubStatus = githubInfo.map(_ => GithubStatus.Ok(now)).getOrElse(GithubStatus.Unknown(now)),
githubInfo = githubInfo,
creationDate = creationDate,
settings = settings.getOrElse(Settings.default)
settings = settings.getOrElse(Settings.empty)
)

case class Settings(
defaultStableVersion: Boolean,
preferStableVersion: Boolean,
defaultArtifact: Option[Artifact.Name],
strictVersions: Boolean,
customScalaDoc: Option[String],
documentationLinks: Seq[DocumentationPattern],
deprecated: Boolean,
contributorsWanted: Boolean,
artifactDeprecations: Set[Artifact.Name],
deprecatedArtifacts: Set[Artifact.Name],
cliArtifacts: Set[Artifact.Name],
category: Option[Category],
beginnerIssuesLabel: Option[String]
chatroom: Option[String]
)

case class Organization private (value: String) extends AnyVal {
Expand All @@ -117,18 +115,16 @@ object Project {
}

object Settings {
val default: Settings = Settings(
defaultStableVersion = true,
val empty: Settings = Settings(
preferStableVersion = true,
defaultArtifact = None,
strictVersions = false,
customScalaDoc = None,
documentationLinks = List(),
deprecated = false,
contributorsWanted = false,
artifactDeprecations = Set(),
deprecatedArtifacts = Set(),
cliArtifacts = Set(),
category = None,
beginnerIssuesLabel = None
chatroom = None
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case class SemanticVersion(
def isPreRelease: Boolean =
preRelease.isDefined || metadata.isDefined

def isRelease: Boolean =
def isStable: Boolean =
isSemantic && !isPreRelease

override def toString: String = this match {
Expand Down Expand Up @@ -103,12 +103,9 @@ object SemanticVersion {
)
}

/**
* Often we will prefer the latest release, but if there is no full release, we will select the most recent
* pre-release.
*/
val PreferReleases: Ordering[SemanticVersion] =
Ordering.by[SemanticVersion, Boolean](_.isRelease).orElse(ordering)
// We prefer the latest stable artifact.
val PreferStable: Ordering[SemanticVersion] =
Ordering.by[SemanticVersion, Boolean](_.isStable).orElse(ordering)

private def MajorP[A: P]: P[Int] = Number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ case class GithubInfoDocument(
openIssues: Seq[GithubIssue],
topics: Seq[String],
contributingGuide: Option[Url],
chatroom: Option[Url],
codeOfConduct: Option[Url],
stars: Option[Int],
forks: Option[Int],
Expand All @@ -22,6 +21,6 @@ case class GithubInfoDocument(
)

object GithubInfoDocument {
def default: GithubInfoDocument =
GithubInfoDocument(None, None, None, Seq.empty, Seq.empty, None, None, None, None, None, 0, None, None, None)
def empty: GithubInfoDocument =
GithubInfoDocument(None, None, None, Seq.empty, Seq.empty, None, None, None, None, 0, None, None, None)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object ProjectDocument {
.map(_.artifactName)
.distinct
.sorted
.partition(project.settings.artifactDeprecations.contains)
.partition(project.settings.deprecatedArtifacts.contains)
import project._
ProjectDocument(
organization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import scaladex.core.model.GithubIssue
*/
final case class ProjectHit(
document: ProjectDocument,
beginnerIssueHits: Seq[GithubIssue]
issues: Seq[GithubIssue]
) {
def displayedIssues: Seq[GithubIssue] =
if (beginnerIssueHits.nonEmpty) beginnerIssueHits
if (issues.nonEmpty) issues
else document.githubInfo.toSeq.flatMap(_.openIssues)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait WebDatabase {
): Future[Seq[Artifact]]
def getArtifacts(ref: Project.Reference, artifactName: Artifact.Name, version: SemanticVersion): Future[Seq[Artifact]]
def getArtifactsByName(projectRef: Project.Reference, artifactName: Artifact.Name): Future[Seq[Artifact]]
def getLatestArtifacts(ref: Project.Reference): Future[Seq[Artifact]]
def getLatestArtifacts(ref: Project.Reference, preferStableVersions: Boolean): Future[Seq[Artifact]]
def getArtifactByMavenReference(mavenRef: Artifact.MavenReference): Future[Option[Artifact]]
def getAllArtifacts(language: Option[Language], platform: Option[Platform]): Future[Seq[Artifact]]
def countArtifacts(): Future[Long]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scaladex.core.model
import org.scalatest.funspec.AsyncFunSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import scaladex.core.model.SemanticVersion.PreferReleases
import scaladex.core.model.SemanticVersion.PreferStable
import scaladex.core.test.Values._

class SemanticVersionTests extends AsyncFunSpec with Matchers with TableDrivenPropertyChecks {
Expand Down Expand Up @@ -44,7 +44,7 @@ class SemanticVersionTests extends AsyncFunSpec with Matchers with TableDrivenPr
it("should allow us to prefer releases over pre-releases") {
val versions = Seq(`7.0.0`, `7.1.0`, `7.2.0-PREVIEW.1`)
versions.max shouldBe `7.2.0-PREVIEW.1`
versions.max(PreferReleases) shouldBe `7.1.0`
versions.max(PreferStable) shouldBe `7.1.0`
}

it("should encode and decode any version") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class InMemoryDatabase extends SchedulerDatabase {
Future.successful(())
}

override def getLatestArtifacts(ref: Project.Reference): Future[Seq[Artifact]] = {
override def getLatestArtifacts(ref: Project.Reference, preferStableVersion: Boolean): Future[Seq[Artifact]] = {
val res = allArtifacts(ref)
.groupBy(a => (a.groupId, a.artifactId))
.values
Expand Down
18 changes: 7 additions & 11 deletions modules/core/shared/src/test/scala/scaladex/core/test/Values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,15 @@ object Values {
contributors = Seq(contributor("olafurpg"), contributor("scala-steward"))
)
val settings: Settings = Settings(
defaultStableVersion = false,
preferStableVersion = false,
defaultArtifact = None,
strictVersions = false,
customScalaDoc = None,
documentationLinks = List(),
deprecated = false,
contributorsWanted = false,
artifactDeprecations = Set(),
deprecatedArtifacts = Set(),
cliArtifacts = Set(),
category = Some(Category.LintingAndRefactoring),
beginnerIssuesLabel = None
chatroom = None
)
val project: Project =
Project.default(reference, None, Some(githubInfo), Some(settings), now = now)
Expand Down Expand Up @@ -118,11 +116,10 @@ object Values {
Scope("compile")
)
val githubInfo: GithubInfo = GithubInfo.empty
val settings: Project.Settings =
Project.Settings.default.copy(
defaultArtifact = Some(artifact.artifactName),
category = Some(Category.Json)
)
val settings: Project.Settings = Project.Settings.empty.copy(
defaultArtifact = Some(artifact.artifactName),
category = Some(Category.Json)
)
}

object Cats {
Expand All @@ -136,7 +133,6 @@ object Values {
stars = Some(4337),
forks = Some(1081),
contributingGuide = Some(Url("https://github.com/typelevel/cats/blob/main/CONTRIBUTING.md")),
chatroom = Some(Url("https://gitter.im/typelevel/cats")),
openIssues = List(issueAboutFoo, issueAboutBar),
contributors = Seq(contributor("travisbrown"), contributor("ceedub"), contributor("kailuowang")),
commitActivity = Seq(GithubCommitActivity(25, Instant.now, IndexedSeq(0, 3, 4, 0, 5, 6, 7)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ class GithubClientImplTests extends AsyncFunSpec with Matchers {
for (openIssues <- client.getOpenIssues(Scalafix.reference))
yield openIssues should not be empty
}
it("getGitterChatRoom") {
for (chatroom <- client.getGitterChatRoom(Scalafix.reference))
yield chatroom shouldBe defined
}

it("should return moved project") {
val reference = Project.Reference.from("rickynils", "scalacheck")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE project_settings RENAME COLUMN default_stable_version TO prefer_stable_version;
ALTER TABLE project_settings RENAME COLUMN artifact_deprecations TO deprecated_artifacts;

ALTER TABLE project_settings
DROP COLUMN strict_versions,
DROP COLUMN deprecated,
DROP COLUMN primary_topic,
DROP COLUMN beginner_issues_label,
ADD chatroom VARCHAR(2083);

ALTER TABLE github_info DROP COLUMN chatroom;
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ class ElasticsearchEngine(esClient: ElasticClient, index: String)(implicit ec: E
"githubInfo.openIssues",
existsQuery("githubInfo.openIssues")
),
existsQuery("githubInfo.contributingGuide"),
existsQuery("githubInfo.chatroom")
existsQuery("githubInfo.contributingGuide")
)
)

Expand Down
18 changes: 0 additions & 18 deletions modules/infra/src/main/scala/scaladex/infra/GithubClientImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class GithubClientImpl(token: Secret)(implicit val system: ActorSystem)
communityProfile <- getCommunityProfile(repo.ref)
contributors <- getContributors(repo.ref)
openIssues <- getOpenIssues(repo.ref)
chatroom <- getGitterChatRoom(repo.ref)
scalaPercentage <- getPercentageOfLanguage(repo.ref, language = "Scala")
commitActivity <- getCommitActivity(repo.ref)
} yield GithubInfo(
Expand All @@ -103,7 +102,6 @@ class GithubClientImpl(token: Secret)(implicit val system: ActorSystem)
topics = repo.topics.toSet,
contributingGuide = communityProfile.flatMap(_.contributingFile).map(Url),
codeOfConduct = communityProfile.flatMap(_.codeOfConductFile).map(Url),
chatroom = chatroom.map(Url),
openIssues = openIssues.map(_.toGithubIssue).toList,
scalaPercentage = Option(scalaPercentage),
license = repo.licenseName.flatMap(License.get),
Expand Down Expand Up @@ -212,22 +210,6 @@ class GithubClientImpl(token: Secret)(implicit val system: ActorSystem)
get[Seq[GithubCommitActivity]](request).fallbackTo(Future.successful(Seq.empty))
}

def getGitterChatRoom(ref: Project.Reference): Future[Option[String]] = {
val uri = s"https://gitter.im/$ref"
val request = HttpRequest(uri = uri)
Http().singleRequest(request).map {
case HttpResponse(StatusCodes.OK, _, entity, _) =>
entity.discardBytes()
Some(uri)
case HttpResponse(StatusCodes.Redirection(_), _, entity, _) =>
entity.discardBytes()
Some(uri)
case resp =>
resp.entity.discardBytes()
None
}
}

def getUserOrganizations(user: String): Future[Seq[Project.Organization]] =
getAllRecursively(getUserOrganizationsPage(user))

Expand Down
27 changes: 16 additions & 11 deletions modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten
override def getArtifactsByName(ref: Project.Reference, artifactName: Artifact.Name): Future[Seq[Artifact]] =
run(ArtifactTable.selectArtifactByProjectAndName.to[Seq]((ref, artifactName)))

override def getLatestArtifacts(ref: Project.Reference): Future[Seq[Artifact]] =
for {
releases <- run(ArtifactTable.selectLatestArtifacts(mustBeRelease = true).to[Seq](ref))
nonReleases <- run(ArtifactTable.selectLatestArtifacts(mustBeRelease = false).to[Seq](ref))
} yield {
// override non-released artifacts with their latest released version
val merge = nonReleases.map(artifact => artifact.mavenReference -> artifact).toMap ++
releases.map(artifact => artifact.mavenReference -> artifact).toMap
merge.values.toSeq
}
override def getLatestArtifacts(ref: Project.Reference, preferStableVersions: Boolean): Future[Seq[Artifact]] = {
val latestArtifactsF = run(ArtifactTable.selectLatestArtifacts(stableOnly = false).to[Seq](ref))
if (preferStableVersions) {
for {
latestStableArtifacts <- run(ArtifactTable.selectLatestArtifacts(stableOnly = true).to[Seq](ref))
latestArtifacts <- latestArtifactsF
} yield
// override non-stable version with the latest stable version
(latestStableArtifacts ++ latestArtifacts)
.groupBy(a => (a.groupId, a.artifactId))
.valuesIterator
.map(_.head)
.toSeq
} else latestArtifactsF
}

override def getArtifactByMavenReference(mavenRef: Artifact.MavenReference): Future[Option[Artifact]] =
run(ArtifactTable.selectByMavenReference.option(mavenRef))
Expand Down Expand Up @@ -250,7 +255,7 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten
oldProject <- getProject(ref)
_ <- updateGithubStatus(ref, status)
_ <- run(ProjectTable.insertIfNotExists.run((status.destination, GithubStatus.Ok(status.updateDate))))
_ <- updateProjectSettings(status.destination, oldProject.map(_.settings).getOrElse(Project.Settings.default))
_ <- updateProjectSettings(status.destination, oldProject.map(_.settings).getOrElse(Project.Settings.empty))
_ <- run(GithubInfoTable.insertOrUpdate.run(status.destination, githubInfo, githubInfo))
} yield ()

Expand Down
Loading

0 comments on commit 2e48d71

Please sign in to comment.