module Github.Repos (
currentUserRepos,
currentUserReposR,
userRepos,
userRepos',
userReposR,
organizationRepos,
organizationRepos',
organizationReposR,
repository,
repository',
repositoryR,
contributors,
contributors',
contributorsR,
contributorsWithAnonymous,
contributorsWithAnonymous',
languagesFor,
languagesFor',
languagesForR,
tagsFor,
tagsFor',
tagsForR,
branchesFor,
branchesFor',
branchesForR,
contentsFor,
contentsFor',
readmeFor,
readmeFor',
createRepo',
createRepoR,
createOrganizationRepo',
createOrganizationRepoR,
editRepo,
editRepoR,
deleteRepo,
deleteRepoR,
module Github.Data,
) where
import Control.Applicative ((<|>))
import Data.Aeson.Compat (encode)
import Data.Vector (Vector)
import Github.Auth
import Github.Data
import Github.Request
import qualified Data.ByteString.Char8 as BS8
repoPublicityQueryString :: RepoPublicity -> QueryString
repoPublicityQueryString All = [("type", Just "all")]
repoPublicityQueryString Owner = [("type", Just "owner")]
repoPublicityQueryString Member = [("type", Just "member")]
repoPublicityQueryString Public = [("type", Just "public")]
repoPublicityQueryString Private = [("type", Just "private")]
currentUserRepos :: GithubAuth -> RepoPublicity -> IO (Either Error (Vector Repo))
currentUserRepos auth publicity =
executeRequest auth $ currentUserReposR publicity Nothing
currentUserReposR :: RepoPublicity -> Maybe Count -> GithubRequest k(Vector Repo)
currentUserReposR publicity =
GithubPagedGet ["user", "repos"] qs
where
qs = repoPublicityQueryString publicity
userRepos :: Name GithubOwner -> RepoPublicity -> IO (Either Error (Vector Repo))
userRepos = userRepos' Nothing
userRepos' :: Maybe GithubAuth -> Name GithubOwner -> RepoPublicity -> IO (Either Error (Vector Repo))
userRepos' auth user publicity =
executeRequestMaybe auth $ userReposR user publicity Nothing
userReposR :: Name GithubOwner -> RepoPublicity -> Maybe Count -> GithubRequest k(Vector Repo)
userReposR user publicity =
GithubPagedGet ["users", toPathPart user, "repos"] qs
where
qs = repoPublicityQueryString publicity
organizationRepos :: Name Organization -> IO (Either Error (Vector Repo))
organizationRepos org = organizationRepos' Nothing org All
organizationRepos' :: Maybe GithubAuth -> Name Organization -> RepoPublicity -> IO (Either Error (Vector Repo))
organizationRepos' auth org publicity =
executeRequestMaybe auth $ organizationReposR org publicity Nothing
organizationReposR :: Name Organization -> RepoPublicity -> Maybe Count -> GithubRequest k (Vector Repo)
organizationReposR org publicity =
GithubPagedGet ["orgs", toPathPart org, "repos"] qs
where
qs = repoPublicityQueryString publicity
repository :: Name GithubOwner -> Name Repo -> IO (Either Error Repo)
repository = repository' Nothing
repository' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error Repo)
repository' auth user repo =
executeRequestMaybe auth $ repositoryR user repo
repositoryR :: Name GithubOwner -> Name Repo -> GithubRequest k Repo
repositoryR user repo =
GithubGet ["repos", toPathPart user, toPathPart repo] []
createRepo' :: GithubAuth -> NewRepo -> IO (Either Error Repo)
createRepo' auth nrepo =
executeRequest auth $ createRepoR nrepo
createRepoR :: NewRepo -> GithubRequest 'True Repo
createRepoR nrepo =
GithubPost Post ["user", "repos"] (encode nrepo)
createOrganizationRepo' :: GithubAuth -> Name Organization -> NewRepo -> IO (Either Error Repo)
createOrganizationRepo' auth org nrepo =
executeRequest auth $ createOrganizationRepoR org nrepo
createOrganizationRepoR :: Name Organization -> NewRepo -> GithubRequest 'True Repo
createOrganizationRepoR org nrepo =
GithubPost Post ["orgs", toPathPart org, "repos"] (encode nrepo)
editRepo :: GithubAuth
-> Name GithubOwner
-> Name Repo
-> EditRepo
-> IO (Either Error Repo)
editRepo auth user repo body =
executeRequest auth $ editRepoR user repo body
editRepoR :: Name GithubOwner -> Name Repo -> EditRepo -> GithubRequest 'True Repo
editRepoR user repo body =
GithubPost Patch ["repos", toPathPart user, toPathPart repo] (encode b)
where
b = body {editName = editName body <|> Just repo}
contributors :: Name GithubOwner -> Name Repo -> IO (Either Error (Vector Contributor))
contributors = contributors' Nothing
contributors' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error (Vector Contributor))
contributors' auth user repo =
executeRequestMaybe auth $ contributorsR user repo False Nothing
contributorsR :: Name GithubOwner
-> Name Repo
-> Bool
-> Maybe Count
-> GithubRequest k (Vector Contributor)
contributorsR user repo anon =
GithubPagedGet ["repos", toPathPart user, toPathPart repo, "contributors"] qs
where
qs | anon = [("anon", Just "true")]
| otherwise = []
contributorsWithAnonymous :: Name GithubOwner -> Name Repo -> IO (Either Error (Vector Contributor))
contributorsWithAnonymous = contributorsWithAnonymous' Nothing
contributorsWithAnonymous' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error (Vector Contributor))
contributorsWithAnonymous' auth user repo =
executeRequestMaybe auth $ contributorsR user repo True Nothing
languagesFor :: Name GithubOwner -> Name Repo -> IO (Either Error Languages)
languagesFor = languagesFor' Nothing
languagesFor' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error Languages)
languagesFor' auth user repo =
executeRequestMaybe auth $ languagesForR user repo
languagesForR :: Name GithubOwner -> Name Repo -> GithubRequest k Languages
languagesForR user repo =
GithubGet ["repos", toPathPart user, toPathPart repo, "languages"] []
tagsFor :: Name GithubOwner -> Name Repo -> IO (Either Error (Vector Tag))
tagsFor = tagsFor' Nothing
tagsFor' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error (Vector Tag))
tagsFor' auth user repo =
executeRequestMaybe auth $ tagsForR user repo Nothing
tagsForR :: Name GithubOwner -> Name Repo -> Maybe Count -> GithubRequest k (Vector Tag)
tagsForR user repo =
GithubPagedGet ["repos", toPathPart user, toPathPart repo, "tags"] []
branchesFor :: Name GithubOwner -> Name Repo -> IO (Either Error (Vector Branch))
branchesFor = branchesFor' Nothing
branchesFor' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error (Vector Branch))
branchesFor' auth user repo =
executeRequestMaybe auth $ branchesForR user repo Nothing
branchesForR :: Name GithubOwner -> Name Repo -> Maybe Count -> GithubRequest k (Vector Branch)
branchesForR user repo =
GithubPagedGet ["repos", toPathPart user, toPathPart repo, "branches"] []
contentsFor :: Name GithubOwner -> Name Repo -> String -> Maybe String -> IO (Either Error Content)
contentsFor = contentsFor' Nothing
contentsFor' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> String -> Maybe String -> IO (Either Error Content)
contentsFor' auth user repo path ref =
executeRequestMaybe auth $ contentsForR user repo path ref
contentsForR :: Name GithubOwner
-> Name Repo
-> String
-> Maybe String
-> GithubRequest k Content
contentsForR user repo path ref =
GithubGet ["repos", toPathPart user, toPathPart repo, "contents", path] qs
where
qs = maybe [] (\r -> [("ref", Just . BS8.pack $ r)]) ref
readmeFor :: Name GithubOwner -> Name Repo -> IO (Either Error Content)
readmeFor = readmeFor' Nothing
readmeFor' :: Maybe GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error Content)
readmeFor' auth user repo =
executeRequestMaybe auth $ readmeForR user repo
readmeForR :: Name GithubOwner -> Name Repo -> GithubRequest k Content
readmeForR user repo =
GithubGet ["repos", toPathPart user, toPathPart repo, "readme"] []
deleteRepo :: GithubAuth -> Name GithubOwner -> Name Repo -> IO (Either Error ())
deleteRepo auth user repo =
executeRequest auth $ deleteRepoR user repo
deleteRepoR :: Name GithubOwner -> Name Repo -> GithubRequest 'True ()
deleteRepoR user repo =
GithubDelete ["repos", toPathPart user, toPathPart repo]