Skip to content

Commit

Permalink
lentille-github: Fix decoding issue for URI type
Browse files Browse the repository at this point in the history
This patch ensures the URI Text where Text is JSON doc (eg.
newTaskDataChangeUrl = "\"https://github.com/elastic/elasticsearch/pull/70392\"")
is decoded.
  • Loading branch information
morucci committed May 10, 2021
1 parent 9afca61 commit 9ce65af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lentille-github/src/Lentille/GitHub/Issues.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

module Lentille.GitHub.Issues where

import Data.Aeson (decode)
import qualified Data.ByteString.Lazy as LBS
import Data.Morpheus.Client
import Data.Time.Calendar
Expand Down Expand Up @@ -118,7 +119,7 @@ transformResponse searchResult =
0
where
getIssueURL :: SearchNodesSearchResultItem -> Text
getIssueURL (SearchNodesIssue _ _ _ changeURL _ _) = show changeURL
getIssueURL (SearchNodesIssue _ _ _ issueURI _ _) = decodeURI issueURI
getIssueID :: SearchNodesSearchResultItem -> Text
getIssueID (SearchNodesIssue issueID _ _ _ _ _) = unpackID issueID
getUpdatedAt :: SearchNodesSearchResultItem -> Timestamp
Expand Down Expand Up @@ -159,7 +160,11 @@ transformResponse searchResult =
extractUrl item = case item of
Just
( SearchNodesTimelineItemsNodesConnectedEvent
(SearchNodesTimelineItemsNodesSubjectPullRequest (url))
) -> show url
(SearchNodesTimelineItemsNodesSubjectPullRequest changeURI)
) -> decodeURI changeURI
-- We are requesting Issue with connected PR we cannot get Nothing
Nothing -> error ("Missing PR URI in SearchNodesTimelineItemsNodesSubjectPullRequest")
decodeURI :: URI -> Text
decodeURI (URI uri) = case (decode (show uri) :: Maybe Text) of
Just uri' -> uri'
Nothing -> error "Unable to decode URI: " <> show uri

0 comments on commit 9ce65af

Please sign in to comment.