Skip to content

Commit

Permalink
Restyled by fourmolu
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Jul 12, 2024
1 parent e36b521 commit 1233f05
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 146 deletions.
62 changes: 31 additions & 31 deletions src/Restyler/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,46 +110,46 @@ instance (MonadUnliftIO m, HasLogger app) => MonadProcess (AppT app m) where
liftIO $ Process.callProcess cmd args

callProcessExitCode cmd args = do
logDebug $
"callProcessExitCode"
:# ["command" .= cmd, "arguments" .= args]
logDebug
$ "callProcessExitCode"
:# ["command" .= cmd, "arguments" .= args]
ec <- liftIO $ Process.withCreateProcess proc $ \_ _ _ p ->
Process.waitForProcess p
(if ec == ExitSuccess then logDebug else logWarn) $
"callProcessExitCode"
:# [ "command" .= cmd
, "arguments" .= args
, "exitCode" .= exitCodeInt ec
]
(if ec == ExitSuccess then logDebug else logWarn)
$ "callProcessExitCode"
:# [ "command" .= cmd
, "arguments" .= args
, "exitCode" .= exitCodeInt ec
]
pure ec
where
proc = (Process.proc cmd args) {Process.delegate_ctlc = True}

readProcess cmd args = do
logDebug $
"readProcess"
:# ["command" .= cmd, "arguments" .= args]
logDebug
$ "readProcess"
:# ["command" .= cmd, "arguments" .= args]
output <- liftIO $ Process.readProcess cmd args ""
logDebug $
"readProcess"
:# [ "command" .= cmd
, "arguments" .= args
, "output" .= output
]
logDebug
$ "readProcess"
:# [ "command" .= cmd
, "arguments" .= args
, "output" .= output
]
pure output

readProcessExitCode cmd args = do
logDebug $
"readProcess"
:# ["command" .= cmd, "arguments" .= args]
logDebug
$ "readProcess"
:# ["command" .= cmd, "arguments" .= args]
(ec, output, err) <- liftIO $ Process.readProcessWithExitCode cmd args ""
(if ec == ExitSuccess then logDebug else logWarn) $
"readProcessExitCode"
:# [ "command" .= cmd
, "arguments" .= args
, "output" .= output
, "errorOutput" .= err
]
(if ec == ExitSuccess then logDebug else logWarn)
$ "readProcessExitCode"
:# [ "command" .= cmd
, "arguments" .= args
, "output" .= output
, "errorOutput" .= err
]
pure (ec, output)

instance (MonadUnliftIO m, HasLogger app) => MonadExit (AppT app m) where
Expand Down Expand Up @@ -186,9 +186,9 @@ runGitHubInternal
=> GenRequest m k a
-> n a
runGitHubInternal req = do
logDebug $
"runGitHub"
:# ["request" .= show @Text (displayGitHubRequest req)]
logDebug
$ "runGitHub"
:# ["request" .= show @Text (displayGitHubRequest req)]
auth <- OAuth . encodeUtf8 . oAccessToken <$> view optionsL
result <- liftIO $ do
mgr <- getGlobalManager
Expand Down
18 changes: 9 additions & 9 deletions src/Restyler/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ loadConfig
)
=> m Config
loadConfig =
loadConfigFrom (map ConfigPath configPaths) $
handleTo ConfigErrorInvalidRestylersYaml
. getAllRestylersVersioned
. runIdentity
. cfRestylersVersion
loadConfigFrom (map ConfigPath configPaths)
$ handleTo ConfigErrorInvalidRestylersYaml
. getAllRestylersVersioned
. runIdentity
. cfRestylersVersion

loadConfigFrom
:: (MonadUnliftIO m, MonadSystem m)
Expand Down Expand Up @@ -284,10 +284,10 @@ decodeThrow = either throwIO pure . Yaml.decodeThrow
resolveRestylers :: MonadIO m => ConfigF Identity -> [Restyler] -> m Config
resolveRestylers ConfigF {..} allRestylers = do
restylers <-
either (throwIO . ConfigErrorInvalidRestylers) pure $
overrideRestylers allRestylers $
unSketchy $
runIdentity cfRestylers
either (throwIO . ConfigErrorInvalidRestylers) pure
$ overrideRestylers allRestylers
$ unSketchy
$ runIdentity cfRestylers

pure
Config
Expand Down
26 changes: 13 additions & 13 deletions src/Restyler/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ restylerMain = do
logInfo "Restyling produced differences"

