github-post-receive 1.1.0.0 → 1.2.0.0
raw patch · 2 files changed
+42/−29 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Github.PostReceive.Types: L :: a -> Or a b
- Github.PostReceive.Types: R :: b -> Or a b
- Github.PostReceive.Types: data Or a b
- Github.PostReceive.Types: statusCommitSHA :: StatusCommit -> Text
- Github.PostReceive.Types: statusEventSHA :: StatusEvent -> Text
- Github.PostReceive.Types: toEither :: Or a b -> Either a b
- Github.PostReceive.Types: treeSHA :: Tree -> Text
+ Github.PostReceive.Types: instance FromJSON ByteString
+ Github.PostReceive.Types: statusCommitSha :: StatusCommit -> HashValue
+ Github.PostReceive.Types: statusEventSha :: StatusEvent -> HashValue
+ Github.PostReceive.Types: treeSha :: Tree -> HashValue
+ Github.PostReceive.Types: type DateString = ByteString
+ Github.PostReceive.Types: type HashValue = ByteString
+ Github.PostReceive.Types: type Url = ByteString
- Github.PostReceive.Types: Commit :: Text -> Bool -> Text -> Text -> Url -> SimpleUser -> SimpleUser -> [FilePath] -> [FilePath] -> [FilePath] -> Commit
+ Github.PostReceive.Types: Commit :: HashValue -> Bool -> Text -> DateString -> Url -> SimpleUser -> SimpleUser -> [FilePath] -> [FilePath] -> [FilePath] -> Commit
- Github.PostReceive.Types: PushEvent :: Text -> Text -> Text -> Bool -> Bool -> Bool -> Maybe Text -> Url -> [Commit] -> Commit -> Repository -> SimpleUser -> User -> PushEvent
+ Github.PostReceive.Types: PushEvent :: Text -> HashValue -> HashValue -> Bool -> Bool -> Bool -> Maybe HashValue -> Url -> [Commit] -> Commit -> Repository -> SimpleUser -> User -> PushEvent
- Github.PostReceive.Types: Repository :: Int -> Text -> Text -> Or SimpleUser User -> Bool -> Url -> Text -> Bool -> Text -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Or Int Text -> Text -> Or Int Text -> Url -> Url -> Url -> Url -> Maybe Url -> Int -> Int -> Int -> Text -> Bool -> Bool -> Bool -> Bool -> Int -> Maybe Url -> Int -> Int -> Int -> Int -> Maybe Int -> Maybe Text -> Repository
+ Github.PostReceive.Types: Repository :: Int -> Text -> Text -> Either SimpleUser User -> Bool -> Url -> Text -> Bool -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Url -> Either Int DateString -> DateString -> Either Int DateString -> Url -> Url -> Url -> Url -> Maybe Url -> Int -> Int -> Int -> Text -> Bool -> Bool -> Bool -> Bool -> Int -> Maybe Url -> Int -> Int -> Int -> Int -> Maybe Int -> Maybe Text -> Repository
- Github.PostReceive.Types: SimpleCommit :: Text -> Url -> Maybe Url -> SimpleCommit
+ Github.PostReceive.Types: SimpleCommit :: HashValue -> Url -> Maybe Url -> SimpleCommit
- Github.PostReceive.Types: SimpleUser :: Text -> Maybe EmailAddress -> Maybe Text -> Maybe Text -> SimpleUser
+ Github.PostReceive.Types: SimpleUser :: Text -> Maybe EmailAddress -> Maybe Text -> Maybe DateString -> SimpleUser
- Github.PostReceive.Types: StatusCommit :: Text -> SimpleStatusCommit -> Url -> Url -> Url -> User -> User -> [SimpleCommit] -> StatusCommit
+ Github.PostReceive.Types: StatusCommit :: HashValue -> SimpleStatusCommit -> Url -> Url -> Url -> User -> User -> [SimpleCommit] -> StatusCommit
- Github.PostReceive.Types: StatusEvent :: Int -> Text -> Text -> Url -> Text -> Text -> Text -> StatusCommit -> [Branch] -> Text -> Text -> Repository -> User -> StatusEvent
+ Github.PostReceive.Types: StatusEvent :: Int -> HashValue -> Text -> Url -> Text -> Text -> Text -> StatusCommit -> [Branch] -> DateString -> DateString -> Repository -> User -> StatusEvent
- Github.PostReceive.Types: Tree :: Text -> Url -> Tree
+ Github.PostReceive.Types: Tree :: HashValue -> Url -> Tree
- Github.PostReceive.Types: commitId :: Commit -> Text
+ Github.PostReceive.Types: commitId :: Commit -> HashValue
- Github.PostReceive.Types: commitTimestamp :: Commit -> Text
+ Github.PostReceive.Types: commitTimestamp :: Commit -> DateString
- Github.PostReceive.Types: pushEventAfter :: PushEvent -> Text
+ Github.PostReceive.Types: pushEventAfter :: PushEvent -> HashValue
- Github.PostReceive.Types: pushEventBaseRef :: PushEvent -> Maybe Text
+ Github.PostReceive.Types: pushEventBaseRef :: PushEvent -> Maybe HashValue
- Github.PostReceive.Types: pushEventBefore :: PushEvent -> Text
+ Github.PostReceive.Types: pushEventBefore :: PushEvent -> HashValue
- Github.PostReceive.Types: repoCreatedAt :: Repository -> Or Int Text
+ Github.PostReceive.Types: repoCreatedAt :: Repository -> Either Int DateString
- Github.PostReceive.Types: repoOwner :: Repository -> Or SimpleUser User
+ Github.PostReceive.Types: repoOwner :: Repository -> Either SimpleUser User
- Github.PostReceive.Types: repoPushedAt :: Repository -> Or Int Text
+ Github.PostReceive.Types: repoPushedAt :: Repository -> Either Int DateString
- Github.PostReceive.Types: repoUpdatedAt :: Repository -> Text
+ Github.PostReceive.Types: repoUpdatedAt :: Repository -> DateString
- Github.PostReceive.Types: repoUrl :: Repository -> Text
+ Github.PostReceive.Types: repoUrl :: Repository -> Url
- Github.PostReceive.Types: simpleCommitSha :: SimpleCommit -> Text
+ Github.PostReceive.Types: simpleCommitSha :: SimpleCommit -> HashValue
- Github.PostReceive.Types: simpleUserDate :: SimpleUser -> Maybe Text
+ Github.PostReceive.Types: simpleUserDate :: SimpleUser -> Maybe DateString
- Github.PostReceive.Types: statusEventCreatedAt :: StatusEvent -> Text
+ Github.PostReceive.Types: statusEventCreatedAt :: StatusEvent -> DateString
- Github.PostReceive.Types: statusEventUpdatedAt :: StatusEvent -> Text
+ Github.PostReceive.Types: statusEventUpdatedAt :: StatusEvent -> DateString
Files
- github-post-receive.cabal +1/−2
- src/Github/PostReceive/Types.hs +41/−27
github-post-receive.cabal view
@@ -1,12 +1,11 @@ name: github-post-receive-version: 1.1.0.0+version: 1.2.0.0 synopsis: GitHub webhooks library description: This is a library to construct github webhooks servers. . Currently, this library supports following events: . * push- . * status homepage: https://github.com/amutake/github-post-receive license: BSD3
src/Github/PostReceive/Types.hs view
@@ -14,17 +14,21 @@ , StatusCommit (..) , SimpleStatusCommit (..) , Tree (..)- , Or (..)- , toEither+ , Url+ , HashValue+ , DateString -- Re-exports , EmailAddress ) where import Control.Applicative ((<$>), (<*>), pure, (<|>))-import Data.Aeson (Value (..), FromJSON (..), (.:), (.:?))+import Data.Aeson (Value (..), FromJSON (..), (.:), (.:?), Object)+import Data.Aeson.Types (Parser)+import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B import Data.Text (Text) import qualified Data.Text as T+import qualified Data.Text.Encoding as T import Data.Typeable (Typeable) import Text.Email.Validate (EmailAddress, emailAddress) @@ -38,12 +42,12 @@ data PushEvent = PushEvent { pushEventRef :: Text- , pushEventBefore :: Text- , pushEventAfter :: Text+ , pushEventBefore :: HashValue+ , pushEventAfter :: HashValue , pushEventCreated :: Bool , pushEventDeleted :: Bool , pushEventForced :: Bool- , pushEventBaseRef :: Maybe Text+ , pushEventBaseRef :: Maybe HashValue , pushEventCompare :: Url , pushEventCommits :: [Commit] , pushEventHeadCommit :: Commit@@ -71,7 +75,7 @@ data StatusEvent = StatusEvent { statusEventId :: Int- , statusEventSHA :: Text+ , statusEventSha :: HashValue , statusEventName :: Text , statusEventTargetUrl :: Url , statusEventContext :: Text@@ -79,8 +83,8 @@ , statusEventState :: Text , statusEventCommit :: StatusCommit , statusEventBranches :: [Branch]- , statusEventCreatedAt :: Text -- TODO: Change to date type- , statusEventUpdatedAt :: Text -- TODO: Change to date type+ , statusEventCreatedAt :: DateString -- TODO: Change to date type+ , statusEventUpdatedAt :: DateString -- TODO: Change to date type , statusEventRepository :: Repository , statusEventSender :: User } deriving (Show, Eq, Typeable)@@ -103,10 +107,10 @@ parseJSON _ = fail "StatusEvent must be an object" data Commit = Commit- { commitId :: Text+ { commitId :: HashValue , commitDistinct :: Bool , commitMessage :: Text- , commitTimestamp :: Text+ , commitTimestamp :: DateString , commitUrl :: Url , commitAuthor :: SimpleUser , commitCommitter :: SimpleUser@@ -133,13 +137,13 @@ { repoId :: Int , repoName :: Text , repoFullName :: Text- , repoOwner :: Or SimpleUser User+ , repoOwner :: Either SimpleUser User , repoPrivate :: Bool , repoHtmlUrl :: Url , repoDescription :: Text , repoFork :: Bool -- urls- , repoUrl :: Text+ , repoUrl :: Url , repoForksUrl :: Url , repoKeysUrl :: Url , repoCollaboratorsUrl :: Url@@ -175,9 +179,9 @@ , repoLabelsUrl :: Url , repoReleasesUrl :: Url -- date- , repoCreatedAt :: Or Int Text -- Int or DateString- , repoUpdatedAt :: Text- , repoPushedAt :: Or Int Text -- Int or DateString+ , repoCreatedAt :: Either Int DateString -- Int or DateString+ , repoUpdatedAt :: DateString+ , repoPushedAt :: Either Int DateString -- Int or DateString , repoGitUrl :: Url , repoSshUrl :: Url , repoCloneUrl :: Url@@ -207,7 +211,7 @@ <$> o .: "id" <*> o .: "name" <*> o .: "full_name"- <*> o .: "owner"+ <*> o .:| "owner" <*> o .: "private" <*> o .: "html_url" <*> o .: "description"@@ -247,9 +251,9 @@ <*> o .: "notifications_url" <*> o .: "labels_url" <*> o .: "releases_url"- <*> o .: "created_at"+ <*> o .:| "created_at" <*> o .: "updated_at"- <*> o .: "pushed_at"+ <*> o .:| "pushed_at" <*> o .: "git_url" <*> o .: "ssh_url" <*> o .: "clone_url"@@ -318,7 +322,7 @@ { simpleUserName :: Text , simpleUserEmail :: Maybe EmailAddress , simpleUserUsername :: Maybe Text- , simpleUserDate :: Maybe Text+ , simpleUserDate :: Maybe DateString } deriving (Show, Eq, Typeable) instance FromJSON SimpleUser where@@ -335,6 +339,10 @@ Nothing -> fail "failed to parse EmailAddress" parseJSON _ = fail "EmailAddress must be a text" +instance FromJSON B.ByteString where+ parseJSON (String t) = pure (T.encodeUtf8 t)+ parseJSON _ = fail "ByteString must be a text"+ data Branch = Branch { branchName :: Text , branchCommit :: SimpleCommit@@ -347,7 +355,7 @@ parseJSON _ = fail "Branch must be an object" data SimpleCommit = SimpleCommit- { simpleCommitSha :: Text+ { simpleCommitSha :: HashValue , simpleCommitUrl :: Url , simpleCommitHtmlUrl :: Maybe Url } deriving (Show, Eq, Typeable)@@ -361,7 +369,7 @@ -- | used in StatusEvent data StatusCommit = StatusCommit- { statusCommitSHA :: Text+ { statusCommitSha :: HashValue , statusCommitCommit :: SimpleStatusCommit , statusCommitUrl :: Url , statusCommitHtmlUrl :: Url@@ -403,7 +411,7 @@ parseJSON _ = fail "SimpleStatusCommit must be an object" data Tree = Tree- { treeSHA :: Text+ { treeSha :: HashValue , treeUrl :: Url } deriving (Show, Eq, Typeable) @@ -413,8 +421,12 @@ <*> o .: "url" parseJSON _ = fail "Tree must be an object" -type Url = Text+type Url = ByteString +type HashValue = ByteString++type DateString = ByteString+ -- | Or a b represents a or b -- The reason why we don't use Either type is that Either Int String type parses { "left": 1 } or { "right": "foo" }, but we want to parse 1 or "foo". data Or a b = L a | R b deriving (Show, Eq, Typeable)@@ -422,6 +434,8 @@ instance (FromJSON a, FromJSON b) => FromJSON (Or a b) where parseJSON v = L <$> parseJSON v <|> R <$> parseJSON v -toEither :: Or a b -> Either a b-toEither (L a) = Left a-toEither (R b) = Right b+(.:|) :: (FromJSON a, FromJSON b) => Object -> Text -> Parser (Either a b)+obj .:| key = toEither <$> (obj .: key)+ where+ toEither (L a) = Left a+ toEither (R b) = Right b