bugzilla 0.1.0.1 → 0.2.0.0
raw patch · 5 files changed
+37/−14 lines, 5 files
Files
- bugzilla.cabal +3/−2
- changelog +7/−0
- demo/BugzillaDemo.hs +5/−4
- src/Web/Bugzilla.hs +1/−0
- src/Web/Bugzilla/Internal/Types.hs +21/−8
bugzilla.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: bugzilla-version: 0.1.0.1+version: 0.2.0.0 synopsis: A Haskell interface to the Bugzilla native REST API description: This package is designed to provide an easy-to-use, typesafe interface to querying Bugzilla from Haskell.@@ -15,12 +15,13 @@ category: Web build-type: Simple extra-source-files: README.md+ changelog cabal-version: >=1.10 source-repository head type: git location: https://github.com/sethfowler/hsbugzilla.git- tag: 0.1+ tag: 0.2 flag BuildDemo description: Build the 'bugzilla' demo program
+ changelog view
@@ -0,0 +1,7 @@+0.2.0.0++ * History events now have a sequential id, just like comments.++ * When using an anonymous session, Bugzilla does not return email addresses for users.+ To accomodate this, the User type now stores email addresses as type+ 'Maybe UserEmail'.
demo/BugzillaDemo.hs view
@@ -119,16 +119,17 @@ showComment (Comment {..}) = do user <- getUser session commentCreator let commentUserRealName = fromMaybe commentCreator $ userRealName <$> user- let commentUserEmail = fromMaybe commentCreator $ userEmail <$> user- return $ "(" ++ show commentId ++ ") " ++ T.unpack commentUserRealName+ let commentUserEmail = fromMaybe commentCreator $ userEmail =<< user+ return $ "(Comment " ++ show commentCount ++ ") " ++ T.unpack commentUserRealName ++ " <" ++ T.unpack commentUserEmail ++ "> " ++ show commentCreationTime ++ "\n" ++ (unlines . map (" " ++) . lines . T.unpack $ commentText) showEvent (HistoryEvent {..}) = do user <- getUser session historyEventUser let eventUserRealName = fromMaybe historyEventUser $ userRealName <$> user- let eventUserEmail = fromMaybe historyEventUser $ userEmail <$> user- return $ T.unpack eventUserRealName ++ " <" ++ T.unpack eventUserEmail ++ ">\n"+ let eventUserEmail = fromMaybe historyEventUser $ userEmail =<< user+ return $ "(Event " ++ show historyEventId ++ ") " ++ T.unpack eventUserRealName+ ++ " <" ++ T.unpack eventUserEmail ++ ">\n" ++ concatMap showChange historyEventChanges showChange (TextFieldChange f (Modification r a aid)) = showChange' f r a aid
src/Web/Bugzilla.hs view
@@ -50,6 +50,7 @@ , AttachmentId , CommentId , UserId+, EventId , FlagId , FlagType , UserEmail
src/Web/Bugzilla/Internal/Types.hs view
@@ -10,6 +10,7 @@ , AttachmentId , CommentId , UserId+, EventId , FlagId , FlagType , UserEmail@@ -48,6 +49,7 @@ type AttachmentId = Int type CommentId = Int type UserId = Int+type EventId = Int type FlagId = Int type FlagType = Int type UserEmail = T.Text@@ -285,7 +287,7 @@ -- | A Bugzilla user. data User = User { userId :: !UserId- , userEmail :: T.Text+ , userEmail :: Maybe UserEmail , userName :: T.Text , userRealName :: T.Text } deriving (Eq, Ord, Show)@@ -293,7 +295,7 @@ instance FromJSON User where parseJSON (Object v) = User <$> v .: "id"- <*> v .: "email"+ <*> v .:? "email" <*> v .: "name" <*> v .: "real_name" parseJSON _ = mzero@@ -500,7 +502,7 @@ } deriving (Eq, Show) instance FromJSON Comment where- parseJSON (Object v) = do+ parseJSON (Object v) = Comment <$> v .: "id" <*> v .: "bug_id" <*> v .: "attachment_id"@@ -545,22 +547,33 @@ bugsVal <- v .: "bugs" case bugsVal of Array (V.toList -> [history]) ->- withObject "history" (\h -> History <$> h .: "id" <*> h .: "history") history+ withObject "history"+ (\h -> History <$> h .: "id"+ <*> parseHistoryEvents h)+ history _ -> mzero parseJSON _ = mzero +parseHistoryEvents :: Object -> Parser [HistoryEvent]+parseHistoryEvents h = do+ events <- h .: "history"+ withArray "event list" (\a -> parseJSON (addCount a)) events+ -- | An event in a bug's history. data HistoryEvent = HistoryEvent- { historyEventTime :: UTCTime -- ^ When the event occurred.+ { historyEventId :: EventId -- ^ A sequential event id.+ , historyEventTime :: UTCTime -- ^ When the event occurred. , historyEventUser :: UserEmail -- ^ Which user was responsible. , historyEventChanges :: [Change] -- ^ All the changes which are -- part of this event. } deriving (Eq, Show) instance FromJSON HistoryEvent where- parseJSON (Object v) = HistoryEvent <$> v .: "when"- <*> v .: "who"- <*> v .: "changes"+ parseJSON (Object v) =+ HistoryEvent <$> v .: "count"+ <*> v .: "when"+ <*> v .: "who"+ <*> v .: "changes" parseJSON _ = mzero -- | A single change which is part of an event. Different constructors