@@ -7,6 +7,8 @@ module Sauron.UI.Issue.Events (
77
88 -- * Rendering
99 , renderEvent
10+ , renderCommitEvent
11+ , renderReviewEvent
1012 , renderLabelGroup
1113 , labelPill
1214
@@ -65,12 +67,14 @@ adaptiveWidth f = Widget Greedy Fixed $ do
6567consolidateEvents :: [TimelineEvent ] -> [TimelineItem ]
6668consolidateEvents [] = []
6769consolidateEvents (TimelineComment c : rest) = SingleItem (TimelineComment c) : consolidateEvents rest
70+ consolidateEvents (TimelineCommit c : rest) = SingleItem (TimelineCommit c) : consolidateEvents rest
71+ consolidateEvents (TimelineReview r : rest) = SingleItem (TimelineReview r) : consolidateEvents rest
6872consolidateEvents (TimelineIssueEvent e : rest)
6973 | isLabelEvent e =
7074 let (run, remaining) = span (isMatchingEvent isLabelEvent e) rest
7175 events = e : [ev | TimelineIssueEvent ev <- run]
72- added = filter (\ ev -> issueEventType ev == Labeled ) events
73- removed = filter (\ ev -> issueEventType ev == Unlabeled ) events
76+ added = filter (\ ev -> issueEventEvent ev == Labeled ) events
77+ removed = filter (\ ev -> issueEventEvent ev == Unlabeled ) events
7478 in if length events > 1
7579 then LabelGroup e added removed : consolidateEvents remaining
7680 else SingleItem (TimelineIssueEvent e) : consolidateEvents rest
@@ -90,10 +94,10 @@ isMatchingEvent predicate ref (TimelineIssueEvent ev) =
9094isMatchingEvent _ _ _ = False
9195
9296isLabelEvent :: IssueEvent -> Bool
93- isLabelEvent e = issueEventType e `elem` [Labeled , Unlabeled ]
97+ isLabelEvent e = issueEventEvent e `elem` [Labeled , Unlabeled ]
9498
9599isReviewRequestEvent :: IssueEvent -> Bool
96- isReviewRequestEvent e = issueEventType e == ReviewRequested
100+ isReviewRequestEvent e = issueEventEvent e == ReviewRequested
97101
98102
99103-- * Rendering
@@ -102,10 +106,10 @@ renderEvent :: UTCTime -> Bool -> IssueEvent -> Widget n
102106renderEvent now isLast issueEvent =
103107 let actorName :: Text = case issueEventActor issueEvent of
104108 Just (SimpleUser {simpleUserLogin= (N username)}) -> username
105- Nothing -> fromMaybe " ghost" (issueEventAuthorName issueEvent)
109+ Nothing -> " ghost"
106110 -- Each sized item is (width, widget)
107111 eventSuffixItems :: [(Int , Widget n )]
108- eventSuffixItems = case issueEventType issueEvent of
112+ eventSuffixItems = case issueEventEvent issueEvent of
109113 Labeled -> case issueEventLabel issueEvent of
110114 Just (IssueLabel {labelName= (N name), labelColor= hexColor}) -> [(5 , str " the " ), (safeWctwidth name + 2 , labelPill hexColor name), (7 , str " label" )]
111115 Nothing -> [(8 , str " a label" )]
@@ -115,23 +119,20 @@ renderEvent now isLast issueEvent =
115119 Referenced -> case issueEventCommitId issueEvent of
116120 Just sha -> let short = T. take 7 sha in [(11 , str " in commit " ), (safeWctwidth short, withAttr hashAttr (str (toString short)))]
117121 Nothing -> []
118- CrossReferenced -> case issueEventSourceIssue issueEvent of
122+ CrossReferenced -> case issueEventSource issueEvent >>= crossReferenceSourceIssue of
119123 Just sourceIssue ->
120124 let num = show (unIssueNumber (issueNumber sourceIssue))
121125 ref = " #" <> num
122126 title = toString (issueTitle sourceIssue)
123127 quoted = " \" " <> title <> " \" "
124128 in [(5 , str " from " ), (safeWcswidth ref, withAttr hashNumberAttr (str ref)), (1 + safeWcswidth quoted, str " " <+> withAttr normalAttr (str quoted))]
125129 Nothing -> []
126- Committed -> case issueEventCommitId issueEvent of
127- Just sha -> let short = T. take 7 sha in [(1 + safeWctwidth short, str " " <+> withAttr hashAttr (str (toString short)))]
128- Nothing -> []
129130 ReviewRequested -> case issueEventRequestedReviewer issueEvent of
130131 Just (SimpleUser {simpleUserLogin= (N reviewer)}) -> [(1 + safeWctwidth reviewer, str " " <+> withAttr usernameAttr (str (toString reviewer)))]
131132 Nothing -> []
132133 _ -> []
133- eventText = getEventDescription (issueEventType issueEvent)
134- iconWidget = getEventIconWithColor (issueEventType issueEvent)
134+ eventText = getEventDescription (issueEventEvent issueEvent)
135+ iconWidget = getEventIconWithColor (issueEventEvent issueEvent)
135136 timeAgo = timeFromNow (diffUTCTime now (issueEventCreatedAt issueEvent))
136137 timeAgoWidget = (safeWcswidth timeAgo, withAttr italicText $ str timeAgo)
137138 descriptionItems = [(safeWcswidth eventText, str eventText)] ++ eventSuffixItems ++ [(1 , str " " ), timeAgoWidget]
@@ -152,13 +153,64 @@ renderEvent now isLast issueEvent =
152153 else adaptiveWidth $ \ _ -> padLeft (Pad 4 ) $ withAttr timelineBorderAttr $ str " │"
153154 in vBox [eventLine, continuationLine]
154155
156+ renderCommitEvent :: UTCTime -> Bool -> TimelineCommitEvent -> Widget n
157+ renderCommitEvent now isLast commit =
158+ let actorName = gitAuthorName (timelineCommitEventAuthor commit)
159+ short = T. take 7 (timelineCommitEventSha commit)
160+ timeAgo = timeFromNow (diffUTCTime now (gitAuthorDate (timelineCommitEventAuthor commit)))
161+ firstMsgLine = T. takeWhile (/= ' \n ' ) (timelineCommitEventMessage commit)
162+ iconWidget = withAttr eventReferencedColor (str " ●" )
163+ descriptionItems =
164+ [(16 , str " added a commit " ), (safeWctwidth short, withAttr hashAttr (str (toString short))), (1 , str " " ), (safeWcswidth timeAgo, withAttr italicText $ str timeAgo)]
165+ prefixWidth = 1 + 2 + safeWctwidth actorName + 1
166+ eventLine = adaptiveWidth $ \ w ->
167+ let availableWidth = w - 4
168+ wrappedLines = wrapWidgets (availableWidth - prefixWidth) descriptionItems
169+ prefix = hBox [iconWidget, str " " , withAttr usernameAttr $ str (toString actorName), str " " ]
170+ firstLine = case wrappedLines of
171+ [] -> prefix
172+ (l: _) -> hBox [prefix, hBox (map snd l)]
173+ restLines = case wrappedLines of
174+ [] -> []
175+ (_: ls) -> [padLeft (Pad 3 ) $ hBox (map snd l) | l <- ls]
176+ msgLine = padLeft (Pad 3 ) $ hLimit (w - 4 - 3 ) $ withAttr normalAttr $ str (toString firstMsgLine)
177+ in padLeft (Pad 4 ) $ vBox (firstLine : restLines ++ [msgLine])
178+ continuationLine = if isLast
179+ then emptyWidget
180+ else adaptiveWidth $ \ _ -> padLeft (Pad 4 ) $ withAttr timelineBorderAttr $ str " │"
181+ in vBox [eventLine, continuationLine]
182+
183+ renderReviewEvent :: UTCTime -> Bool -> TimelineReviewEvent -> Widget n
184+ renderReviewEvent now isLast review =
185+ let actorName = case timelineReviewEventUser review of
186+ SimpleUser {simpleUserLogin= (N username)} -> username
187+ timeAgo = timeFromNow (diffUTCTime now (timelineReviewEventSubmittedAt review))
188+ iconWidget = withAttr eventReviewColor (str " ✓" )
189+ descriptionItems = [(13 , str " reviewed this " ), (safeWcswidth timeAgo, withAttr italicText $ str timeAgo)]
190+ prefixWidth = 1 + 2 + safeWctwidth actorName + 1
191+ eventLine = adaptiveWidth $ \ w ->
192+ let availableWidth = w - 4
193+ wrappedLines = wrapWidgets (availableWidth - prefixWidth) descriptionItems
194+ prefix = hBox [iconWidget, str " " , withAttr usernameAttr $ str (toString actorName), str " " ]
195+ firstLine = case wrappedLines of
196+ [] -> prefix
197+ (l: _) -> hBox [prefix, hBox (map snd l)]
198+ restLines = case wrappedLines of
199+ [] -> []
200+ (_: ls) -> [padLeft (Pad 3 ) $ hBox (map snd l) | l <- ls]
201+ in padLeft (Pad 4 ) $ vBox (firstLine : restLines)
202+ continuationLine = if isLast
203+ then emptyWidget
204+ else adaptiveWidth $ \ _ -> padLeft (Pad 4 ) $ withAttr timelineBorderAttr $ str " │"
205+ in vBox [eventLine, continuationLine]
206+
155207renderLabelGroup :: UTCTime -> Bool -> IssueEvent -> [IssueEvent ] -> [IssueEvent ] -> Widget n
156208renderLabelGroup now isLast rep added removed =
157209 let actorName :: Text = case issueEventActor rep of
158210 Just (SimpleUser {simpleUserLogin= (N username)}) -> username
159211 Nothing -> " ghost"
160212 timeAgo = timeFromNow (diffUTCTime now (issueEventCreatedAt rep))
161- iconWidget = getEventIconWithColor (issueEventType rep)
213+ iconWidget = getEventIconWithColor (issueEventEvent rep)
162214 addedItems = mapMaybe eventLabelPillWithWidth added
163215 removedItems = mapMaybe eventLabelPillWithWidth removed
164216 totalLabels = length added + length removed
0 commit comments