1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43-- | Helper functions for accessing the remote site.
module Remote ( getRemoteRepoList, getRemoteRepoList' ) where
import Control.Applicative ((<$>))
import Data.List (isInfixOf)
import System.Process (readProcess)
-- | Get a list of all repos you have access to (determined by your
-- SSH key).
getRemoteRepoList :: String -- ^ The git user on the remote site
-> String -- ^ The hostname
-> String -- ^ The port
-> String -- ^ Get only repos with this string as infix
-> IO [String] -- ^ The list of reponames
getRemoteRepoList user host port infixStr =
getRemoteRepoList' infixStr
<$> readProcess "ssh" [ "-p" ++ port
, user ++ "@" ++ host
, "info"
] ""
-- Output is something like:
--
-- hello obraun, this is git@gitolite ..
--
-- R W braun/14WS/algdatI/testing
-- R W braun/14WS/compiler/testing
-- R W braun/14WS/sweng/testing
-- R W testing
--
-- More Infos ...
getRemoteRepoList' :: String -- ^ Get only repos with this string as infix
-> String -- ^ The raw output from the gitolite info cmd
-> [String] -- ^ The list of reponames
getRemoteRepoList' infixStr =
filter (isInfixOf infixStr)
. filter (not . isInfixOf "..*") -- those are not concrete repos
. map (last . words) -- the last word is the repo name
. takeWhile (not . null) -- take all 'til the next emptyline
. dropWhile null -- drop empty lines
. dropWhile (not . null) -- drop the header
. lines