From e2db399c173c8424cac75e724520afdfcd6c6e66 Mon Sep 17 00:00:00 2001 From: Ondrej Rafaj Date: Wed, 16 Oct 2019 12:39:39 +0100 Subject: [PATCH] adding commit to info --- .../Controllers/SettingsController.swift | 1 - Sources/ApiCore/Model/Info.swift | 17 ++++++++++++++++- Sources/ApiCore/Model/Setting.swift | 1 - 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Sources/ApiCore/Controllers/SettingsController.swift b/Sources/ApiCore/Controllers/SettingsController.swift index 148ef9e..ac8e20c 100644 --- a/Sources/ApiCore/Controllers/SettingsController.swift +++ b/Sources/ApiCore/Controllers/SettingsController.swift @@ -7,7 +7,6 @@ import Foundation import Vapor -import ApiCore import ErrorsCore import FluentPostgreSQL diff --git a/Sources/ApiCore/Model/Info.swift b/Sources/ApiCore/Model/Info.swift index b5953e6..e6e4537 100644 --- a/Sources/ApiCore/Model/Info.swift +++ b/Sources/ApiCore/Model/Info.swift @@ -56,6 +56,9 @@ public struct Info: Content { /// Gitlab teams public let allowedGitlabGroups: [String] + /// Commit hash (if available, n/a otherwise) + public let commit: String + enum CodingKeys: String, CodingKey { case allowLogin = "allow_login" case singleTeam = "single_team" @@ -67,6 +70,7 @@ public struct Info: Content { case allowedGithubTeams = "allowed_github_teams" case gitlabEnabled = "gitlab_enabled" case allowedGitlabGroups = "allowed_gitlab_groups" + case commit } } @@ -104,6 +108,16 @@ public struct Info: Content { let url = try fm.url(for: "server/image/\($0.rawValue)", on: req) return Info.Icon(size: $0, url: url) }) + + let dc = DirectoryConfig.detect() + let url = URL(fileURLWithPath: dc.workDir).appendingPathComponent("Resources").appendingPathComponent("commit.txt") + let commit: String + if FileManager.default.fileExists(atPath: url.path), let c = try? String(contentsOfFile: url.path) { + commit = c + } else { + commit = "n/a" + } + config = Config( singleTeam: ApiCoreBase.configuration.general.singleTeam, allowLogin: ApiCoreBase.configuration.auth.allowLogin, @@ -114,7 +128,8 @@ public struct Info: Content { githubEnabled: ApiCoreBase.configuration.auth.github.enabled, allowedGithubTeams: ApiCoreBase.configuration.auth.github.teams, gitlabEnabled: ApiCoreBase.configuration.auth.gitlab.enabled, - allowedGitlabGroups: ApiCoreBase.configuration.auth.gitlab.groups + allowedGitlabGroups: ApiCoreBase.configuration.auth.gitlab.groups, + commit: commit ) } diff --git a/Sources/ApiCore/Model/Setting.swift b/Sources/ApiCore/Model/Setting.swift index 9637066..a50a316 100644 --- a/Sources/ApiCore/Model/Setting.swift +++ b/Sources/ApiCore/Model/Setting.swift @@ -9,7 +9,6 @@ import Foundation import Vapor import Fluent import FluentPostgreSQL -import ApiCore import ErrorsCore