Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

lentille-github: Fix decoding issue for URI type #15

Merged
merged 1 commit into from
May 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The show implementation for Text does adds quotes. I don't think we need to further decode the value and unwrapping the URI type may be enough:

(SearchNodesTimelineItemsNodesSubjectPullRequest (URI url))) -> 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