pagure-cli 0.2.3 → 0.3
raw patch · 5 files changed
+652/−260 lines, 5 filesdep +pagure-clidep −filepathdep −optparse-applicativedep ~basedep ~pagure
Dependencies added: pagure-cli
Dependencies removed: filepath, optparse-applicative
Dependency ranges changed: base, pagure
Files
- CHANGELOG.md +8/−0
- README.md +20/−7
- pagure-cli.cabal +47/−14
- src/Fedora/Pagure/Client.hs +523/−0
- src/Main.hs +54/−239
CHANGELOG.md view
@@ -1,5 +1,13 @@ # Changelog +## 0.3 (2026-06-16)+- add 'pull-requests' and 'pull-request' commands+- add 'user-activity-stats' command+- add 'user-activity-date' command+- add 'user-issues' command+- add 'user-requests-filed' command+- add 'user-requests-actionable' command+ ## 0.2.3 (2026-02-11) - hide output of empty lists and object by default (behind --show-empty) - add 'contributors' command
README.md view
@@ -8,6 +8,8 @@ A [pagure](https://docs.pagure.org/pagure/) gitforge client for querying and listing projects (repos), users, groups, and issues. +Since version 0.3, a client library provides the module `Fedora.Pagure.Client`.+ ## Usage By default it uses the [src.fedoraproject.org](https://src.fedoraproject.org/) Pagure server instance (aka Fedora dist-git), but this can be overriden@@ -30,10 +32,10 @@ Count projects of a user: -`$ pagure user --server pagure.io --count jspaleta`+`$ pagure user --count petersen` ```-11+825 ``` ### List groups:@@ -52,16 +54,19 @@ rpms/budgie-display-configurator rpms/gtklock rpms/gtk-session-lock+forks/packit/rpms/labwc+rpms/labwc rpms/libxfce4windowing rpms/pocillo-gtk-theme rpms/sassc rpms/wlrctl ``` + `$ pagure group -c rust-sig` ```-4266+4826 ``` ## Help@@ -69,7 +74,7 @@ `$ pagure --version` ```-0.2.3+0.3 ``` `$ pagure --help`@@ -95,9 +100,16 @@ contributors show project repo's contributors issues list project issues issue show project issue+ pull-requests list project pull requests+ pull-request show project PR users list users username fullname of user userinfo show user details+ user-activity-stats show user activity stats+ user-activity-date show user activity on date+ user-issues show user's issues+ user-requests-filed show user's filed pull requests+ user-requests-actionable show user's actionable pull requests groups list groups groupinfo show group details ```@@ -115,7 +127,7 @@ Or to build from the git source, run the commands without the package name. ## Contributions-Pagure rest API can be found on pagure servers: eg <https://pagure.io/api/0>.+Pagure rest API can be found on pagure servers: eg <https://src.fedoraproject.org/api/0/>. There are still many unsupported commands and options. Please open a ticket or PR to request adding more at <https://github.com/juhp/pagure-cli>.@@ -123,9 +135,10 @@ Also part of this client uses the simple [pagure-hs](https://hackage.haskell.org/package/pagure) bindings. +The project is distributed under GPLv2+.+ ## Other pagure clients After writing the initial version I discovered that Ricky Elrod (relrod) had made <https://github.com/fedora-infra/pagure-cli>. -There is a library client in Rust <https://pagure.io/ironthree/pagure-rs>-by decathorpe.+A library client in Rust <https://pagure.io/ironthree/pagure-rs> by decathorpe.
pagure-cli.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: pagure-cli-version: 0.2.3+version: 0.3 synopsis: A Pagure gitforge query tool description: A command-line Pagure (gitforge) client for querying and listing projects, users, groups, and issues.@@ -18,7 +18,7 @@ tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.2, GHC == 9.2.8, GHC == 9.4.8, GHC == 9.6.6, GHC == 9.8.4, GHC == 9.10.3,- GHC == 9.12.3+ GHC == 9.12.4 source-repository head type: git@@ -27,28 +27,61 @@ executable pagure main-is: src/Main.hs + build-depends: base < 5+ , pagure-cli+ , simple-cmd-args >= 0.1.6+ if impl(ghc<8.0)+ build-depends: semigroups++ other-modules: Paths_pagure_cli++ 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++ default-language: Haskell2010++library build-depends: aeson , aeson-pretty- , base < 5+ , base >= 4 && < 5 , bytestring , extra- , filepath , http-query- , optparse-applicative- , pagure >= 0.2.1+ , pagure >= 0.2.2 , simple-cmd- , simple-cmd-args >= 0.1.6 , text- , unordered-containers , vector , yaml-- if impl(ghc<8.0)- build-depends: semigroups-- other-modules: Paths_pagure_cli+ if impl(ghc < 9)+ build-depends: unordered-containers+ hs-source-dirs: src+ exposed-modules: Fedora.Pagure.Client 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 default-language: Haskell2010- default-extensions: OverloadedStrings
+ src/Fedora/Pagure/Client.hs view
@@ -0,0 +1,523 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}++module Fedora.Pagure.Client (+ OutputFormat(..),+ Packager(..),+ Forks(..),+ srcFedoraprojectOrg,+ defaultPrinter,+ yamlPrinter,+ listProjects,+ projectIssues,+ projectPRs,+ projectInfo,+ projectIssue,+ projectPR,+ repoBranches,+ users,+ userRepos,+ userInfo,+ username,+ userIssues,+ userRequestsFiled,+ userRequestsActionable,+ userActivityStats,+ userActivityDate,+ groups,+ groupInfo,+ groupProjects,+ gitUrl,+ contributors,+ )+where++import Control.Applicative (+#if !MIN_VERSION_base(4,8,0)+ (<$>), (<*>),+#endif+ )+import Control.Monad.Extra (unless, when, whenJust)+import Data.Aeson.Encode.Pretty (encodePretty)+import Data.Aeson.Types+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as M+#else+import qualified Data.HashMap.Lazy as M+#endif+import qualified Data.ByteString.Char8 as B+import qualified Data.ByteString.Lazy.Char8 as BL+import Data.List.Extra (lower)+import Data.Maybe+import Data.Text (Text)+import qualified Data.Text as T+import qualified Data.Text.IO as T+import qualified Data.Vector as V+import Data.Yaml (encode)+import Network.HTTP.Query ((+/+))+import SimpleCmd (error', (+-+))+import Fedora.Pagure++data OutputFormat = FormatDefault+ | FormatJson+ | FormatYaml++data Packager = Owner String+ | Committer String++data Forks = NoForks+ | IncludeForks+ | OnlyForks++-- | Fedora dist-git+srcFedoraprojectOrg :: String+srcFedoraprojectOrg = "src.fedoraproject.org"++-- | default print helper+defaultPrinter :: Bool -- ^ no hide empty+ -> OutputFormat+ -> (Object -> IO ()) -- ^ printer+ -> Object -- ^ JSON+ -> IO ()+defaultPrinter _ FormatDefault pr = pr+defaultPrinter nohide fmt _ = yamlPrinter nohide fmt++-- | List projects+listProjects :: String -- ^ server+ -> Bool -- ^ count+ -> Bool -- ^ no hide+ -> OutputFormat+ -> Forks+ -> Maybe String -- ^ namespace+ -> Maybe Packager+ -> Maybe String -- ^ pattern+ -> IO ()+listProjects server count nohide format forks mnamespace mpackager mpattern = do+ unless (count || isJust mpackager || isJust mpattern) $+ error' "Please give a package pattern, --count, or --owner/--username"+ let path = "projects"+ params = makeKey "short" "1" ++ fork ++ packager ++ maybeKey "namespace" mnamespace ++ maybeKey "pattern" mpattern+ pages <- queryPagureCountPaged server count path params ("pagination", "page")+ let projects = concatMap (lookupKey' "projects") pages+ mapM_ (defaultPrinter nohide format printProject) projects+ where+ -- (!orphan only works on pagure >=0.29)+ packager = case mpackager of+ Nothing -> boolKey (server == srcFedoraprojectOrg) "owner" "!orphan"+ Just (Owner o) -> makeKey "owner" o+ Just (Committer c) -> makeKey "username" c++ fork = case forks of+ NoForks -> makeKey "fork" "0"+ IncludeForks -> []+ OnlyForks -> makeKey "fork" "1"++ printProject :: Object -> IO ()+ printProject project = do+ let key' = if isJust mnamespace then "name" else "fullname"+ whenJust (lookupKey key' project) T.putStrLn++-- FIXME duplicates subset of listProjects+-- | Variant of `pagureUserRepos` or `pagureUserForks`+userRepos :: String -- ^ server+ -> Bool -- ^ count+ -> Bool -- ^ forks+ -> String -- ^ user+ -> IO ()+userRepos server count forks user =+ if count then do+ let path = "user" +/+ user+ mcnt <- queryPagureCount server path [] $+ if forks then "forks_pagination" else "repos_pagination"+ print $+ fromMaybe+ (error' ("number of" +-+ (if forks then "forks" else "repos") +-+ "could not be determined"))+ mcnt+ else do+ repos <- (if forks then pagureUserForks else pagureUserRepos) server user+ mapM_ T.putStrLn repos++boolKey :: Bool -> String -> String -> Query+boolKey False _ _ = []+boolKey True k val = makeKey k val++-- FIXME limit max number of issues+-- | List project issues+--+-- Please use allstatus with care since it can list of a lot issues+projectIssues :: String -- ^ server+ -> Bool -- ^ count+ -> Bool -- ^ no hide+ -> OutputFormat+ -> Bool -- ^ all status+ -> Maybe String -- ^ author+ -> Maybe String -- ^ since+ -> Maybe String -- ^ pattern+ -> String -- ^ repo+ -> IO ()+projectIssues server count nohide format allstatus mauthor msince mpat repo = do+ let path = repo +/+ "issues"+ params = boolKey allstatus "status" "all" +++ maybeKey "author" mauthor ++ maybeKey "since" msince+ pages <- queryPagureCountPaged server count path params ("pagination", "page")+ mapM_ (defaultPrinter nohide format printIssues) pages+ where+ printIssues :: Object -> IO ()+ printIssues result = do+ let issues = lookupKey' "issues" result :: [Object]+ mapM_ printIssue issues++ printIssue :: Object -> IO ()+ printIssue issue = do+ case parseIssue issue of+ Nothing -> putStrLn "parsing issue failed"+ Just (id',title,status) ->+ when (isNothing mpat || T.pack (fromJust mpat) `T.isInfixOf` title) $+ putStrLn $ "https://" ++ server +/+ repo +/+ "issue" +/+ show id' ++ (if allstatus then " (" ++ T.unpack status ++ ")" else "") +-+ ":" +-+ T.unpack title++ parseIssue :: Object -> Maybe (Integer, Text, Text)+ parseIssue =+ parseMaybe $ \obj -> do+ id' <- obj .: "id"+ title <- obj .: "title"+ status <- obj .: "status"+ return (id',title,status)++-- FIXME limit max number of issues+-- | List pull-requests+--+-- Please use allstatus with care since it can list of a lot of requests+projectPRs :: String -- ^ server+ -> Bool -- ^ count+ -> Bool -- ^ no hide+ -> OutputFormat+ -> Bool -- ^ all status+ -> Maybe String -- ^ author+ -> Maybe String -- ^ since+ -> Maybe String -- ^ pattern+ -> String -- ^ repo+ -> IO ()+projectPRs server count nohide format allstatus mauthor msince mpat repo = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ project = namespace ++ repo+ path = project +/+ "pull-requests"+ params = [makeItem "status" "all" | allstatus] +++ maybeKey "author" mauthor ++ maybeKey "since" msince+ pages <- queryPagureCountPaged server count path params ("pagination", "page")+ mapM_ (defaultPrinter nohide format (printPRs project)) pages+ where+ printPRs :: String -> Object -> IO ()+ printPRs project result = do+ let prs = lookupKey' "requests" result :: [Object]+ mapM_ (printPR project) prs++ printPR :: String -> Object -> IO ()+ printPR project pr = do+ case parsePR pr of+ Nothing -> putStrLn "parsing issue failed"+ Just (id',title,status) ->+ when (isNothing mpat || T.pack (fromJust mpat) `T.isInfixOf` title) $+ putStrLn $ "https://" ++ server +/+ project +/+ "pull-request" +/+ show id' ++ (if allstatus then " (" ++ lower (T.unpack status) ++ ")" else "") +-+ ":" +-+ T.unpack title++ parsePR :: Object -> Maybe (Integer, Text, Text)+ parsePR =+ parseMaybe $ \obj -> do+ id' <- obj .: "id"+ title <- obj .: "title"+ status <- obj .: "status"+ return (id',title,status)++-- | List repo git branches+repoBranches :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> IO ()+repoBranches server nohide format repo = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ path = namespace ++ repo +/+ "git/branches"+ eres <- queryPagureSingle server path []+ either error' (defaultPrinter nohide format (printKeyList "branches")) eres++-- | List users matching pattern+users :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ pattern+ -> IO ()+users server nohide format pat = do+ let path = "users"+ params = makeKey "pattern" pat+ res <- queryPagure server path params+ defaultPrinter nohide format (printKeyList "users") res++-- | Get full name of user+username :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ user+ -> IO ()+username server nohide format user = do+ let path = "user" +/+ user+ eres <- queryPagureSingle server path $ makeKey "per_page" "1"+ case eres of+ Left err -> error' err+ Right res -> defaultPrinter nohide format printName res+ where+ printName res =+ case lookupKey "user" res >>= lookupKey "fullname" of+ Nothing -> error' "User fullname not found"+ Just fn -> T.putStrLn fn++-- | List groups with optional pattern+groups :: String -- ^ server+ -> Bool -- ^ count+ -> Bool -- ^ no hide+ -> OutputFormat+ -> Maybe String -- ^ pattern+ -> IO ()+groups server count nohide format mpat = do+ let path = "groups"+ params = maybeKey "pattern" mpat+ pages <- queryPagureCountPaged server count path params ("pagination", "page")+ mapM_ (defaultPrinter nohide format (printKeyList "groups")) pages++printKeyList :: String -> Object -> IO ()+printKeyList key' res =+ mapM_ T.putStrLn (lookupKey' (T.pack key') res :: [Text])++-- | Print git url of project+gitUrl :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> IO ()+gitUrl server nohide format repo = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ path = namespace ++ repo +/+ "git/urls"+ res <- queryPagure server path []+ defaultPrinter nohide format printURLs res+ where+ printURLs result =+ mapM_ T.putStrLn $+ M.elems $ localLookupKey "urls" result++ localLookupKey :: String -> Object ->+#if MIN_VERSION_aeson(2,0,0)+ M.KeyMap Text+#else+ M.HashMap Text Text+#endif+ localLookupKey = lookupKey' . T.pack++-- | List contributors of project+contributors :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> IO ()+contributors server nohide format repo = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ path = namespace ++ repo +/+ "contributors"+ res <- queryPagure server path []+ yamlPrinter nohide format res++-- | Yaml printer+yamlPrinter :: Bool -- ^ no hide+ -> OutputFormat+ -> Object+ -> IO ()+yamlPrinter nohide format =+ case format of+ FormatDefault -> yamlPrinter nohide FormatYaml+ FormatJson -> BL.putStrLn . encodePretty . hideEmpty+ FormatYaml -> B.putStrLn . encode . hideEmpty+ where+ hideEmpty = if nohide then id else cleanObject++ cleanObject :: Object -> Object+ cleanObject = M.mapMaybe go+ where+ go :: Value -> Maybe Value+ -- drop empty lists+ go (Array v) | V.null v = Nothing+ | otherwise = Just $ Array (V.map (wrap go) v)+ where+ wrap f (Object o) = Object (M.mapMaybe f o)+ wrap f (Array a) = Array (V.map (wrap f) a)+ wrap _ x = x+ -- drop empty objects+ go (Object o) =+ let cleaned = M.mapMaybe go o+ in if M.null cleaned then Nothing else Just (Object cleaned)+ go other = Just other++-- | Show project info+projectInfo :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> IO ()+projectInfo server nohide format repo = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ path = namespace ++ repo+ eval <- pagureProjectInfo server path+ either error' (yamlPrinter nohide format) eval++-- | Display project issue+projectIssue :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> Int -- ^ issue+ -> IO ()+projectIssue server nohide format repo issue = do+ eval <- pagureProjectIssueInfo server repo issue+ either error' (yamlPrinter nohide format) eval++-- | Display project pull request+projectPR :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ repo+ -> Int -- ^ PR number+ -> IO ()+projectPR server nohide format repo issue = do+ let namespace =+ if server == srcFedoraprojectOrg && '/' `notElem` repo+ then "rpms/" else ""+ project = namespace ++ repo+ eval <- pagureProjectPRInfo server project issue+ either error' (yamlPrinter nohide format) eval++-- | Display user info+userInfo :: String -- ^ server+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ user+ -> IO ()+userInfo server nohide format user = do+ eval <- pagureUserInfo server user []+ either error' (yamlPrinter nohide format) eval++-- | Show user activity stats+userActivityStats :: String -- ^ server+ -> OutputFormat+ -> String -- ^ user+ -> IO ()+userActivityStats server format user = do+ eval <- pagureUserActivityStats server False user+ either error' (yamlPrinter False format) eval++-- | Show user activity on date+userActivityDate :: String -- ^ server+ -> OutputFormat+ -> Bool -- ^ summary+ -> String -- ^ user+ -> String -- ^ date+ -> IO ()+userActivityDate server format summary user date = do+ eval <- pagureUserActivityDate server summary user date+ either error' (yamlPrinter False format) eval++-- | List user issues+userIssues :: String -- ^ server+ -> Bool -- ^ count+ -> OutputFormat+ -> String -- ^ user+ -> IO ()+userIssues server count format user = do+ issues <- pagureUserIssues server count user+ mapM_ (yamlPrinter False format) issues++-- | List pull requests filed by user+userRequestsFiled :: String -- ^ server+ -> Bool -- ^ count+ -> OutputFormat+ -> Maybe String -- ^ pattern+ -> Maybe String -- ^ status+ -> String -- ^ user+ -> IO ()+userRequestsFiled server count format mpat mstatus user = do+ result <- pagureUserRequestsFiled server count (fromMaybe "Open" mstatus) user+ let requests = concatMap (lookupKey' "requests") result+ mapM_ (defaultPrinter False format printPR) requests+ where+ printPR :: Object -> IO ()+ printPR pr = do+ case parsePR pr of+ Nothing -> putStrLn "parsing PR failed"+ Just (id',title,repo) ->+ when (isNothing mpat || T.pack (fromJust mpat) `T.isInfixOf` title) $+ putStrLn $ "https://" ++ server +/+ T.unpack repo +/+ "pull-request" +/+ show id' +-+ show (T.unpack title)++ parsePR :: Object -> Maybe (Integer, Text, Text)+ parsePR =+ parseMaybe $ \obj -> do+ id' <- obj .: "id"+ title <- obj .: "title"+ proj <- obj .: "project"+ repo <- proj .: "fullname"+ return (id',title,repo)++-- | Show actionable pull requests for user+userRequestsActionable :: String -- ^ server+ -> Bool -- ^ count+ -> OutputFormat+ -> Maybe String -- ^ pattern+ -> Maybe String -- ^ status+ -> String -- ^ user+ -> IO ()+userRequestsActionable server count format mpat mstatus user = do+ result <- pagureUserRequestsActionable server count (fromMaybe "Open" mstatus) user+ let requests = concatMap (lookupKey' "requests") result+ mapM_ (defaultPrinter False format printPR) requests+ where+ printPR :: Object -> IO ()+ printPR pr = do+ case parsePR pr of+ Nothing -> putStrLn "parsing PR failed"+ Just (id',title,repo) ->+ when (isNothing mpat || T.pack (fromJust mpat) `T.isInfixOf` title) $+ putStrLn $ "https://" ++ server +/+ T.unpack repo +/+ "pull-request" +/+ show id' +-+ show (T.unpack title)++ parsePR :: Object -> Maybe (Integer, Text, Text)+ parsePR =+ parseMaybe $ \obj -> do+ id' <- obj .: "id"+ title <- obj .: "title"+ proj <- obj .: "project"+ repo <- proj .: "fullname"+ return (id',title,repo)++-- | Show group info+groupInfo :: String -- ^ server+ -> Bool -- ^ projects+ -> Bool -- ^ no hide+ -> OutputFormat+ -> String -- ^ group+ -> IO ()+groupInfo server projects nohide format group = do+ let params = boolKey projects "projects" "1"+ eval <- pagureGroupInfo server group params+ either error' (yamlPrinter nohide format) eval++-- FIXME support acl parameter (admin, commit or ticket)+-- | List group projects+groupProjects :: String -- ^ server+ -> Bool -- ^ count+ -> String -- ^ group+ -> IO ()+groupProjects server count group =+ pagureGroupRepos server count group >>=+ mapM_ T.putStrLn
src/Main.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE OverloadedStrings #-} module Main (main) where @@ -11,27 +10,9 @@ (<|>) #endif )-import Control.Monad.Extra (unless, when, whenJust)-import Data.Aeson.Encode.Pretty (encodePretty)-import Data.Aeson.Types-#if MIN_VERSION_aeson(2,0,0)-import qualified Data.Aeson.KeyMap as M-#else-import qualified Data.HashMap.Lazy as M-#endif-import qualified Data.ByteString.Char8 as B-import qualified Data.ByteString.Lazy.Char8 as BL-import Data.Maybe-import Data.Text (Text)-import qualified Data.Text as T-import qualified Data.Text.IO as T-import qualified Data.Vector as V-import Data.Yaml (encode)-import Network.HTTP.Query ((+/+))-import SimpleCmd (error', (+-+)) import SimpleCmdArgs-import Fedora.Pagure +import Fedora.Pagure.Client import Paths_pagure_cli (version) main :: IO ()@@ -89,11 +70,11 @@ <*> countOpt <*> nohideOpt <*> formatOpt- <*> strArg "REPO" <*> switchWith 'A' "all" "list Open and Closed issues" <*> optional (strOptionWith 'a' "author" "AUTHOR" "Filter issues by creator") <*> optional (strOptionWith 'S' "since" "Y-M-D" "Filter issues updated after date") <*> optional (strOptionWith 't' "title" "pattern" "Filter issues by title")+ <*> strArg "REPO" , Subcommand "issue" "show project issue" $ projectIssue <$> serverOpt@@ -101,6 +82,24 @@ <*> formatOpt <*> strArg "REPO" <*> argumentWith auto "ISSUE"+ , Subcommand "pull-requests" "list project pull requests" $+ projectPRs+ <$> serverOpt+ <*> countOpt+ <*> nohideOpt+ <*> formatOpt+ <*> switchWith 'A' "all" "list Open and Closed issues"+ <*> optional (strOptionWith 'a' "author" "AUTHOR" "Filter issues by creator")+ <*> optional (strOptionWith 'S' "since" "Y-M-D" "Filter issues updated after date")+ <*> optional (strOptionWith 't' "title" "pattern" "Filter issues by title")+ <*> strArg "REPO"+ , Subcommand "pull-request" "show project PR" $+ projectPR+ <$> serverOpt+ <*> nohideOpt+ <*> formatOpt+ <*> strArg "REPO"+ <*> argumentWith auto "ISSUE" , Subcommand "users" "list users" $ users <$> serverOpt@@ -119,6 +118,40 @@ <*> nohideOpt <*> formatOpt <*> strArg "USERNAME"+ , Subcommand "user-activity-stats" "show user activity stats" $+ userActivityStats+ <$> serverOpt+ <*> formatOpt+ <*> strArg "USERNAME"+ , Subcommand "user-activity-date" "show user activity on date" $+ userActivityDate+ <$> serverOpt+ <*> formatOpt+ <*> switchWith 'S' "summary" "Summarize (group) activity per project"+ <*> strArg "USERNAME"+ <*> strArg "YYYY-MM-DD"+ , Subcommand "user-issues" "show user's issues" $+ userIssues+ <$> serverOpt+ <*> countOpt+ <*> formatOpt+ <*> strArg "USERNAME"+ , Subcommand "user-requests-filed" "show user's filed pull requests" $+ userRequestsFiled+ <$> serverOpt+ <*> countOpt+ <*> formatOpt+ <*> optional (strOptionWith 't' "title" "pattern" "Filter requests by title")+ <*> optional (strOptionWith 'S' "status" "open|closed|merged|all" "Select by status [default: Open]")+ <*> strArg "USERNAME"+ , Subcommand "user-requests-actionable" "show user's actionable pull requests" $+ userRequestsActionable+ <$> serverOpt+ <*> countOpt+ <*> formatOpt+ <*> optional (strOptionWith 't' "title" "pattern" "Filter requests by title")+ <*> optional (strOptionWith 'S' "status" "Open|Closed|Merged|All" "Select by status [default: Open]")+ <*> strArg "USERNAME" , Subcommand "groups" "list groups" $ groups <$> serverOpt@@ -145,221 +178,3 @@ serverOpt = strOptionalWith 's' "server" "SERVER" "Pagure server" srcFedoraprojectOrg forksOpt = flagWith' OnlyForks 'F' "only-forks" "Only list forks" <|> flagWith NoForks IncludeForks 'f' "include-forks" "Include forks [default: ignore forks]"--data OutputFormat = FormatDefault | FormatJson | FormatYaml--data Packager = Owner String | Committer String--data Forks = NoForks | IncludeForks | OnlyForks--srcFedoraprojectOrg :: String-srcFedoraprojectOrg = "src.fedoraproject.org"--defaultPrinter :: Bool -> OutputFormat -> (Object -> IO ()) -> Object -> IO ()-defaultPrinter _ FormatDefault pr = pr-defaultPrinter nohide fmt _ = yamlPrinter nohide fmt--listProjects :: String -> Bool -> Bool -> OutputFormat -> Forks -> Maybe String- -> Maybe Packager -> Maybe String -> IO ()-listProjects server count nohide format forks mnamespace mpackager mpattern = do- unless (count || isJust mpackager || isJust mpattern) $- error' "Please give a package pattern, --count, or --owner/--username"- let path = "projects"- params = makeKey "short" "1" ++ fork ++ packager ++ maybeKey "namespace" mnamespace ++ maybeKey "pattern" mpattern- pages <- queryPagureCountPaged server count path params ("pagination", "page")- let projects = concatMap (lookupKey' "projects") pages- mapM_ (defaultPrinter nohide format printProject) projects- where- -- (!orphan only works on pagure >=0.29)- packager = case mpackager of- Nothing -> boolKey "owner" (server == srcFedoraprojectOrg) "!orphan"- Just (Owner o) -> makeKey "owner" o- Just (Committer c) -> makeKey "username" c-- fork = case forks of- NoForks -> makeKey "fork" "0"- IncludeForks -> []- OnlyForks -> makeKey "fork" "1"-- printProject :: Object -> IO ()- printProject project = do- let key' = if isJust mnamespace then "name" else "fullname"- whenJust (lookupKey key' project) T.putStrLn---- FIXME duplicates subset of listProjects-userRepos :: String -> Bool -> Bool -> String -> IO ()-userRepos server count forks user =- if count then do- let path = "user" +/+ user- mcnt <- queryPagureCount server path [] $- if forks then "forks_pagination" else "repos_pagination"- print $- fromMaybe- (error' ("number of" +-+ (if forks then "forks" else "repos") +-+ "could not be determined"))- mcnt- else do- repos <- (if forks then pagureUserForks else pagureUserRepos) server user- mapM_ T.putStrLn repos--boolKey :: String -> Bool -> String -> Query-boolKey _ False _ = []-boolKey k True val = makeKey k val---- FIXME limit max number of issues-projectIssues :: String -> Bool -> Bool -> OutputFormat -> String -> Bool- -> Maybe String -> Maybe String -> Maybe String -> IO ()-projectIssues server count nohide format repo allstatus mauthor msince mpat = do- let path = repo +/+ "issues"- params = [makeItem "status" "all" | allstatus] ++- maybeKey "author" mauthor ++ maybeKey "since" msince- pages <- queryPagureCountPaged server count path params ("pagination", "page")- mapM_ (defaultPrinter nohide format printIssues) pages- where- printIssues :: Object -> IO ()- printIssues result = do- let issues = lookupKey' "issues" result :: [Object]- mapM_ printIssue issues-- printIssue :: Object -> IO ()- printIssue issue = do- let mfields = parseIssue issue- case mfields of- Nothing -> putStrLn "parsing issue failed"- Just (id',title,status) ->- when (isNothing mpat || T.pack (fromJust mpat) `T.isInfixOf` title) $- putStrLn $ "https://" ++ server +/+ repo +/+ "issue" +/+ show id' +-+ "(" ++ T.unpack status ++ "):" +-+ T.unpack title-- parseIssue :: Object -> Maybe (Integer, Text, Text)- parseIssue =- parseMaybe $ \obj -> do- id' <- obj .: "id"- title <- obj .: "title"- status <- obj .: "status"- return (id',title,status)--repoBranches :: String -> Bool -> OutputFormat -> String -> IO ()-repoBranches server nohide format repo = do- let namespace =- if server == srcFedoraprojectOrg && '/' `notElem` repo- then "rpms/" else ""- path = namespace ++ repo +/+ "git/branches"- eres <- queryPagureSingle server path []- either error' (defaultPrinter nohide format (printKeyList "branches")) eres--users :: String -> Bool -> OutputFormat -> String -> IO ()-users server nohide format pat = do- let path = "users"- params = makeKey "pattern" pat- res <- queryPagure server path params- defaultPrinter nohide format (printKeyList "users") res--username :: String -> Bool -> OutputFormat -> String -> IO ()-username server nohide format user = do- let path = "user" +/+ user- eres <- queryPagureSingle server path $ makeKey "per_page" "1"- case eres of- Left err -> error' err- Right res -> defaultPrinter nohide format printName res- where- printName res =- case lookupKey "user" res >>= lookupKey "fullname" of- Nothing -> error' "User fullname not found"- Just fn -> T.putStrLn fn--groups :: String -> Bool -> Bool -> OutputFormat -> Maybe String -> IO ()-groups server count nohide format mpat = do- let path = "groups"- params = maybeKey "pattern" mpat- pages <- queryPagureCountPaged server count path params ("pagination", "page")- mapM_ (defaultPrinter nohide format (printKeyList "groups")) pages--printKeyList :: String -> Object -> IO ()-printKeyList key' res =- mapM_ T.putStrLn (lookupKey' (T.pack key') res :: [Text])--gitUrl :: String -> Bool -> OutputFormat -> String -> IO ()-gitUrl server nohide format repo = do- let namespace =- if server == srcFedoraprojectOrg && '/' `notElem` repo- then "rpms/" else ""- path = namespace ++ repo +/+ "git/urls"- res <- queryPagure server path []- defaultPrinter nohide format printURLs res- where- printURLs result =- mapM_ T.putStrLn $- M.elems $ localLookupKey "urls" result-- localLookupKey :: String -> Object ->-#if MIN_VERSION_aeson(2,0,0)- M.KeyMap Text-#else- M.HashMap Text Text-#endif- localLookupKey = lookupKey' . T.pack--contributors :: String -> Bool -> OutputFormat -> String -> IO ()-contributors server nohide format repo = do- let namespace =- if server == srcFedoraprojectOrg && '/' `notElem` repo- then "rpms/" else ""- path = namespace ++ repo +/+ "contributors"- res <- queryPagure server path []- yamlPrinter nohide format res--yamlPrinter :: Bool -> OutputFormat -> Object -> IO ()-yamlPrinter nohide format =- case format of- FormatDefault -> yamlPrinter nohide FormatYaml- FormatJson -> BL.putStrLn . encodePretty . hideEmpty- FormatYaml -> B.putStrLn . encode . hideEmpty- where- hideEmpty = if nohide then id else cleanObject--cleanObject :: Object -> Object-cleanObject = M.mapMaybe go- where- go :: Value -> Maybe Value- -- drop empty lists- go (Array v) | V.null v = Nothing- | otherwise = Just $ Array (V.map (wrap go) v)- where- wrap f (Object o) = Object (M.mapMaybe f o)- wrap f (Array a) = Array (V.map (wrap f) a)- wrap _ x = x- -- drop empty objects- go (Object o) =- let cleaned = M.mapMaybe go o- in if M.null cleaned then Nothing else Just (Object cleaned)- go other = Just other--projectInfo :: String -> Bool -> OutputFormat -> String -> IO ()-projectInfo server nohide format repo = do- let namespace =- if server == srcFedoraprojectOrg && '/' `notElem` repo- then "rpms/" else ""- path = namespace ++ repo- eval <- pagureProjectInfo server path- either error' (yamlPrinter nohide format) eval--projectIssue :: String -> Bool -> OutputFormat -> String -> Int -> IO ()-projectIssue server nohide format repo issue = do- eval <- pagureProjectIssueInfo server repo issue- either error' (yamlPrinter nohide format) eval--userInfo :: String -> Bool -> OutputFormat -> String -> IO ()-userInfo server nohide format user = do- eval <- pagureUserInfo server user []- either error' (yamlPrinter nohide format) eval--groupInfo :: String -> Bool -> Bool -> OutputFormat -> String -> IO ()-groupInfo server projects nohide format group = do- let params = [makeItem "projects" "1" | projects]- eval <- pagureGroupInfo server group params- either error' (yamlPrinter nohide format) eval---- FIXME support acl parameter (admin, commit or ticket)-groupProjects :: String -> Bool -> String -> IO ()-groupProjects server count group =- pagureGroupRepos server count group >>=- mapM_ T.putStrLn