mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 19:08:26 +00:00
@ -247,7 +247,13 @@ object JoexAppImpl {
|
||||
.withTask(
|
||||
JobTask.json(
|
||||
UpdateCheckTask.taskName,
|
||||
UpdateCheckTask[F](cfg.updateCheck, cfg.sendMail, javaEmil, updateCheck),
|
||||
UpdateCheckTask[F](
|
||||
cfg.updateCheck,
|
||||
cfg.sendMail,
|
||||
javaEmil,
|
||||
updateCheck,
|
||||
ThisVersion.default
|
||||
),
|
||||
UpdateCheckTask.onCancel[F]
|
||||
)
|
||||
)
|
||||
|
@ -24,10 +24,11 @@ object MakeMail {
|
||||
sendCfg: MailSendConfig,
|
||||
cfg: UpdateCheckConfig,
|
||||
smtpCfg: RUserEmail,
|
||||
latestRelease: UpdateCheck.Release
|
||||
latestRelease: UpdateCheck.Release,
|
||||
thisVersion: ThisVersion
|
||||
): Mail[F] = {
|
||||
|
||||
val templateCtx = TemplateCtx(latestRelease)
|
||||
val templateCtx = TemplateCtx(latestRelease, thisVersion)
|
||||
val md = templateCtx.render(cfg.body)
|
||||
val subj = templateCtx.render(cfg.subject)
|
||||
|
||||
@ -49,8 +50,8 @@ object MakeMail {
|
||||
releasedAt: String
|
||||
)
|
||||
object TemplateCtx {
|
||||
def apply(release: UpdateCheck.Release): TemplateCtx =
|
||||
TemplateCtx(UpdateCheck.currentVersion, release.version, release.published_at)
|
||||
def apply(release: UpdateCheck.Release, thisVersion: ThisVersion): TemplateCtx =
|
||||
TemplateCtx(thisVersion.get, release.version, release.published_at)
|
||||
|
||||
implicit val yamuscaConverter: ValueConverter[TemplateCtx] =
|
||||
ValueConverter.deriveConverter[TemplateCtx]
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2020 Docspell Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.joex.updatecheck
|
||||
|
||||
import docspell.joex.BuildInfo
|
||||
|
||||
trait ThisVersion {
|
||||
def get: String
|
||||
}
|
||||
|
||||
object ThisVersion {
|
||||
def default: ThisVersion =
|
||||
constant(BuildInfo.version)
|
||||
|
||||
def constant(value: String): ThisVersion = new ThisVersion {
|
||||
override def get: String = value
|
||||
}
|
||||
}
|
@ -8,8 +8,6 @@ package docspell.joex.updatecheck
|
||||
|
||||
import cats.effect._
|
||||
|
||||
import docspell.joex.BuildInfo
|
||||
|
||||
import io.circe.Decoder
|
||||
import io.circe.generic.semiauto._
|
||||
import org.http4s.circe.CirceEntityDecoder._
|
||||
@ -24,9 +22,6 @@ trait UpdateCheck[F[_]] {
|
||||
|
||||
object UpdateCheck {
|
||||
|
||||
val currentVersion: String =
|
||||
BuildInfo.version
|
||||
|
||||
final case class Release(
|
||||
html_url: String,
|
||||
id: Int,
|
||||
@ -36,13 +31,14 @@ object UpdateCheck {
|
||||
published_at: String
|
||||
) {
|
||||
|
||||
def version: String = tag_name
|
||||
def version: String = tag_name.replaceFirst("v", "")
|
||||
|
||||
def isCurrent: Boolean = {
|
||||
val version = BuildInfo.version
|
||||
version.endsWith("SNAPSHOT") || version == tag_name
|
||||
/** Checks if `thisVersion` is either a SNAPSHOT version or the same as this release.
|
||||
*/
|
||||
def matchesVersion(tv: ThisVersion): Boolean = {
|
||||
val myVersion = tv.get
|
||||
myVersion.endsWith("SNAPSHOT") || myVersion == version
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object Release {
|
||||
|
@ -45,13 +45,14 @@ object UpdateCheckTask {
|
||||
cfg: UpdateCheckConfig,
|
||||
sendCfg: MailSendConfig,
|
||||
emil: Emil[F],
|
||||
updateCheck: UpdateCheck[F]
|
||||
updateCheck: UpdateCheck[F],
|
||||
thisVersion: ThisVersion
|
||||
): Task[F, Args, Unit] =
|
||||
if (cfg.enabled)
|
||||
Task { ctx =>
|
||||
for {
|
||||
_ <- ctx.logger.info(
|
||||
s"Check for updates. Current version is: ${UpdateCheck.currentVersion}"
|
||||
s"Check for updates. Current version is: ${thisVersion.get}"
|
||||
)
|
||||
_ <- ctx.logger.debug(
|
||||
s"Get SMTP connection for ${cfg.senderAccount.asString} and ${cfg.smtpId}"
|
||||
@ -67,7 +68,7 @@ object UpdateCheckTask {
|
||||
)
|
||||
else ().pure[F]
|
||||
_ <-
|
||||
if (latest.isCurrent && !cfg.testRun)
|
||||
if (latest.matchesVersion(thisVersion) && !cfg.testRun)
|
||||
ctx.logger.info(
|
||||
s"Latest release is ${latest.version}, which is the current one. Everything uptodate."
|
||||
)
|
||||
@ -75,7 +76,7 @@ object UpdateCheckTask {
|
||||
ctx.logger.info(
|
||||
s"Sending mail about new release: ${latest.tag_name}"
|
||||
) *> emil(smtpCfg.toMailConfig).send(
|
||||
MakeMail(sendCfg, cfg, smtpCfg, latest)
|
||||
MakeMail(sendCfg, cfg, smtpCfg, latest, thisVersion)
|
||||
)
|
||||
} yield ()
|
||||
}
|
||||
|
Reference in New Issue
Block a user