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