From 0821486b5c570d8258a8d98d87ff1b5e58062fe2 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Tue, 26 Mar 2019 20:23:28 -0400 Subject: [PATCH] Fix unsafe function --- src/PullWatch/PullWatch.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/PullWatch/PullWatch.hs b/src/PullWatch/PullWatch.hs index 441a715..a855571 100644 --- a/src/PullWatch/PullWatch.hs +++ b/src/PullWatch/PullWatch.hs @@ -25,7 +25,7 @@ import Data.Default import Data.IntMap (IntMap, (\\)) import Data.Maybe import Data.Monoid -import Data.Vector ((!)) +import Data.Vector ((!?)) import GitHub.Data.Id (untagId) import GitHub.Data.Name (untagName) import Prelude.Compat @@ -58,11 +58,11 @@ instance Default PullRequest where tenMinutes = 300000000*2 -getPRId = Just . fromIntegral . untagId . simplePullRequestId . (! 0) +getPRId = Just . fromIntegral . untagId . simplePullRequestId -getPRTitle = Just . simplePullRequestTitle . (! 0) +getPRTitle = Just . simplePullRequestTitle -getPRBody = simplePullRequestBody . (! 0) +getPRBody = simplePullRequestBody -- Converts a pull request into a dbus notification toNote :: PullRequest -> Note @@ -83,17 +83,20 @@ getLatest :: (?pat :: (Maybe Auth.Auth)) => (PR.Name PR.Repo) -> IO (Maybe PullRequest) --- TODO fix this crap getLatest owner repo = do prs <- PR.pullRequestsFor' ?pat owner repo let pr = case prs of (Left _) -> Nothing (Right pullreqs) -> do - id <- getPRId pullreqs - title <- getPRTitle pullreqs - body <- getPRBody pullreqs + firstPR <- pullreqs !? 0 + + id <- getPRId firstPR + title <- getPRTitle firstPR + body <- getPRBody firstPR + let repoName = untagName repo let repoOwner = untagName owner + return $ PR body title repoName repoOwner id return pr