patch <- getRestyledPatch
withThreadContext ["patch" .= True] $
traverse_ (logInfo . (:# [])) $
T.lines patch
withThreadContext ["patch" .= True]
$ traverse_ (logInfo . (:# []))
$ T.lines patch

-- This message only makes sense in the context of a Job
for_ mJobUrl $ \jobUrl -> do
Expand All @@ -75,20 +75,20 @@ restylerMain = do
then logWarn "Ignoring auto:true because PR is a fork"
else do
logInfo "Pushing changes directly to PR branch"
gitPush $
unpack $
pullRequestLocalHeadRef pullRequest
<> ":"
<> pullRequestHeadRef pullRequest
gitPush
$ unpack
$ pullRequestLocalHeadRef pullRequest
<> ":"
<> pullRequestHeadRef pullRequest
exitWithInfo "Restyling successful"

-- NB there is the edge-case of switching this off mid-PR. A previously
-- opened Restyle PR would stop updating at that point.
whenConfig (not . cPullRequests) $ do
sendPullRequestStatus $ DifferencesStatus mJobUrl
logInfo $
"Not creating Restyle PR"
:# ["reason" .= ("disabled by config" :: Text)]
logInfo
$ "Not creating Restyle PR"
:# ["reason" .= ("disabled by config" :: Text)]
exitWithInfo "Please correct style using the process described above"

let
Expand Down Expand Up @@ -150,8 +150,8 @@ getRestyledPatch = do
getChangedPaths :: MonadGitHub m => PullRequest -> m [FilePath]
getChangedPaths pullRequest = do
files <-
runGitHub $
pullRequestFilesR
runGitHub
$ pullRequestFilesR
(pullRequestOwnerName pullRequest)
(pullRequestRepoName pullRequest)
(pullRequestNumber pullRequest)
Expand Down
22 changes: 11 additions & 11 deletions src/Restyler/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ instance HasOptions Options where
optionsL = id

instance HasManifestOption Options where
manifestOptionL = lens (toManifestOption . oManifest) $
\x y -> x {oManifest = unManifestOption y}
manifestOptionL = lens (toManifestOption . oManifest)
$ \x y -> x {oManifest = unManifestOption y}

instance HasHostDirectoryOption Options where
hostDirectoryOptionL = lens (toHostDirectoryOption . oHostDirectory) $
\x y -> x {oHostDirectory = unHostDirectoryOption y}
hostDirectoryOptionL = lens (toHostDirectoryOption . oHostDirectory)
$ \x y -> x {oHostDirectory = unHostDirectoryOption y}

instance HasImageCleanupOption Options where
imageCleanupOptionL = lens (toImageCleanupOption . oImageCleanup) $
\x y -> x {oImageCleanup = unImageCleanupOption y}
imageCleanupOptionL = lens (toImageCleanupOption . oImageCleanup)
$ \x y -> x {oImageCleanup = unImageCleanupOption y}

instance HasRestrictions Options where
restrictionsL = lens oRestrictions $ \x y -> x {oRestrictions = y}
Expand All @@ -82,11 +82,11 @@ parseOptions :: IO Options
parseOptions = do
EnvOptions {..} <- Env.parse id envParser
CLIOptions {..} <-
execParser $
info (optionsParser <**> helper) $
fullDesc
<> progDesc
"Restyle a GitHub Pull Request"
execParser
$ info (optionsParser <**> helper)
$ fullDesc
<> progDesc
"Restyle a GitHub Pull Request"

pure
Options
Expand Down
16 changes: 8 additions & 8 deletions src/Restyler/PullRequest/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pullRequestFileStatusToText = \case

pullRequestFileToChangedPath :: PullRequestFile -> Maybe FilePath
pullRequestFileToChangedPath file = do
guard $
file.status
`elem` [ PullRequestFileAdded
, PullRequestFileCopied
, PullRequestFileChanged
, PullRequestFileRenamed
, PullRequestFileModified
]
guard
$ file.status
`elem` [ PullRequestFileAdded
, PullRequestFileCopied
, PullRequestFileChanged
, PullRequestFileRenamed
, PullRequestFileModified
]

pure $ file.filename

Check warning on line 73 in src/Restyler/PullRequest/File.hs

View workflow job for this annotation

GitHub Actions / lint

Suggestion in pullRequestFileToChangedPath in module Restyler.PullRequest.File: Redundant $ ▫︎ Found: "pure $ file.filename" ▫︎ Perhaps: "pure file.filename"
44 changes: 22 additions & 22 deletions src/Restyler/Restrictions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ data Restrictions = Restrictions

restrictionOptions :: Restrictions -> [String]
restrictionOptions Restrictions {..} =
concat $
catMaybes
concat
$ catMaybes
[ (\b -> if b then ["--net", "none"] else []) <$> getLast netNone
, (\b -> if b then ["--cap-drop", "all"] else []) <$> getLast capDropAll
, (\n -> ["--cpu-shares", show n]) <$> getLast cpuShares
Expand All @@ -54,26 +54,26 @@ envRestrictions =

parseOverrides :: Env.Parser Env.Error Restrictions
parseOverrides =
Env.prefixed "RESTYLER_" $
Restrictions
<$> ( fmap not
<$> lastSwitch
"NO_NET_NONE"
"Run restylers without --net=none"
)
<*> ( fmap not
<$> lastSwitch
"NO_CAP_DROP_ALL"
"Run restylers without --cap-drop=all"
)
<*> lastReader
readNat
"CPU_SHARES"
"Run restylers with --cpu-shares=<number>"
<*> lastReader
readBytes
"MEMORY"
"Run restylers with --memory=<number>[b|k|m|g]"
Env.prefixed "RESTYLER_"
$ Restrictions
<$> ( fmap not
<$> lastSwitch
"NO_NET_NONE"
"Run restylers without --net=none"
)
<*> ( fmap not
<$> lastSwitch
"NO_CAP_DROP_ALL"
"Run restylers without --cap-drop=all"
)
<*> lastReader
readNat
"CPU_SHARES"
"Run restylers with --cpu-shares=<number>"
<*> lastReader
readBytes
"MEMORY"
"Run restylers with --memory=<number>[b|k|m|g]"
where
lastSwitch
:: String
Expand Down
50 changes: 25 additions & 25 deletions src/Restyler/Restyler/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ runRestylersWith run config@Config {..} allPaths = do
if lenPaths > maxPaths
then case cpcOutcome cChangedPaths of
MaximumChangedPathsOutcomeSkip -> do
logWarn $
"Number of changed paths is greater than configured maximum"
:# ["paths" .= lenPaths, "maximum" .= maxPaths]
logWarn
$ "Number of changed paths is greater than configured maximum"
:# ["paths" .= lenPaths, "maximum" .= maxPaths]
pure []
MaximumChangedPathsOutcomeError ->
throwIO $ TooManyChangedPaths lenPaths maxPaths
Expand Down Expand Up @@ -185,16 +185,16 @@ withFilteredPaths restylers paths run = do
else rInclude r
included = includePath includes path

logDebug $
"Matching paths"
:# [ "name" .= rName r
, "path" .= path
, "matched" .= matched
, "includes" .= includes
, "included" .= included
, "interpreter" .= mInterpreter
-- , "filtered" .= filtered
]
logDebug
$ "Matching paths"
:# [ "name" .= rName r
, "path" .= path
, "matched" .= matched
, "includes" .= includes
, "included" .= included
, "interpreter" .= mInterpreter
-- , "filtered" .= filtered
]

pure $ if included then Just path else Nothing

Expand Down Expand Up @@ -322,12 +322,12 @@ dockerRunRestyler r@Restyler {..} WithProgress {..} = do
-- to avoid out-of-space errors.
withImageCleanup f = if imageCleanup then f `finally` cleanupImage else f

logInfo $
"Restyling"
:# [ "restyler" .= rName
, "run" .= progress
, "style" .= rRunStyle
]
logInfo
$ "Restyling"
:# [ "restyler" .= rName
, "run" .= progress
, "style" .= rRunStyle
]

flushLogger -- so docker stdout is not interleaved
ec <- withImageCleanup $ case pItem of
Expand All @@ -353,15 +353,15 @@ dockerRunRestyler r@Restyler {..} WithProgress {..} = do
eec <- tryAny $ callProcessExitCode "docker" ["image", "rm", "--force", rImage]
case eec of
Left ex ->
logWarn $
"Exception removing Restyler image"
:# ["exception" .= displayException ex]
logWarn
$ "Exception removing Restyler image"
:# ["exception" .= displayException ex]
Right ExitSuccess ->
logInfo "Removed Restyler image"
Right (ExitFailure i) ->
logWarn $
"Error removing Restyler image"
:# ["status" .= i]
logWarn
$ "Error removing Restyler image"
:# ["status" .= i]

fixNewline :: Text -> Text
fixNewline = (<> "\n") . T.dropWhileEnd (== '\n')
Expand Down
Loading

0 comments on commit 1233f05

Please sign in to comment.