File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name : bartlett
2- version : 1.1.0
2+ version : 1.1.1
33synopsis : The Jenkins command-line tool to serve your needs.
44description : Please see README.md
55homepage : https://github.com/Nike-inc/bartlett
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ postBuild ::
4040 -> Maybe JobParameters -- ^ Optional set of job parameters to trigger with.
4141 -> IO ()
4242postBuild user base path parameters = do
43- resp <- execRequest " post " reqOpts reqUri Nothing
43+ resp <- execRequest Post reqOpts reqUri Nothing
4444 BL. putStrLn . encodePretty . BU. toResponseStatus $
4545 resp ^. responseStatus
4646 where (suffix, buildOpts) = consBuildType parameters
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ getConfig :: BasicAuthUser a =>
3131 -> JobPath -- The Job for the given Jenkins instance to interact with.
3232 -> IO () -- The XML configuration for the given job.
3333getConfig user base path = do
34- resp <- execRequest " get " reqOpts (configUri base path) Nothing
34+ resp <- execRequest Get reqOpts (configUri base path) Nothing
3535 BL. putStrLn $ resp ^. responseBody
3636 where reqOpts = defaults & auth ?~ getBasicAuth user
3737
@@ -44,6 +44,6 @@ updateConfig :: BasicAuthUser a =>
4444 -> IO ()
4545updateConfig user base path configPath = do
4646 configFile <- BL. readFile configPath
47- resp <- execRequest " post " reqOpts (configUri base path) (Just configFile)
47+ resp <- execRequest Post reqOpts (configUri base path) (Just configFile)
4848 BL. putStrLn . encodePretty . toResponseStatus $ resp ^. responseStatus
4949 where reqOpts = defaults & auth ?~ getBasicAuth user
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ getInfo ::
3333 -> IO ()
3434getInfo user base [] = return ()
3535getInfo user base (path: paths) = do
36- resp <- execRequest " get " reqOpts reqUri Nothing
36+ resp <- execRequest Get reqOpts reqUri Nothing
3737 BL. putStrLn . toPrettyJson $ resp ^. responseBody
3838 getInfo user base paths
3939 where reqOpts = defaults & auth ?~ getBasicAuth user
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ module Bartlett.Network (
1818)where
1919
2020import Bartlett.Util (toResponseStatus , withForcedSSL )
21+ import Bartlett.Types (RequestType (Get , Post ))
2122
2223import qualified Control.Exception as E
2324import Data.Aeson.Encode.Pretty (encodePretty )
@@ -30,7 +31,7 @@ import qualified Network.Wreq.Session as S
3031
3132-- | General request handler that provides basic error handling.
3233execRequest ::
33- ByteString -- ^ The type of request to make (e.g. "get")
34+ RequestType -- ^ The type of request to make
3435 -> Options -- ^ Request params to pass along with the request.
3536 -> ByteString -- ^ The uri to make the request to
3637 -> Maybe ByteString -- ^ The file to upload to the Jenkins instance.
@@ -41,13 +42,13 @@ execRequest requestType opts reqUrl postBody =
4142 -- TODO Need to get a CSRF crumb
4243 -- JENKINS_URL/crumbIssuer/api/json?xpath=?xpath=concat(//crumbRequestField,":",//crumb)')
4344 -- TODO create a proper sum type for requestType
44- " post " ->
45+ Post ->
4546 postSession reqUrl
4647 `E.catch`
4748 recoverableErrorHandler (postSession $ withForcedSSL reqUrl)
4849 where fileToUpload = fromMaybe " " postBody :: ByteString
4950 postSession url = S. postWith opts session (unpack url) fileToUpload
50- " get " ->
51+ Get ->
5152 getSession reqUrl
5253 `E.catch`
5354 recoverableErrorHandler (getSession $ withForcedSSL reqUrl)
Original file line number Diff line number Diff line change @@ -10,7 +10,25 @@ Stability : stable
1010
1111Types and type alises used throughout Bartlett.
1212-}
13- module Bartlett.Types where
13+ module Bartlett.Types (
14+ -- * Type Aliases
15+ JenkinsInstance ,
16+ Username ,
17+ Password ,
18+ JobPath ,
19+ JobParameters ,
20+ Profile ,
21+ ConfigPath ,
22+ -- * User types
23+ BasicAuthUser (.. ),
24+ User (.. ),
25+ -- * Command-Line Types
26+ Command (.. ),
27+ Options (.. ),
28+ -- * Network Types
29+ StatusResponse (.. ),
30+ RequestType (.. )
31+ ) where
1432
1533import Data.Aeson (ToJSON , FromJSON )
1634import Data.ByteString.Lazy.Char8 (ByteString , toStrict )
@@ -70,3 +88,6 @@ data StatusResponse = StatusResponse {
7088-- Derived JSON serlializers
7189instance ToJSON StatusResponse
7290instance FromJSON StatusResponse
91+
92+ -- | Incomplete sum type for network requests
93+ data RequestType = Get | Post
You can’t perform that action at this time.
0 commit comments