From 2c120b1592db26a721bcf7d8bfa603c971682bdc Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 30 Mar 2019 21:58:53 -0400 Subject: [PATCH] Refactor types into Types module --- pullwatch.cabal | 8 +++++++ src/PullWatch/Environment.hs | 9 ++++++++ src/PullWatch/PullWatch.hs | 38 ++------------------------------ src/PullWatch/Types.hs | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 src/PullWatch/Types.hs diff --git a/pullwatch.cabal b/pullwatch.cabal index 98343a5..d837b4e 100644 --- a/pullwatch.cabal +++ b/pullwatch.cabal @@ -27,6 +27,7 @@ library exposed-modules: PullWatch.PullWatch , PullWatch.Environment + , PullWatch.Types other-modules: Paths_pullwatch hs-source-dirs: @@ -41,6 +42,9 @@ library , vector , async , containers + , yaml + , system-filepath + , system-fileio , data-default , fdo-notify default-language: Haskell2010 @@ -63,6 +67,9 @@ executable pullwatch-exe , vector , async , containers + , yaml + , system-filepath + , system-fileio , data-default , fdo-notify default-language: Haskell2010 @@ -86,6 +93,7 @@ test-suite pullwatch-test , vector , async , containers + , yaml , data-default , fdo-notify default-language: Haskell2010 diff --git a/src/PullWatch/Environment.hs b/src/PullWatch/Environment.hs index ee8aabd..629369d 100644 --- a/src/PullWatch/Environment.hs +++ b/src/PullWatch/Environment.hs @@ -3,13 +3,22 @@ module PullWatch.Environment ( getPAT + , getRepoConfig ) where import System.Environment +import Filesystem.Path +import qualified Data.Yaml as Y import qualified GitHub.Auth as Auth import qualified Data.ByteString.Char8 as C getPAT = do (Just pat) <- lookupEnv "PERSONAL_ACCESS_TOKEN" return $ Just $ Auth.OAuth $ C.pack pat + +getRepoConfig = do + config <- lookupEnv "PULLWATCH_CONFIG" + case config of + Nothing -> return "~/.config/pullwatch.yml" + Just configPath -> return configPath diff --git a/src/PullWatch/PullWatch.hs b/src/PullWatch/PullWatch.hs index a9e158e..66bd317 100644 --- a/src/PullWatch/PullWatch.hs +++ b/src/PullWatch/PullWatch.hs @@ -1,7 +1,6 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ImplicitParams #-} -{-# LANGUAGE FlexibleInstances #-} module PullWatch.PullWatch ( getLatest @@ -24,53 +23,20 @@ import Control.Applicative import Control.Concurrent (threadDelay) import Control.Concurrent.Async import DBus.Notify -import Data.Default -import Data.IntMap (IntMap, (\\)) import Data.Maybe import Data.Vector ((!?)) import GitHub.Data.Id (untagId) import GitHub.Data.Name (untagName) import Prelude.Compat import System.Console.ArgParser -import System.Console.ArgParser.QuickParams (RawRead, rawParse) -import GitHub.Data.Name +import PullWatch.Types +import Data.IntMap ((\\)) import qualified Data.IntMap as IntMap import qualified Data.Text as T import qualified GitHub.Auth as Auth import qualified GitHub.Endpoints.PullRequests as PR --- Type definitions - -type PullRequests = IntMap PullRequest - -data PullRequest = PR { - prText :: T.Text - , prTitle :: T.Text - , prRepo :: T.Text - , prOwner :: T.Text - , prID :: Integer - } - - deriving (Show) - -data RepoArgs = RepoArgs (PR.Name PR.Owner) - (PR.Name PR.Repo) - deriving (Show) - -instance Default PullRequest where - def = PR { - prText = "" - , prTitle = "" - , prRepo = "" - , prOwner = "" - , prID = 0 - } - -instance RawRead (PR.Name a) where - rawParse x = Just (N $ T.pack x, x) - - -- Argument parser parseRepos :: ParserSpec RepoArgs diff --git a/src/PullWatch/Types.hs b/src/PullWatch/Types.hs new file mode 100644 index 0000000..a0386bb --- /dev/null +++ b/src/PullWatch/Types.hs @@ -0,0 +1,42 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE FlexibleInstances #-} + +module PullWatch.Types where + +import Data.Default +import GitHub.Data.Name +import System.Console.ArgParser.QuickParams (RawRead, rawParse) + +import qualified GitHub.Endpoints.PullRequests as PR +import qualified Data.IntMap as IntMap +import qualified Data.Text as T + +-- Type definitions + +type PullRequests = IntMap.IntMap PullRequest + +data PullRequest = PR { + prText :: T.Text + , prTitle :: T.Text + , prRepo :: T.Text + , prOwner :: T.Text + , prID :: Integer + } + + deriving (Show) + +data RepoArgs = RepoArgs (PR.Name PR.Owner) + (PR.Name PR.Repo) + deriving (Show) + +instance Default PullRequest where + def = PR { + prText = "" + , prTitle = "" + , prRepo = "" + , prOwner = "" + , prID = 0 + } + +instance RawRead (PR.Name a) where + rawParse x = Just (N $ T.pack x, x)