module Github.Issues (
issue
,issue'
,issuesForRepo
,issuesForRepo'
,IssueLimitation(..)
,createIssue
,newIssue
,editIssue
,editOfIssue
,module Github.Data
) where
import Github.Data
import Github.Private
import Data.List (intercalate)
import Data.Time.Format (formatTime)
import System.Locale (defaultTimeLocale)
import Data.Time.Clock (UTCTime(..))
data IssueLimitation =
AnyMilestone
| NoMilestone
| MilestoneId Int
| Open
| OnlyClosed
| Unassigned
| AnyAssignment
| AssignedTo String
| Mentions String
| Labels [String]
| Ascending
| Descending
| Since UTCTime
| PerPage Int
issue' :: Maybe GithubAuth -> String -> String -> Int -> IO (Either Error Issue)
issue' auth user reqRepoName reqIssueNumber =
githubGet' auth ["repos", user, reqRepoName, "issues", show reqIssueNumber]
issue :: String -> String -> Int -> IO (Either Error Issue)
issue = issue' Nothing
issuesForRepo' :: Maybe GithubAuth -> String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
issuesForRepo' auth user reqRepoName issueLimitations =
githubGetWithQueryString'
auth
["repos", user, reqRepoName, "issues"]
(queryStringFromLimitations issueLimitations)
where
queryStringFromLimitations = intercalate "&" . map convert
convert AnyMilestone = "milestone=*"
convert NoMilestone = "milestone=none"
convert (MilestoneId n) = "milestone=" ++ show n
convert Open = "state=open"
convert OnlyClosed = "state=closed"
convert Unassigned = "assignee=none"
convert AnyAssignment = "assignee=*"
convert (AssignedTo u) = "assignee=" ++ u
convert (Mentions u) = "mentioned=" ++ u
convert (Labels l) = "labels=" ++ intercalate "," l
convert Ascending = "direction=asc"
convert Descending = "direction=desc"
convert (PerPage n) = "per_page=" ++ show n
convert (Since t) =
"since=" ++ formatTime defaultTimeLocale "%FT%TZ" t
issuesForRepo :: String -> String -> [IssueLimitation] -> IO (Either Error [Issue])
issuesForRepo = issuesForRepo' Nothing
newIssue :: String -> NewIssue
newIssue title = NewIssue title Nothing Nothing Nothing Nothing
createIssue :: GithubAuth -> String -> String -> NewIssue
-> IO (Either Error Issue)
createIssue auth user repo = githubPost auth ["repos", user, repo, "issues"]
editOfIssue :: EditIssue
editOfIssue = EditIssue Nothing Nothing Nothing Nothing Nothing Nothing
editIssue :: GithubAuth -> String -> String -> Int -> EditIssue
-> IO (Either Error Issue)
editIssue auth user repo iss =
githubPatch auth ["repos", user, repo, "issues", show iss]