From 3fdb6e3229d7034f7c13bbad1f2a2a7985523e20 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Mon, 10 May 2021 20:25:18 +0000 Subject: [PATCH] lentille-github: Fix decoding issue for URI type This patch ensures the URI Text where Text is JSON doc (eg. newTaskDataChangeUrl = "URI \"https://github.com/elastic/elasticsearch/pull/72808\"") is decoded. --- lentille-github/src/Lentille/GitHub/Issues.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lentille-github/src/Lentille/GitHub/Issues.hs b/lentille-github/src/Lentille/GitHub/Issues.hs index 09edfcd..78acee5 100644 --- a/lentille-github/src/Lentille/GitHub/Issues.hs +++ b/lentille-github/src/Lentille/GitHub/Issues.hs @@ -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 @@ -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 @@ -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