travis (empty) → 0.1.0.0
raw patch · 5 files changed
+160/−0 lines, 5 filesdep +aesondep +basedep +bytestringsetup-changed
Dependencies added: aeson, base, bytestring, http-conduit, transformers
Files
- LICENSE +19/−0
- Setup.hs +2/−0
- src/Travis.hs +46/−0
- src/Travis/Types.hs +71/−0
- travis.cabal +22/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2015 Tomas Tauber++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Travis.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE OverloadedStrings #-}+{-|+Module : Travis+Description : A simple client implementation using Travis CI API.+Copyright : (c) Tomas Tauber, 2015+License : MIT+Maintainer : Tomas Tauber <tomtau@hku.hk>+Stability : experimental++A simple client implementation using Travis CI API: <http://docs.travis-ci.com/api/>.+-}+module Travis where++import Data.Aeson (decode)+import Network.HTTP.Conduit+import Travis.Types (BuildRaw (..), BuildsRaw (..),+ RepoRaw (..), RepositoryRaw (..))++type AccountName = String++type RepositoryName = String++-- |Travis CI base API URL+travisAPIBaseURL = "https://api.travis-ci.org/repos/" :: String+-- |Travis CI API v2 headers+requestH = [("Accept", "application/vnd.travis-ci.2+json"),+ ("User-Agent", "HaskellHTTPConduit/2.1.8")]++-- |fetches information about public repository on Travis CI+-- may return a tuple of repository and its builds information+fetchRepository :: AccountName -> RepositoryName -> IO (Maybe RepositoryRaw, Maybe [BuildRaw])+fetchRepository acname reponame = do+ -- repository info+ let coreUrl = travisAPIBaseURL ++ acname ++ "/" ++ reponame+ req1 <- parseUrl coreUrl+ let request1 = req1 { requestHeaders = requestH}+ manager <- newManager conduitManagerSettings+ _response1 <- httpLbs request1 manager+ let repository = decode (responseBody _response1) :: Maybe RepoRaw+ -- build info+ let buildsUrl = coreUrl ++ "/builds"+ req2 <- parseUrl buildsUrl+ let request2 = req2 { requestHeaders = requestH}+ _response2 <- httpLbs request2 manager+ let repobuilds = decode (responseBody _response2) :: Maybe BuildsRaw+ return (fmap repo repository, fmap builds repobuilds)
+ src/Travis/Types.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE OverloadedStrings #-}+module Travis.Types where++import Data.Aeson (FromJSON (..), ToJSON (..), Value (..),+ withObject, (.:))+import Data.Aeson.Types (Object (..), Parser (..), defaultOptions,+ fieldLabelModifier, genericParseJSON,+ genericToJSON)+import GHC.Generics (Generic)++-- |Data types representing: <http://docs.travis-ci.com/api/?http#repositories>+-- TODO: more precise parsing / types+data RepoRaw =+ RepoRaw { repo :: RepositoryRaw+ } deriving (Show, Generic)++data RepositoryRaw =+ RepositoryRaw { id :: Int+ , slug :: String+ , active :: Bool+ , description :: String+ , last_build_id :: Int+ , last_build_number :: String+ , last_build_state :: String+ , last_build_duration :: Int+ , last_build_started_at :: String+ , last_build_finished_at :: String+ , github_language :: String+ } deriving (Show, Generic)++instance FromJSON RepositoryRaw+instance ToJSON RepositoryRaw++instance FromJSON RepoRaw+instance ToJSON RepoRaw++-- |Data types representing: <http://docs.travis-ci.com/api/?http#builds>+-- TODO: more precise parsing / types+data BuildsRaw =+ BuildsRaw { builds :: [BuildRaw]+ , jobs :: Maybe [Object]+ , commits :: [Object]+ } deriving (Show, Generic)++data BuildRaw =+ BuildRaw { _commit_id :: Int+ , _config :: Object+ , _duration :: Int+ , _finished_at :: String+ , _id :: Int+ , _job_ids :: [Int]+ , _number :: String+ , _pull_request :: Bool+ , _pull_request_number :: Maybe Int+ , _pull_request_title :: Maybe String+ , _repository_id :: Int+ , _started_at :: String+ , _state :: String+ } deriving (Show, Generic)++instance FromJSON BuildsRaw+instance ToJSON BuildsRaw++instance FromJSON BuildRaw where+ parseJSON = genericParseJSON defaultOptions {+ fieldLabelModifier = drop 1 }++instance ToJSON BuildRaw where+ toJSON = genericToJSON defaultOptions {+ fieldLabelModifier = drop 1 }
+ travis.cabal view
@@ -0,0 +1,22 @@+name: travis+version: 0.1.0.0+synopsis: A simple client implementation using Travis CI API.+description: A simple client implementation using Travis CI API.+homepage: http://github.com/tomtau/travis#readme+license: MIT+license-file: LICENSE+author: Tomas Tauber+maintainer: tomtau@hku.hk+category: Web+build-type: Simple+cabal-version: >=1.10++Library+ hs-source-dirs: src+ exposed-modules: Travis, Travis.Types+ default-language: Haskell2010+ build-depends: aeson,+ base >= 4.7 && < 5,+ bytestring,+ http-conduit,+ transformers