module GitHUD.Git.Parse.Branch (
  buildFullyQualifiedRemoteBranchName
  ) where

import Text.Parsec (parse)
import Text.Parsec.String (Parser)
import Text.Parsec.Char (anyChar, string)
import Text.Parsec.Prim (many)

buildFullyQualifiedRemoteBranchName :: String       -- ^ remote
                                    -> String       -- ^ remote Branch Name
                                    -> String
buildFullyQualifiedRemoteBranchName :: String -> String -> String
buildFullyQualifiedRemoteBranchName String
remote String
branch =
  String
remote String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (String -> String
simpleRemoteBranchName String
branch)

simpleRemoteBranchName :: String
                       -> String
simpleRemoteBranchName :: String -> String
simpleRemoteBranchName String
branch =
  (ParseError -> String)
-> (String -> String) -> Either ParseError String -> String
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
    (String -> ParseError -> String
forall a b. a -> b -> a
const String
"")
    String -> String
forall a. a -> a
id
    (Parsec String () String
-> String -> String -> Either ParseError String
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
parse Parsec String () String
remoteBranchParser String
"" String
branch)

remoteBranchParser :: Parser String
remoteBranchParser :: Parsec String () String
remoteBranchParser = do
  String -> Parsec String () String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string String
"refs/heads/"
  ParsecT String () Identity Char -> Parsec String () String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
anyChar