slack-progressbar 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+49/−39 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Web.Slack.ProgressBar: SlackConfig :: String -> SlackConfig
+ Web.Slack.ProgressBar: SlackConfig :: Text -> SlackConfig
- Web.Slack.ProgressBar: [slackApiToken] :: SlackConfig -> String
+ Web.Slack.ProgressBar: [slackApiToken] :: SlackConfig -> Text
Files
- README.md +11/−0
- app/Main.hs +20/−7
- slack-progressbar.cabal +7/−7
- src/Web/Slack/ProgressBar.hs +11/−25
README.md view
@@ -1,1 +1,12 @@+ # slack-progressbar++This is a simple library for creating and updating Slack messages that contain progress bars.++It can be used to display the progress of a long-running task in a Slack channel, for example as part of CI tooling.++See the code in [Main.hs](./app/Main.hs) for an example which generates the video below.++# Example++
app/Main.hs view
@@ -1,18 +1,24 @@-{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}+{-# LANGUAGE OverloadedStrings, QuasiQuotes, LambdaCase #-} module Main where import Control.Concurrent import Control.Monad.Except-import Data.Maybe+import Data.IORef import Data.String.Interpolate.IsString+import qualified Data.Text as T import Web.Slack.ProgressBar mySlackConfig :: SlackConfig-mySlackConfig = SlackConfig { slackApiToken = "TODO" }+mySlackConfig = SlackConfig { slackApiToken = "my-slack-api-token" } main :: IO ()-main = void $ runExceptT $ do+main = runProgressBar >>= \case+ Left err -> error [i|Progress bar failed: '#{err}'|]+ Right () -> return ()++runProgressBar :: IO (Either T.Text ())+runProgressBar = runExceptT $ do let progressBarInfo = ProgressBarInfo { progressBarInfoTopMessage = Just "Top message" , progressBarInfoBottomMessage = Just "Bottom message"@@ -22,12 +28,19 @@ progressBar <- ExceptT $ createProgressBar mySlackConfig "test-channel" progressBarInfo + attachmentsRef <- liftIO $ newIORef [] forM_ [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] $ \size -> do liftIO $ threadDelay 1000000++ -- Add attachments on a few examples+ when (size `elem` [30, 60, 90]) $+ liftIO $ modifyIORef attachmentsRef (<> [[i|Got failure at #{size}|]])++ attachments <- liftIO $ readIORef attachmentsRef+ ExceptT $ updateProgressBar mySlackConfig progressBar ( progressBarInfo { progressBarInfoSize = Just size- , progressBarInfoAttachments = Just $- (ProgressBarAttachment [i|Hello there #{size}|] "#ff4136")- : (fromMaybe [] (progressBarInfoAttachments progressBarInfo))+ , progressBarInfoAttachments = Just [ProgressBarAttachment x "#ff4136" | x <- attachments]+ , progressBarInfoBottomMessage = Just [i|Currently running at #{size}|] })
slack-progressbar.cabal view
@@ -1,16 +1,16 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: e02cced5857da29a9cf41726beda4002ad8659cc67ab309b5badc64895ed004a+-- hash: 509416a4b76d8017508581fa1643f95f17f011d038a65f18f6ccfdac73118ff6 name: slack-progressbar-version: 0.1.0.0-description: Please see the README on GitHub at <https://github.com/githubuser/slack-progressbar#readme>-homepage: https://github.com/githubuser/slack-progressbar#readme-bug-reports: https://github.com/githubuser/slack-progressbar/issues+version: 0.1.0.1+description: Please see the README on GitHub at <https://github.com/codedownio/slack-progressbar#readme>+homepage: https://github.com/codedownio/slack-progressbar#readme+bug-reports: https://github.com/codedownio/slack-progressbar/issues author: Tom McLaughlin maintainer: tom@codedown.io copyright: 2020 CodeDown@@ -23,7 +23,7 @@ source-repository head type: git- location: https://github.com/githubuser/slack-progressbar+ location: https://github.com/codedownio/slack-progressbar library exposed-modules:
src/Web/Slack/ProgressBar.hs view
@@ -1,4 +1,9 @@-{-# LANGUAGE ScopedTypeVariables, OverloadedStrings, QuasiQuotes, FlexibleContexts, LambdaCase, RecordWildCards #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE RecordWildCards #-} {-| Module: Web.Slack.ProgressBar@@ -7,27 +12,10 @@ Stability: experimental Portability: portable -This is a simple library for creating and updating Slack messages that contain progressbars.+This is a simple library for creating and updating Slack messages that contain progress bars. It can be used to display the progress of a long-running task in a Slack channel, for example as part of CI tooling. -@-main :: IO ()-main = do- let mySlackConfig = SlackConfig { slackApiToken = "my-slack-api-token" }-- let progressBarInfo = def { progressBarInfoTopMessage = Just "Top message"- , progressBarInfoSize = Just 0 }-- result <- runExceptT $ do- progressBar <- ExceptT $ createProgressBar mySlackConfig "test-channel" progressBarInfo-- forM_ [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] $ \\size -> do- threadDelay 1000000- ExceptT $ updateProgressBar mySlackConfig progressBar (progressBarInfo { progressBarInfoSize = Just size })-- putStrLn [i|Result: '#{result}'|]-@-+See <https://github.com/codedownio/slack-progressbar/blob/master/app/Main.hs app/Main.hs> in the repo for example code, or <https://github.com/codedownio/slack-progressbar#readme README.md> on GitHub for an animated GIF. -} module Web.Slack.ProgressBar (@@ -38,7 +26,6 @@ , ProgressBar , ChannelName - -- * Re-exports , SlackConfig (..) ) where @@ -144,18 +131,17 @@ encode' :: ToJSON a => a -> T.Text encode' = T.decodeUtf8 . BL.toStrict . encode --- Inlined and modified slightly from slack-api--- Didn't seem worth it to add that entire library as a dependency just for these+-- Based on code from slack-api -- | Configuration options needed to connect to the Slack API-newtype SlackConfig = SlackConfig { slackApiToken :: String+newtype SlackConfig = SlackConfig { slackApiToken :: T.Text -- ^ Slack API token } deriving (Show) makeSlackCall :: (MonadError T.Text m, MonadIO m) => SlackConfig -> String -> (W.Options -> W.Options) -> m Value makeSlackCall conf method setArgs = do let url = "https://slack.com/api/" ++ method- let setToken = W.param "token" .~ [T.pack (slackApiToken conf)]+ let setToken = W.param "token" .~ [slackApiToken conf] let opts = W.defaults & setToken & setArgs rawResp <- liftIO $ W.getWith opts url resp <- rawResp ^? W.responseBody . _Value ?? "Couldn't parse response"