forgejo (empty) → 0.1.0
raw patch · 6 files changed
+297/−0 lines, 6 filesdep +basedep +bytestringdep +extra
Dependencies added: base, bytestring, extra, forgejo, gitea-api, http-client-tls, simple-cmd, simple-cmd-args, text
Files
- ChangeLog.md +5/−0
- LICENSE +29/−0
- README.md +39/−0
- app/Main.hs +69/−0
- forgejo.cabal +80/−0
- src/Gitea/Forgejo.hs +75/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# forgejo releases++## 0.1.0 (2026-11-23)+- inital release with `listOrgRepos` and `listRepoIssues`+- also corresponding CLI
+ LICENSE view
@@ -0,0 +1,29 @@+Copyright (c) 2026, Jens Petersen+++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of the copyright holder nor the names of its+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,39 @@+# forgejo++A simple Haskell library and query cli for gitea/forgejo forges built+on top of [gitea-api](https://hackage.haskell.org/package/gitea-api).++Currently only has two functions:++- `listOrgRepos`+- `listRepoIssues`++and corresponding CLI tool.++The package is distributed under a BSD3 license.++## CLI tool++`$ forgejo --version`++```+0.1.0+```++`$ forgejo --help`++```+Forgejo client++Usage: forgejo [--version] COMMAND++ Simple forgejo CLI++Available options:+ -h,--help Show this help text+ --version Show version++Available commands:+ repos list org's repos+ issues list repo issues+```
+ app/Main.hs view
@@ -0,0 +1,69 @@+-- SPDX-License-Identifier: BSD-3-Clause++module Main (main) where++import Data.List (sort)+import Data.Maybe (mapMaybe)+import qualified Data.Text as T+import SimpleCmd (error', (+-+))+import SimpleCmdArgs++import Gitea.Forgejo (RepoIssueOptions(..), fedoraForge,+ listOrgRepos, listRepoIssues,+ Repository(repositoryName), Issue(issueNumber, issueTitle))+import Paths_forgejo (version)++main :: IO ()+main =+ simpleCmdArgs (Just version) "Forgejo client" "Simple forgejo CLI" $+ subcommands+ [ Subcommand "repos" "list org's repos" $+ listOrgReposCmd+ <$> serviceOpt+ <*> switchLongWith "full" "Print full name"+ <*> strArg "ORG"+ , Subcommand "issues" "list repo issues" $+ repoIssuesCmd+ <$> serviceOpt+ <*> optional (strOptionLongWith "created-by" "USER" "Only issues created by USER")+ <*> optional (optionLongWith (eitherReader parseIssueState) "state" "STATE" "open, closed, or all")+ <*> strArg "OWNER/REPO"+ ]+ where+ serviceOpt = strOptionalWith 's' "server" "URL" ("Forgejo server" +-+ "[default:" +-+ fedoraForge ++ "]") fedoraForge++listOrgReposCmd :: String -> Bool -> String -> IO ()+listOrgReposCmd url full org = do+ erepos <- listOrgRepos url org+ case erepos of+ Left err -> error' err+ Right repos ->+ mapM_ (printRepo . T.unpack) . sort $+ mapMaybe repositoryName repos+ where+ printRepo repo =+ putStrLn $ (if full then org ++ "/" else "") ++ repo++repoIssuesCmd :: String -> Maybe String -> Maybe String -> String+ -> IO ()+repoIssuesCmd url createdBy state repoPath =+ case break (== '/') repoPath of+ (owner, '/':repo) | not (null owner) && not (null repo) && '/' `notElem` repo -> do+ let options = RepoIssueOptions createdBy state+ eissues <- listRepoIssues url owner repo options+ case eissues of+ Left err -> error' err+ Right issues ->+ mapM_ printIssue . sort $ mapMaybe issueSummary issues+ _ -> fail "Expected repository in OWNER/REPO form"+ where+ issueSummary issue =+ (,) <$> issueNumber issue <*> issueTitle issue+ printIssue (number, title) =+ putStrLn $ "#" ++ show number ++ " " ++ T.unpack title++parseIssueState :: String -> Either String String+parseIssueState s =+ if s `elem` ["open","closed","all"]+ then Right s+ else Left "STATE must be open, closed, or all"
+ forgejo.cabal view
@@ -0,0 +1,80 @@+cabal-version: 2.2+name: forgejo+version: 0.1.0+synopsis: forgejo query library and cli+description:+ A simple Forgejo/Gitea forge query library and cli tool.+license: BSD-3-Clause+license-file: LICENSE+author: Jens Petersen <juhpetersen@gmail.com>+maintainer: Jens Petersen <juhpetersen@gmail.com>+copyright: 2026 Jens Petersen <juhpetersen@gmail.com>+category: Web+homepage: https://github.com/juhp/forgejo-hs+bug-reports: https://github.com/juhp/forgejo-hs/issues+build-type: Simple+extra-doc-files: README.md+ ChangeLog.md+tested-with: GHC == 8.10.7+ || == 9.0.2+ || == 9.2.8+ || == 9.4.8+ || == 9.6.7+ || == 9.8.4+ || == 9.10.3++source-repository head+ type: git+ location: https://github.com/juhp/forgejo-hs.git++executable forgejo+ main-is: Main.hs+ other-modules: Paths_forgejo+ autogen-modules: Paths_forgejo+ hs-source-dirs: app+ build-depends: base < 5,+ forgejo,+ simple-cmd >= 0.1.4,+ simple-cmd-args,+ text+ default-language: Haskell2010+ ghc-options: -Wall+ if impl(ghc >= 8.0)+ ghc-options: -Wcompat+ -Widentities+ -Wincomplete-uni-patterns+ -Wincomplete-record-updates+ -Wredundant-constraints+ if impl(ghc >= 8.2)+ ghc-options: -fhide-source-paths+ if impl(ghc >= 8.4)+ ghc-options: -Wmissing-export-lists+ -Wpartial-fields+ if impl(ghc >= 8.10)+ ghc-options: -Wunused-packages++library+ build-depends: base < 5,+ bytestring,+ extra,+ gitea-api,+ http-client-tls,+ text+ default-language: Haskell2010+ exposed-modules: Gitea.Forgejo+ hs-source-dirs: src++ ghc-options: -Wall+ if impl(ghc >= 8.0)+ ghc-options: -Wcompat+ -Widentities+ -Wincomplete-uni-patterns+ -Wincomplete-record-updates+ -Wredundant-constraints+ if impl(ghc >= 8.2)+ ghc-options: -fhide-source-paths+ if impl(ghc >= 8.4)+ ghc-options: -Wmissing-export-lists+ -Wpartial-fields+ if impl(ghc >= 8.10)+ ghc-options: -Wunused-packages
+ src/Gitea/Forgejo.hs view
@@ -0,0 +1,75 @@+module Gitea.Forgejo (+ listOrgRepos,+ listRepoIssues,+ RepoIssueOptions(..),+ defaultRepoIssueOptions,+ fedoraForge,+ Repository(..),+ Issue(..),+ Label(..)+ )+where++import qualified Data.ByteString.Lazy.Char8 as B+import Data.Char (toLower)+import Data.Either.Extra (mapLeft)+import qualified Data.Text as T+import Gitea (configHost, configValidateAuthMethods, dispatchMime, issueListIssues, mimeError, mimeResult, newConfig, orgListRepos, (-&-), CreatedBy(..), E'State4(..), E'Type3(..), Issue(..), Label(..), Org(..), Owner(..), ParamType2(..), Repo(..), Repository(..), State3(..))+import Network.HTTP.Client.TLS (newTlsManager)++-- | Fedora Forge api url+fedoraForge :: String+fedoraForge = "https://forge.fedoraproject.org/api/v1"++-- | List the repositories of a Forgejo org+listOrgRepos :: String -- ^ api url+ -> String -- ^ org+ -> IO (Either String [Repository])+listOrgRepos url org = do+ let req = orgListRepos (Org $ T.pack org)+ mgr <- newTlsManager+ config' <- newConfig+ let config = config'+ { configHost = B.pack url+ , configValidateAuthMethods = False }+ -- `addAuthMethod` AuthOAuthFoo "secret-key"+ mapLeft mimeError . mimeResult <$> dispatchMime mgr config req++data RepoIssueOptions = RepoIssueOptions+ { repoIssueCreatedBy :: Maybe String+ , repoIssueState :: Maybe String+ }++-- | no options+defaultRepoIssueOptions :: RepoIssueOptions+defaultRepoIssueOptions = RepoIssueOptions Nothing Nothing++-- | List issues in a forgejo repo+listRepoIssues :: String -- ^ api url+ -> String -- ^ repo owner+ -> String -- ^ repo+ -> RepoIssueOptions -- ^ issue filter options+ -> IO (Either String [Issue])+listRepoIssues url owner repo options = do+ let baseReq = issueListIssues (Owner $ T.pack owner) (Repo $ T.pack repo)+ -&- ParamType2 E'Type3'Issues+ creatorReq = maybe baseReq+ ((\user -> baseReq -&- CreatedBy user) . T.pack) $+ repoIssueCreatedBy options+ req = maybe creatorReq+ ((\state -> creatorReq -&- State3 state) . toE'State4') $+ repoIssueState options+ mgr <- newTlsManager+ config' <- newConfig+ let config = config'+ { configHost = B.pack url+ , configValidateAuthMethods = False }+ mapLeft mimeError . mimeResult <$> dispatchMime mgr config req++toE'State4' :: String -> E'State4+toE'State4' s =+ case map toLower s of+ "closed" -> E'State4'Closed+ "open" -> E'State4'Open+ "all" -> E'State4'All+ _ -> error $ "toE'State4': enum parse failure: " ++ show s