Skip to content

Commit

Permalink
Expose restylerEnv, instead of individual fields
Browse files Browse the repository at this point in the history
Our agents have been deployed to use this opaque value as-is. From
there, it's an API-only change to adjust restyler environment variables.
  • Loading branch information
pbrisbin committed May 30, 2023
1 parent f4b1c17 commit e35e3b8
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/Restyled/Api/Repo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ data ApiRepo = ApiRepo
, installationId :: InstallationId
, marketplacePlanAllows :: Maybe MarketplacePlanAllows
, restylerImage :: RestylerImage
, restylerLogLevel :: ApiLogLevel
, restylerLogFormat :: Text
-- ^ TODO: 'LogFormat' needs 'ToJSON'
, restylerEnv :: [Text]
}
deriving stock (Show, Generic)
deriving anyclass ToJSON

newtype ApiLogLevel = ApiLogLevel
{ unApiLogLevel :: LogLevel
}
deriving newtype Show

instance ToJSON ApiLogLevel where
toJSON = toJSON . logLevelToText . unApiLogLevel
toEncoding = toEncoding . logLevelToText . unApiLogLevel

apiRepo :: Entity Repo -> AppSettings -> Maybe MarketplacePlanAllows -> ApiRepo
apiRepo (Entity _ Repo {..}) AppSettings {..} mAllows = ApiRepo
{ owner = repoOwner
Expand All @@ -44,10 +33,15 @@ apiRepo (Entity _ Repo {..}) AppSettings {..} mAllows = ApiRepo
, installationId = repoInstallationId
, marketplacePlanAllows = mAllows
, restylerImage = fromMaybe appRestylerImage repoRestylerImage
, restylerLogLevel = ApiLogLevel
$ if repoDebugEnabled then LevelDebug else guessLogLevel appLogSettings
, restylerLogFormat = "json"
, restylerEnv =
[ "DEBUG=" <> if logLevel == LevelDebug then "x" else ""
, "LOG_LEVEL=" <> logLevelToText logLevel
, "LOG_FORMAT=json"
]
}
where
logLevel =
if repoDebugEnabled then LevelDebug else guessLogLevel appLogSettings

logLevelToText :: LogLevel -> Text
logLevelToText = \case
Expand Down

0 comments on commit e35e3b8

Please sign in to comment.