Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle pb/action #236

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 10 additions & 10 deletions src/Restyler/GHA/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ main = do
for_ results $ \RestylerResult {..} ->
case rrOutcome of
ChangesCommitted paths sha -> do
logInfo $
"Changes committed"
:# [ "restyler" .= rName rrRestyler
, "paths" .= paths
, "sha" .= sha
]
logInfo
$ "Changes committed"
:# [ "restyler" .= rName rrRestyler
, "paths" .= paths
, "sha" .= sha
]
x ->
logDebug $
"Outcome"
:# ["restyler" .= rName rrRestyler]
<> objectToPairs x
logDebug
$ "Outcome"
:# ["restyler" .= rName rrRestyler]
<> objectToPairs x

logExit :: (MonadIO m, MonadLogger m) => SomeException -> m a
logExit ex = do
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 @@

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
Loading
Loading