Skip to content

Commit

Permalink
Fix #1320 : get project with no artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Dec 18, 2023
1 parent 79c03ae commit f79c3a3
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(
artifactsParams { params =>
getProjectOrRedirect(ref, user) { project =>
val artifactsF = database.getArtifacts(ref, artifactName, params)
val headerF = getProjectHeader(project)
for {
artifacts <- artifactsF
header <- headerF
} yield {
val headerF = getProjectHeader(project).map(_.get)
for (artifacts <- artifactsF; header <- headerF) yield {
val binaryVersions = artifacts
.map(_.binaryVersion)
.distinct
Expand Down Expand Up @@ -241,7 +238,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(
}
}

private def getProjectHeader(project: Project): Future[ProjectHeader] = {
private def getProjectHeader(project: Project): Future[Option[ProjectHeader]] = {
val ref = project.reference
for {
latestArtifacts <- database.getLatestArtifacts(ref)
Expand All @@ -253,7 +250,10 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(
getProjectOrRedirect(ref, user) { project =>
for {
header <- getProjectHeader(project)
directDependencies <- database.getProjectDependencies(ref, header.defaultVersion)
directDependencies <-
header
.map(h => database.getProjectDependencies(ref, h.defaultVersion))
.getOrElse(Future.successful(Seq.empty))
reverseDependencies <- database.getProjectDependents(ref)
} yield {
val groupedDirectDependencies = directDependencies
Expand All @@ -280,10 +280,8 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)(

private def getBadges(ref: Project.Reference, user: Option[UserState]): Route =
getProjectOrRedirect(ref, user) { project =>
for {
header <- getProjectHeader(project)
artifact = header.getDefaultArtifact(None, None)
} yield {
for (header <- getProjectHeader(project).map(_.get)) yield {
val artifact = header.getDefaultArtifact(None, None)
val page = html.badges(env, user, project, header, artifact)
complete(StatusCodes.OK, page)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte
else
for {
latestArtifacts <- database.getLatestArtifacts(project.reference)
projectHeader = ProjectHeader(project.reference, latestArtifacts, 0, project.settings.defaultArtifact)
dependencies <- database.computeProjectDependencies(project.reference, projectHeader.defaultVersion)
header = ProjectHeader(project.reference, latestArtifacts, 0, project.settings.defaultArtifact)
dependencies <- header
.map(h => database.computeProjectDependencies(project.reference, h.defaultVersion))
.getOrElse(Future.successful(Seq.empty))
_ <- database.deleteProjectDependencies(project.reference)
_ <- database.insertProjectDependencies(dependencies)
} yield ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import scaladex.core.model.ScalaJs
import scaladex.core.model.ScalaNative
import scaladex.core.model.SemanticVersion

object ProjectHeader {
def apply(
ref: Project.Reference,
latestArtifacts: Seq[Artifact],
versionCount: Long,
defaultArtifactName: Option[Artifact.Name]
): Option[ProjectHeader] =
Option.when(latestArtifacts.nonEmpty)(new ProjectHeader(ref, latestArtifacts, versionCount, defaultArtifactName))
}

final case class ProjectHeader(
ref: Project.Reference,
latestArtifacts: Seq[Artifact],
Expand Down Expand Up @@ -88,7 +98,7 @@ final case class ProjectHeader(
.orElse(byNamePrerelease)
.orElse(byLatestVersionStable)
.orElse(byLatestVersionPrerelease)
.getOrElse(throw new Exception(s"No default artifact found for $ref with $language and $platform"))
.get
}

def scalaVersions: Seq[Scala] = languages.collect { case v: Scala => v }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
env: Env,
user: Option[UserState],
project: Project,
header: ProjectHeader,
header: Option[ProjectHeader],
artifact: Artifact,
binaryVersions: Seq[BinaryVersion],
params: ArtifactPageParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@main(env, title = project.repository.toString, user) {
<main id="container-project">
@headproject(env, user, project, header, "Artifacts")
@headproject(env, user, project, Some(header), "Artifacts")
<div class="container">
<div class="content-project artifacts box" data-organization="@project.reference.organization"
data-repository="@project.reference.repository">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
@main(env, title = project.repository.value, user, extraMeta = project.twitterCard.toHeadMeta, extraMetaProperty = project.ogp.toHeadMetaProperty) {
<main id="container-project">
@headproject(env, user, project, header, "Badges")
@headproject(env, user, project, Some(header), "Badges")
<div class="container">
<div class="content-project box project-badges">
<section class="badge-section" id="latest">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@import scaladex.core.model.SemanticVersion
@import scaladex.view.model.ProjectHeader

@(env: Env, user: UserState, project: Project, header: ProjectHeader, artifacts: Seq[Artifact])
@(env: Env, user: UserState, project: Project, header: Option[ProjectHeader], artifacts: Seq[Artifact])

@artifactNames = @{ artifacts.map(_.artifactName).distinct }
@main(env, title = s"Edit ${project.repository}", Some(user)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@import scaladex.view.html.ensureUri
@import scaladex.view.model.ProjectHeader

@(env: Env, user: Option[UserState], project: Project, header: ProjectHeader, activeTab: String)
@(env: Env, user: Option[UserState], project: Project, header: Option[ProjectHeader], activeTab: String)

@canEdit = @{user.exists(_.canEdit(project.reference, env))}
@isActive(nameTab: String) = @{if(nameTab == activeTab) "active" else ""}
Expand All @@ -21,7 +21,9 @@
<h1>
<a href="/@project.organization">@project.organization</a> /
<a href="/@project.reference">@project.repository</a>
<span class="head-last-version">&nbsp;&nbsp;@header.defaultVersion.encode </span>
@for(header <- header) {
<span class="head-last-version">&nbsp;&nbsp;@header.defaultVersion.encode</span>
}
</h1>

@if(project.settings.contributorsWanted) {
Expand Down Expand Up @@ -58,50 +60,52 @@ <h1>
}
</ul>
}
<div class="project-versions">
@if(header.scalaVersions.nonEmpty){
<div>
Scala versions:
@for(scalaVersion <- header.scalaVersions.sorted.reverse) {
<a href="@header.artifactsUrl(scalaVersion)" class="targets">@scalaVersion.version</a>
}
</div>
}

@if(header.scalaJsVersions.nonEmpty){
<div>
Scala.js versions:
@for(platform <- header.scalaJsVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.scalaNativeVersions.nonEmpty){
<div>
Scala Native versions:
@for(platform <- header.scalaNativeVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.sbtVersions.nonEmpty){
<div>
sbt plugins:
@for(platform <- header.sbtVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.millVersions.nonEmpty){
<div>
Mill plugins:
@for(platform <- header.millVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
@for(header <- header) {
<div class="project-versions">
@if(header.scalaVersions.nonEmpty){
<div>
Scala versions:
@for(scalaVersion <- header.scalaVersions.sorted.reverse) {
<a href="@header.artifactsUrl(scalaVersion)" class="targets">@scalaVersion.version</a>
}
</div>
}

@if(header.scalaJsVersions.nonEmpty){
<div>
Scala.js versions:
@for(platform <- header.scalaJsVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.scalaNativeVersions.nonEmpty){
<div>
Scala Native versions:
@for(platform <- header.scalaNativeVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.sbtVersions.nonEmpty){
<div>
sbt plugins:
@for(platform <- header.sbtVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}

@if(header.millVersions.nonEmpty){
<div>
Mill plugins:
@for(platform <- header.millVersions.sorted.reverse) {
<a href="@header.artifactsUrl(platform)" class="targets">@platform.version</a>
}
</div>
}
}
</div>
</div>
Expand All @@ -110,7 +114,9 @@ <h1>
<div class="project-nav-bar">
<ul class="nav nav-tabs">
<li role="project" class="@isActive("Project")"><a href="/@project.reference">Project</a></li>
<li role="artifacts" class="@isActive("Artifacts")"><a href="@header.artifactsUrl">@plural(header.versionCount, "Version")</a></li>
@for(header <- header) {
<li role="artifacts" class="@isActive("Artifacts")"><a href="@header.artifactsUrl">@plural(header.versionCount, "Version")</a></li>
}
<!-- <li role="version-matrix" class="@isActive("Version Matrix")"><a href="/@project.reference/version-matrix">Version Matrix</a></li> -->
<li role="badges" class="@isActive("Badges")"><a href="/@project.reference/badges">Badges</a></li>
@if(canEdit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
env: Env,
user: Option[UserState],
project: Project,
header: ProjectHeader,
header: Option[ProjectHeader],
directDependencies: Map[Project.Reference, (ArtifactDependency.Scope, Seq[SemanticVersion])],
reverseDependency: Map[Project.Reference, (ArtifactDependency.Scope, SemanticVersion)],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
env: Env,
user: Option[UserState],
project: Project,
header: ProjectHeader,
header: Option[ProjectHeader],
binaryVersionsByPlatforms: Seq[(Platform, Seq[BinaryVersion])],
artifactsByVersions: Seq[(SemanticVersion, Seq[(Artifact.Name, Seq[Artifact])])]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProjectHeaderTests extends AnyFunSpec with Matchers {
}

private def getDefaultArtifact(artifacts: Artifact*): Artifact = {
val header = ProjectHeader(reference, artifacts, 10, None)
val header = ProjectHeader(reference, artifacts, 10, None).get
header.getDefaultArtifact(None, None)
}
}

0 comments on commit f79c3a3

Please sign in to comment.