Skip to content

Commit

Permalink
Revamp project settings page
Browse files Browse the repository at this point in the history
- remove unused fields
- renames some fields
- add chatroom field
- reorganize page
  • Loading branch information
adpi2 committed May 23, 2024
1 parent 91854c7 commit 836dc53
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 293 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 @@ -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)
}
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 @@ -56,10 +56,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 @@ -447,7 +447,6 @@ class ElasticsearchEngine(esClient: ElasticClient, index: String)(implicit ec: E
existsQuery("githubInfo.openIssues")
),
existsQuery("githubInfo.contributingGuide"),
existsQuery("githubInfo.chatroom")
)
)

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
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ object DoobieUtils {
githubStatus = githubStatus,
githubInfo = githubInfo,
creationDate = creationDate,
settings = settings.getOrElse(Project.Settings.default)
settings = settings.getOrElse(Project.Settings.empty)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object GithubInfoTable {
"topics",
"contributing_guide",
"code_of_conduct",
"chatroom",
"open_issues",
"scala_percentage",
"license",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ object ProjectSettingsTable {

val referenceFields: Seq[String] = Seq("organization", "repository")
val settingsFields: Seq[String] = Seq(
"default_stable_version",
"prefer_stable_version",
"default_artifact",
"strict_versions",
"custom_scaladoc",
"documentation_links",
"deprecated",
"contributors_wanted",
"artifact_deprecations",
"deprecated_artifacts",
"cli_artifacts",
"category",
"beginner_issues_label"
"chatroom"
)

val insertOrUpdate: Update[(Project.Reference, Project.Settings, Project.Settings)] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn
for {
_ <- insertAll(projects)
hits <- searchEngine.find(params, pageParams)
} yield hits.items.flatMap(_.beginnerIssueHits) should contain theSameElementsAs expected
} yield hits.items.flatMap(_.issues) should contain theSameElementsAs expected
}

"count by topics" in {
Expand Down Expand Up @@ -173,7 +173,7 @@ class ElasticsearchEngineTests extends AsyncFreeSpec with Matchers with BeforeAn
}

private def projectDocument(ref: String, stars: Int, scalaPercentage: Int): ProjectDocument = {
val githubInfo = GithubInfoDocument.default.copy(stars = Some(stars), scalaPercentage = Some(scalaPercentage))
val githubInfo = GithubInfoDocument.empty.copy(stars = Some(stars), scalaPercentage = Some(scalaPercentage))
ProjectDocument.default(Project.Reference.from(ref)).copy(githubInfo = Some(githubInfo))
}

Expand Down
Loading

0 comments on commit 836dc53

Please sign in to comment.