~jan0sch/smederee

Showing details for patch ecb62c85f1945555ab6e41a87318e6f58c38fc59.
2025-04-20 (Sun), 3:10 PM - Jens Grassel - ecb62c85f1945555ab6e41a87318e6f58c38fc59

vcs: Add flag to actually run the repair command in the health tab.

- add flag query parameter
- add button
- implement check if parameter is set and exit code is not zero
Summary of changes
3 files modified with 23 lines added and 9 lines removed
  • modules/hub/src/main/resources/messages.properties with 2 added and 0 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 18 added and 4 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html with 3 added and 5 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/messages.properties new-smederee/modules/hub/src/main/resources/messages.properties
--- old-smederee/modules/hub/src/main/resources/messages.properties	2025-06-20 20:20:20.242203718 +0000
+++ new-smederee/modules/hub/src/main/resources/messages.properties	2025-06-20 20:20:20.246203711 +0000
@@ -250,6 +250,8 @@
 
 repository.edit.title=Edit the repository settings.
 
+repository.health.run-repair=Run repair command
+
 repository.label.edit.title=Edit label >> {0} <<
 repository.label.edit.link=Edit
 repository.labels.add.title=Add a new label.
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-06-20 20:20:20.242203718 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-06-20 20:20:20.246203711 +0000
@@ -676,12 +676,16 @@
       *   The name of the user who owns the repository.
       * @param repositoryName
       *   The actual name of the repository.
+      * @param runRepair
+      *   A boolean flag indicating if the repair command shall be run (i.e. omit `--dry-run`).
       * @return
       *   An HTTP response containing the rendered HTML.
       */
     def doShowRepositoryHealth(
         csrf: Option[CsrfToken]
-    )(user: Option[Account])(repositoryOwnerName: Username, repositoryName: VcsRepositoryName): F[Response[F]] =
+    )(
+        user: Option[Account]
+    )(repositoryOwnerName: Username, repositoryName: VcsRepositoryName, runRepair: Boolean): F[Response[F]] =
         for {
             language  <- Sync[F].delay(user.flatMap(_.language).getOrElse(LanguageCode("en")))
             repoAndId <- loadRepo(user)(repositoryOwnerName, repositoryName)
@@ -698,7 +702,13 @@
                 case Some(repoId) => vcsMetadataRepo.findVcsRepositoryBranches(repoId).compile.toList
                 case _            => Sync[F].delay(List.empty)
             }
-            check <- darcs.repair(directory.toNIO)(repositoryName.toString)(Chain("--dry-run"))
+            options =
+                if (runRepair) {
+                    Chain.empty
+                } else {
+                    Chain("--dry-run")
+                }
+            check <- darcs.repair(directory.toNIO)(repositoryName.toString)(options)
             health = VcsRepositoryHealth(
                 command = "darcs repair --dry-run",
                 exitCode = check.exitValue,
@@ -1926,7 +1936,7 @@
     private val showRepositoryHealth: AuthedRoutes[Account, F] = AuthedRoutes.of {
         case ar @ GET -> Root / UsernamePathParameter(repositoryOwnerName) / VcsRepositoryNamePathParameter(
                 repositoryName
-            ) / "health" as user =>
+            ) / "health" :? RunRepairCommand(runRepair) as user =>
             for {
                 csrf      <- Sync[F].delay(ar.req.getCsrfToken)
                 language  <- Sync[F].delay(user.language.getOrElse(LanguageCode("en")))
@@ -1942,7 +1952,7 @@
                             repositoryName
                         )
                     )
-                )(_ => doShowRepositoryHealth(csrf)(user.some)(repositoryOwnerName, repositoryName))
+                )(_ => doShowRepositoryHealth(csrf)(user.some)(repositoryOwnerName, repositoryName, runRepair))
             } yield resp
     }
 
@@ -2125,6 +2135,10 @@
   */
 object HistoryFromQueryParameter extends OptionalQueryParamDecoderMatcher[Int]("from")
 
+/** A query flag that implies that the health endpoint should run the repair command.
+  */
+object RunRepairCommand extends FlagQueryParamMatcher("run-repair")
+
 /** A path parameter extractor to get the vcs repository name for a clone operation.
   */
 object VcsRepositoryClonePathParameter {
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html	2025-06-20 20:20:20.242203718 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHealth.scala.html	2025-06-20 20:20:20.246203711 +0000
@@ -70,17 +70,15 @@
         </div>
       </div>
     </div>
+    @if(health.exitCode =!= 0) {
     <div class="pure-g">
       <div class="pure-u-1-1 pure-u-md-1-1">
         <div class="l-box">
-          <pre>
-          @for(line <- health.stderr.iterator) {
-            @line
-          }
-          </pre>
+          <a class="pure-button pure-button-warning" href="@repositoryBaseUri.addSegment("health").withQueryParam("run-repair")">@Messages("repository.health.run-repair")</a>
         </div>
       </div>
     </div>
+    } else {}
   </div>
 }
 }