Browse Source

Refactor types into Types module

master
Wesley Kerfoot 6 years ago
parent
commit
2c120b1592
  1. 8
      pullwatch.cabal
  2. 9
      src/PullWatch/Environment.hs
  3. 38
      src/PullWatch/PullWatch.hs
  4. 42
      src/PullWatch/Types.hs

8
pullwatch.cabal

@ -27,6 +27,7 @@ library
exposed-modules: exposed-modules:
PullWatch.PullWatch PullWatch.PullWatch
, PullWatch.Environment , PullWatch.Environment
, PullWatch.Types
other-modules: other-modules:
Paths_pullwatch Paths_pullwatch
hs-source-dirs: hs-source-dirs:
@ -41,6 +42,9 @@ library
, vector , vector
, async , async
, containers , containers
, yaml
, system-filepath
, system-fileio
, data-default , data-default
, fdo-notify , fdo-notify
default-language: Haskell2010 default-language: Haskell2010
@ -63,6 +67,9 @@ executable pullwatch-exe
, vector , vector
, async , async
, containers , containers
, yaml
, system-filepath
, system-fileio
, data-default , data-default
, fdo-notify , fdo-notify
default-language: Haskell2010 default-language: Haskell2010
@ -86,6 +93,7 @@ test-suite pullwatch-test
, vector , vector
, async , async
, containers , containers
, yaml
, data-default , data-default
, fdo-notify , fdo-notify
default-language: Haskell2010 default-language: Haskell2010

9
src/PullWatch/Environment.hs

@ -3,13 +3,22 @@
module PullWatch.Environment module PullWatch.Environment
( getPAT ( getPAT
, getRepoConfig
) where ) where
import System.Environment import System.Environment
import Filesystem.Path
import qualified Data.Yaml as Y
import qualified GitHub.Auth as Auth import qualified GitHub.Auth as Auth
import qualified Data.ByteString.Char8 as C import qualified Data.ByteString.Char8 as C
getPAT = do getPAT = do
(Just pat) <- lookupEnv "PERSONAL_ACCESS_TOKEN" (Just pat) <- lookupEnv "PERSONAL_ACCESS_TOKEN"
return $ Just $ Auth.OAuth $ C.pack pat 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

38
src/PullWatch/PullWatch.hs

@ -1,7 +1,6 @@
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ImplicitParams #-} {-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE FlexibleInstances #-}
module PullWatch.PullWatch module PullWatch.PullWatch
( getLatest ( getLatest
@ -24,53 +23,20 @@ import Control.Applicative
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import Control.Concurrent.Async import Control.Concurrent.Async
import DBus.Notify import DBus.Notify
import Data.Default
import Data.IntMap (IntMap, (\\))
import Data.Maybe import Data.Maybe
import Data.Vector ((!?)) import Data.Vector ((!?))
import GitHub.Data.Id (untagId) import GitHub.Data.Id (untagId)
import GitHub.Data.Name (untagName) import GitHub.Data.Name (untagName)
import Prelude.Compat import Prelude.Compat
import System.Console.ArgParser import System.Console.ArgParser
import System.Console.ArgParser.QuickParams (RawRead, rawParse) import PullWatch.Types
import GitHub.Data.Name import Data.IntMap ((\\))
import qualified Data.IntMap as IntMap import qualified Data.IntMap as IntMap
import qualified Data.Text as T import qualified Data.Text as T
import qualified GitHub.Auth as Auth import qualified GitHub.Auth as Auth
import qualified GitHub.Endpoints.PullRequests as PR 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 -- Argument parser
parseRepos :: ParserSpec RepoArgs parseRepos :: ParserSpec RepoArgs

42
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)
Loading…
Cancel
Save