generated from tpl/purs
feat: topics and list for org #1
@ -30,8 +30,8 @@ import Type.Row.Subset (class Subset)
|
||||
reposURL :: forall m. Monad m => Username -> RepoName -> GiteaT m URL
|
||||
reposURL (Username owner) (RepoName repo) = (\{ baseURI } -> baseURI / "repos" / owner / repo) <$> ask
|
||||
|
||||
orgReposURL :: forall m. Monad m => OrgName -> {page :: Int , limit :: Int} -> GiteaT m URL
|
||||
orgReposURL (OrgName org) {page,limit} = (\{ baseURI } -> baseURI / "orgs" / org / "repos" ? "limit" /\ show limit & "page" /\ show page) <$> ask
|
||||
orgReposURL :: forall m. Monad m => OrgName -> { page :: Int, limit :: Int } -> GiteaT m URL
|
||||
orgReposURL (OrgName org) { page, limit } = (\{ baseURI } -> baseURI / "orgs" / org / "repos" ? "limit" /\ show limit & "page" /\ show page) <$> ask
|
||||
|
||||
get :: forall m. MonadAff m => Username -> RepoName -> GiteaT m (Record Repo)
|
||||
get u r = do
|
||||
@ -41,22 +41,24 @@ get u r = do
|
||||
Error.tryGetRepJSON rep
|
||||
|
||||
listForOrg :: forall m. MonadAff m => MonadRec m => OrgName -> GiteaT m (Array (Record Repo))
|
||||
listForOrg o = let
|
||||
limit = 10
|
||||
paginate (repos /\ pageN) =
|
||||
do
|
||||
newRepos <- getPage pageN
|
||||
pure if Array.length newRepos < limit then
|
||||
Done $ repos <> newRepos
|
||||
else
|
||||
Loop $ (repos <> newRepos) /\ (pageN + 1)
|
||||
getPage n = do
|
||||
{ auth } <- ask
|
||||
url <- orgReposURL o
|
||||
rep <- HTTP.fetch $ HTTP.GET /\ url /\ Auth.headers auth
|
||||
Error.tryGetRepJSON rep
|
||||
in tailRecM paginate ([] /\ 1)
|
||||
|
||||
listForOrg o =
|
||||
let
|
||||
limit = 10
|
||||
paginate (repos /\ pageN) =
|
||||
do
|
||||
newRepos <- getPage pageN
|
||||
pure
|
||||
if Array.length newRepos < limit then
|
||||
Done $ repos <> newRepos
|
||||
else
|
||||
Loop $ (repos <> newRepos) /\ (pageN + 1)
|
||||
getPage n = do
|
||||
{ auth } <- ask
|
||||
url <- orgReposURL o { limit, page: n }
|
||||
rep <- HTTP.fetch $ HTTP.GET /\ url /\ Auth.headers auth
|
||||
Error.tryGetRepJSON rep
|
||||
in
|
||||
tailRecM paginate ([] /\ 1)
|
||||
|
||||
update
|
||||
:: forall m patch
|
||||
|
@ -42,7 +42,6 @@ derive newtype instance Monad m => MonadError Gitea.Error.Error (GiteaT m)
|
||||
derive newtype instance Monad m => MonadThrow Gitea.Error.Error (GiteaT m)
|
||||
derive newtype instance MonadRec m => MonadRec (GiteaT m)
|
||||
|
||||
|
||||
derive newtype instance Monad m => Functor (GiteaT m)
|
||||
derive newtype instance Monad m => Apply (GiteaT m)
|
||||
derive newtype instance Monad m => Applicative (GiteaT m)
|
||||
|
Loading…
Reference in New Issue
Block a user