libjenkins 0.6.0 → 0.7.0
raw patch · 12 files changed
+159/−136 lines, 12 files
Files
- CHANGELOG.markdown +96/−0
- CHANGELOG.md +0/−88
- LICENSE +1/−5
- README.markdown +4/−0
- README.md +0/−4
- bench/README.markdown +14/−0
- bench/README.md +0/−14
- example/rename-jobs.hs +2/−1
- libjenkins.cabal +6/−6
- src/Jenkins/Rest.hs +24/−9
- src/Jenkins/Rest/Internal.hs +11/−8
- test/Jenkins/RestSpec.hs +1/−1
+ CHANGELOG.markdown view
@@ -0,0 +1,96 @@+0.7.0+=====++ * Jenkins' responses to `POST` requests are being read again++ * Added `groovy` to ease the communication with the embedded Groovy+ interpreter (see example/repl.hs)++0.6.0+=====++ * Made `orElse` more powerful. The old version is available as `orElse_`++ * Renamed a bunch of things. The `Jenkins.Rest` module is intended to be imported qualified.++ * Switched to the transformer version of the Church-encoded free monad++ * Removed `getS`. As a side-effect, `get` doesn't leak like crazy anymore++ * Generalized `traverseC_` (again)++ * Removed redundant `jenkinsPort` option: `jenkinsUrl` handles port numbers well enough++ * Reworked API method construction. The new version is safer (it's impossible to forget+ to specify the format of the response), less magical (format is a separate argument to+ the query function), and has fewer corner cases++0.5.0+=====++ * Replaced `concurrentlys` and `concurrentlys_` with `traverseC` and `traverseC_`+ respectively. Quick migration guide:++ + `concurrentlys` -> `traverseC id . toList`+ + `concurrentlys_` -> `traverseC_ id . toList`++ * Added `getS` for tighter control of Jenkins responses consumption++ * `post` variants do not read the response body at all anymore++ * Added `orElse`++ * Removed `runJenkinsThrowing` from the API++ * `runJenkins` only catches exceptions thrown by the execution of `Jenkins` queries++ * Switched to `network-uri`++ * Removed `io` from the API. Quick migration guide: `io` -> `liftIO`++0.4.3.0+=======++ * Upgraded dependencies' bounds++0.4.2.0+=======++ * Generalized `ConnectInfo`++0.4.1.0+=======++ * Generalized `io`++ * Added `runJenkinsThrowing`++0.4.0.0+=======++ * Switched to `Text` for username and API token (password)++ * Supported `lens-4.0`++0.3.0.0+=======++ * `restart` does not send requests to `$jenkins_url/restart` anymore. Instead, it calls+ `$jenkins_url/safe-restart` which waits running jobs to complete. New `forceRestart` function+ does now what `restart` did before++ * Massive refactoring++ * More optics in `Network.HTTP.Conduit.Lens`++ * Added `overallLoad` and `computer` REST API methods shortcuts++0.2.0.0+=======++ * Moved onto http-conduit 2.0 API.++0.1.0.0+=======++ * Initial release. REST and Discovery APIs support.
− CHANGELOG.md
@@ -1,88 +0,0 @@-0.6.0-=====-- * Made `orElse` more powerful. The old version is available as `orElse_`-- * Renamed a bunch of things. The `Jenkins.Rest` module is intended to be imported qualified.-- * Switched to the transformer version of the Church-encoded free monad-- * Removed `getS`. As a side-effect, `get` doesn't leak like crazy anymore-- * Generalized `traverseC_` (again)-- * Removed redundant `jenkinsPort` option: `jenkinsUrl` handles port numbers well enough-- * Reworked API method construction. The new version is safer (it's impossible to forget- to specify the format of the response), less magical (format is a separate argument to- the query function), and has fewer corner cases--0.5.0-=====-- * Replaced `concurrentlys` and `concurrentlys_` with `traverseC` and `traverseC_`- respectively. Quick migration guide:-- + `concurrentlys` -> `traverseC id . toList`- + `concurrentlys_` -> `traverseC_ id . toList`-- * Added `getS` for tighter control of Jenkins responses consumption-- * `post` variants do not read the response body at all anymore-- * Added `orElse`-- * Removed `runJenkinsThrowing` from the API-- * `runJenkins` only catches exceptions thrown by the execution of `Jenkins` queries-- * Switched to `network-uri`-- * Removed `io` from the API. Quick migration guide: `io` -> `liftIO`--0.4.3.0-=======-- * Upgraded dependencies' bounds--0.4.2.0-=======-- * Generalized `ConnectInfo`--0.4.1.0-=======-- * Generalized `io`-- * Added `runJenkinsThrowing`--0.4.0.0-=======-- * Switched to `Text` for username and API token (password)-- * Supported `lens-4.0`--0.3.0.0-=======-- * `restart` does not send requests to `$jenkins_url/restart` anymore. Instead, it calls- `$jenkins_url/safe-restart` which waits running jobs to complete. New `forceRestart` function- does now what `restart` did before-- * Massive refactoring-- * More optics in `Network.HTTP.Conduit.Lens`-- * Added `overallLoad` and `computer` REST API methods shortcuts--0.2.0.0-=======-- * Moved onto http-conduit 2.0 API.--0.1.0.0-=======-- * Initial release. REST and Discovery APIs support.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013, Matvey Aksenov+Copyright (c) 2013-2014, Matvey Aksenov All rights reserved. @@ -12,10 +12,6 @@ copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.-- * Neither the name of Matvey Aksenov nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ README.markdown view
@@ -0,0 +1,4 @@+libjenkins+==========+[](https://hackage.haskell.org/package/libjenkins)+[](https://travis-ci.org/supki/libjenkins)
− README.md
@@ -1,4 +0,0 @@-libjenkins-==========-[](https://hackage.haskell.org/package/libjenkins)-[](https://travis-ci.org/supki/libjenkins)
+ bench/README.markdown view
@@ -0,0 +1,14 @@+# Benchmarks++## `Concurrent.hs`++ ./bench/Concurrency (concurrent|sequential) HOST PORT USERNAME PASSWORD++Measures the concurrency impact on time API queries take.++Concurrency is the most useful if you:++ * Do not use any kind of "proxy" servers (apache2, nginx, etc) and _especially_ https+ * Try to run queries from the nearest machine possible: network latency matters++Under these conditions, expect to get ~2x speedup from using `concurrent` mode on Jenkins server with ~500 jobs.
− bench/README.md
@@ -1,14 +0,0 @@-# Benchmarks--## `Concurrent.hs`-- ./bench/Concurrency (concurrent|sequential) HOST PORT USERNAME PASSWORD--Measures the concurrency impact on time API queries take.--Concurrency is the most useful if you:-- * Do not use any kind of "proxy" servers (apache2, nginx, etc) and _especially_ https- * Try to run queries from the nearest machine possible: network latency matters--Under these conditions, expect to get ~2x speedup from using `concurrent` mode on Jenkins server with ~500 jobs.
example/rename-jobs.hs view
@@ -3,6 +3,7 @@ -- | Rename jobs matching supplied pattern module Main (main) where +import Control.Applicative -- base import Control.Lens -- lens import Control.Monad (when) -- base import Data.Aeson.Lens -- lens-aeson@@ -65,7 +66,7 @@ yes <- prompt $ Text.unwords ["Rename", name, "to", name', "? [y/n]"] when yes $ -- if user agrees then voodoo comes- Jenkins.post_ (Jenkins.job name -/- "doRename" -?- "newName" -=- name')+ () <$ Jenkins.post_ (Jenkins.job name -/- "doRename" -?- "newName" -=- name') -- asks user until she enters 'y' or 'n' prompt message = liftIO . fix $ \loop -> do
libjenkins.cabal view
@@ -1,18 +1,18 @@ name: libjenkins-version: 0.6.0+version: 0.7.0 synopsis: Jenkins API interface description: Jenkins API interface. It supports REST and Discovery APIs-license: BSD3+license: BSD2 license-file: LICENSE author: Matvey Aksenov maintainer: matvey.aksenov@gmail.com category: Network build-type: Simple extra-source-files:- README.md- CHANGELOG.md+ README.markdown+ CHANGELOG.markdown bench/Concurrency.hs- bench/README.md+ bench/README.markdown example/grep-jobs.hs example/rename-jobs.hs example/discover.hs@@ -26,7 +26,7 @@ source-repository this type: git location: https://github.com/supki/libjenkins- tag: 0.6.0+ tag: 0.7.0 library default-language:
src/Jenkins/Rest.hs view
@@ -32,6 +32,7 @@ , Jenkins.Rest.traverse_ -- ** Convenience , postXml+ , groovy , reload , restart , forceRestart@@ -42,7 +43,7 @@ , JenkinsException(..) -- * Reexports , liftIO- , Request+ , Http.Request ) where import Control.Applicative ((<$))@@ -55,7 +56,10 @@ import qualified Data.Foldable as F import Data.Monoid (mempty) import Data.Text (Text)-import Network.HTTP.Client (Request, requestHeaders)+import qualified Data.Text.Lazy as Text.Lazy+import qualified Data.Text.Lazy.Encoding as Text.Lazy+import qualified Network.HTTP.Client as Http+import qualified Network.HTTP.Types as Http import Jenkins.Rest.Internal import Jenkins.Rest.Method@@ -167,11 +171,11 @@ get (Formatter f) m = liftJ (Get (f m) id) -- | Perform a @POST@ request-post :: (forall f. Method Complete f) -> Lazy.ByteString -> JenkinsT m ()-post m body = liftJ (Post m body ())+post :: (forall f. Method Complete f) -> Lazy.ByteString -> JenkinsT m Lazy.ByteString+post m body = liftJ (Post m body id) -- | Perform a @POST@ request without a payload-post_ :: (forall f. Method Complete f) -> JenkinsT m ()+post_ :: (forall f. Method Complete f) -> JenkinsT m Lazy.ByteString post_ m = post m mempty -- | A simple exception handler. If an exception is raised while the action is@@ -182,7 +186,7 @@ -- | A simpler exception handler -- -- @--- orElse_ a b = 'orElse' a (\_ -> b)+-- orElse_ a b = 'orElse' a (\\_ -> b) -- @ orElse_ :: JenkinsT m a -> JenkinsT m a -> JenkinsT m a orElse_ a b = orElse a (\_ -> b)@@ -192,7 +196,7 @@ -- (think 'Control.Monad.Trans.Reader.local') -- -- This is useful for setting the appropriate headers, response timeouts and the like-locally :: (Request -> Request) -> JenkinsT m a -> JenkinsT m a+locally :: (Http.Request -> Http.Request) -> JenkinsT m a -> JenkinsT m a locally f j = liftJ (With f j id) -- | Disconnect from Jenkins. The following actions are ignored.@@ -223,10 +227,21 @@ -- -- Sets up the correct @Content-Type@ header. Mostly useful for updating @config.xml@ -- files for jobs, views, etc-postXml :: (forall f. Method Complete f) -> Lazy.ByteString -> JenkinsT m ()-postXml m = locally (\r -> r { requestHeaders = xmlHeader : requestHeaders r }) . post m+postXml :: (forall f. Method Complete f) -> Lazy.ByteString -> JenkinsT m Lazy.ByteString+postXml m = locally (\r -> r { Http.requestHeaders = xmlHeader : Http.requestHeaders r }) . post m where xmlHeader = ("Content-Type", "text/xml")++-- | Perform a @POST@ request to @/scriptText@+groovy+ :: Text.Lazy.Text -- ^ Groovy source code+ -> JenkinsT m Text.Lazy.Text+groovy script = locally (\r -> r { Http.requestHeaders = ascii : Http.requestHeaders r }) $+ liftJ (Post "scriptText" body Text.Lazy.decodeUtf8)+ where+ body = Lazy.fromChunks+ [Http.renderSimpleQuery False [("script", Lazy.toStrict (Text.Lazy.encodeUtf8 script))]]+ ascii = ("Content-Type", "application/x-www-form-urlencoded") -- | Reload jenkins configuration from disk --
src/Jenkins/Rest/Internal.hs view
@@ -63,7 +63,6 @@ #if MIN_VERSION_free(5,0,0) JenkinsT f <*> JenkinsT x = JenkinsT (f <*> x) #else- -- https://github.com/ekmett/free/pull/80 JenkinsT f <*> JenkinsT x = JenkinsT (forwards (Backwards f <*> Backwards x)) #endif @@ -93,7 +92,7 @@ data JF m a where Get :: Method Complete f -> (ByteString -> a) -> JF n a- Post :: (forall f. Method Complete f) -> ByteString -> a -> JF m a+ Post :: (forall f. Method Complete f) -> ByteString -> (ByteString -> a) -> JF m a Conc :: JenkinsT m a -> JenkinsT m b -> (a -> b -> c) -> JF m c Or :: JenkinsT m a -> (JenkinsException -> JenkinsT m a) -> JF m a With :: (Request -> Request) -> JenkinsT m b -> (b -> a) -> JF m a@@ -101,7 +100,7 @@ instance Functor (JF m) where fmap f (Get m g) = Get m (f . g)- fmap f (Post m body a) = Post m body (f a)+ fmap f (Post m body g) = Post m body (f . g) fmap f (Conc m n g) = Conc m n (\a b -> f (g a b)) fmap f (Or a b) = Or (fmap f a) (fmap f . b) fmap f (With h j g) = With h j (f . g)@@ -178,13 +177,11 @@ interpreter man = go where go :: JF m (InterpT m a) -> InterpT m a go (Get m next) = InterpT $ do- req <- lift Reader.ask- res <- liftIO $ wrapException (liftM Http.responseBody (Http.httpLbs (prepareGet m req) man))+ res <- request man (prepareGet m) runInterpT (next res) go (Post m body next) = InterpT $ do- req <- lift Reader.ask- _ <- liftIO $ wrapException (Http.httpNoBody (preparePost m body req) man)- runInterpT next+ res <- request man (preparePost m body)+ runInterpT (next res) go (Conc ja jb next) = do (a, b) <- intoM man $ \run -> concurrently (run ja) (run jb) c <- outoM (return a)@@ -198,6 +195,12 @@ res <- mapMaybeT (Reader.local f) (runInterpT (iterInterpT man jenk)) runInterpT (next res) go Dcon = mzero++request :: (MonadIO m, MonadReader e m) => Http.Manager -> (e -> Request) -> m ByteString+request man f = do+ req <- ask+ res <- liftIO $ wrapException (liftM Http.responseBody (Http.httpLbs (f req) man))+ return res intoM :: forall m a. (MonadIO m, MonadBaseControl IO m)
test/Jenkins/RestSpec.hs view
@@ -86,7 +86,7 @@ fmap (r :) (n mempty) go (Post m body n) = do r <- render (\x y -> QPost x body y) m- fmap (r :) n+ fmap (r :) (n mempty) go Dcon = return [QDisconnect]