{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.Boards where
import Data.Either
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
import Network.HTTP.Types.Status
projectIssueBoards ::
Project ->
GitLab [IssueBoard]
projectIssueBoards :: Project -> GitLab [IssueBoard]
projectIssueBoards Project
project = do
Either Status [IssueBoard]
result <- Int -> GitLab (Either Status [IssueBoard])
projectIssueBoards' (Project -> Int
project_id Project
project)
[IssueBoard] -> GitLab [IssueBoard]
forall (m :: * -> *) a. Monad m => a -> m a
return ([IssueBoard] -> Either Status [IssueBoard] -> [IssueBoard]
forall b a. b -> Either a b -> b
fromRight [] Either Status [IssueBoard]
result)
projectIssueBoards' ::
Int ->
GitLab (Either Status [IssueBoard])
projectIssueBoards' :: Int -> GitLab (Either Status [IssueBoard])
projectIssueBoards' Int
projectId =
Text -> GitLab (Either Status [IssueBoard])
forall a. FromJSON a => Text -> GitLab (Either Status [a])
gitlab (Int -> Text
boardsAddr Int
projectId)
where
boardsAddr :: Int -> Text
boardsAddr :: Int -> Text
boardsAddr Int
projId =
Text
"/projects/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards"
projectIssueBoard ::
Project ->
Int ->
GitLab (Either Status (Maybe IssueBoard))
projectIssueBoard :: Project -> Int -> GitLab (Either Status (Maybe IssueBoard))
projectIssueBoard Project
project = do
Int -> Int -> GitLab (Either Status (Maybe IssueBoard))
projectIssueBoard' (Project -> Int
project_id Project
project)
projectIssueBoard' ::
Int ->
Int ->
GitLab (Either Status (Maybe IssueBoard))
projectIssueBoard' :: Int -> Int -> GitLab (Either Status (Maybe IssueBoard))
projectIssueBoard' Int
projectId Int
boardId = do
Text -> GitLab (Either Status (Maybe IssueBoard))
forall a. FromJSON a => Text -> GitLab (Either Status (Maybe a))
gitlabOne Text
boardAddr
where
boardAddr :: Text
boardAddr :: Text
boardAddr =
Text
"/projects/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
createIssueBoard ::
Project ->
Text ->
GitLab (Maybe IssueBoard)
createIssueBoard :: Project -> Text -> GitLab (Maybe IssueBoard)
createIssueBoard Project
project Text
boardName = do
Either Status (Maybe IssueBoard)
result <- Int -> Text -> GitLab (Either Status (Maybe IssueBoard))
createIssueBoard' (Project -> Int
project_id Project
project) Text
boardName
Maybe IssueBoard -> GitLab (Maybe IssueBoard)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe IssueBoard
-> Either Status (Maybe IssueBoard) -> Maybe IssueBoard
forall b a. b -> Either a b -> b
fromRight Maybe IssueBoard
forall a. Maybe a
Nothing Either Status (Maybe IssueBoard)
result)
createIssueBoard' ::
Int ->
Text ->
GitLab (Either Status (Maybe IssueBoard))
createIssueBoard' :: Int -> Text -> GitLab (Either Status (Maybe IssueBoard))
createIssueBoard' Int
projectId Text
boardName = do
Text -> Text -> GitLab (Either Status (Maybe IssueBoard))
forall b.
FromJSON b =>
Text -> Text -> GitLab (Either Status (Maybe b))
gitlabPost Text
boardAddr Text
T.empty
where
boardAddr :: Text
boardAddr :: Text
boardAddr =
Text
"/projects/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/?name=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
boardName
updateIssueBoard' ::
Int ->
Int ->
UpdateBoardAttrs ->
GitLab (Either Status IssueBoard)
updateIssueBoard' :: Int -> Int -> UpdateBoardAttrs -> GitLab (Either Status IssueBoard)
updateIssueBoard' Int
projectId Int
boardId UpdateBoardAttrs
attrs = do
Text -> Text -> GitLab (Either Status IssueBoard)
forall b. FromJSON b => Text -> Text -> GitLab (Either Status b)
gitlabPut Text
boardAddr Text
T.empty
where
boardAddr :: Text
boardAddr :: Text
boardAddr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (UpdateBoardAttrs -> String
updateBoardAttrs UpdateBoardAttrs
attrs)
deleteIssueBoard ::
Project ->
IssueBoard ->
GitLab (Either Status ())
deleteIssueBoard :: Project -> IssueBoard -> GitLab (Either Status ())
deleteIssueBoard Project
project IssueBoard
board = do
Int -> Int -> GitLab (Either Status ())
deleteIssueBoard' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board)
deleteIssueBoard' ::
Int ->
Int ->
GitLab (Either Status ())
deleteIssueBoard' :: Int -> Int -> GitLab (Either Status ())
deleteIssueBoard' Int
projectId Int
boardId = do
Text -> GitLab (Either Status ())
gitlabDelete Text
boardAddr
where
boardAddr :: Text
boardAddr :: Text
boardAddr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
projectBoardLists ::
Project ->
IssueBoard ->
GitLab [BoardIssue]
projectBoardLists :: Project -> IssueBoard -> GitLab [BoardIssue]
projectBoardLists Project
project IssueBoard
board = do
Either Status [BoardIssue]
result <- Int -> Int -> GitLab (Either Status [BoardIssue])
projectBoardLists' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board)
[BoardIssue] -> GitLab [BoardIssue]
forall (m :: * -> *) a. Monad m => a -> m a
return ([BoardIssue] -> Either Status [BoardIssue] -> [BoardIssue]
forall b a. b -> Either a b -> b
fromRight [] Either Status [BoardIssue]
result)
projectBoardLists' ::
Int ->
Int ->
GitLab (Either Status [BoardIssue])
projectBoardLists' :: Int -> Int -> GitLab (Either Status [BoardIssue])
projectBoardLists' Int
projectId Int
boardId =
Text -> GitLab (Either Status [BoardIssue])
forall a. FromJSON a => Text -> GitLab (Either Status [a])
gitlab Text
boardsAddr
where
boardsAddr :: Text
boardsAddr :: Text
boardsAddr =
Text
"/projects/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/lists"
boardList ::
Project ->
IssueBoard ->
Int ->
GitLab (Maybe BoardIssue)
boardList :: Project -> IssueBoard -> Int -> GitLab (Maybe BoardIssue)
boardList Project
project IssueBoard
board Int
listId = do
Either Status (Maybe BoardIssue)
result <- Int -> Int -> Int -> GitLab (Either Status (Maybe BoardIssue))
boardList' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board) Int
listId
Maybe BoardIssue -> GitLab (Maybe BoardIssue)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe BoardIssue
-> Either Status (Maybe BoardIssue) -> Maybe BoardIssue
forall b a. b -> Either a b -> b
fromRight Maybe BoardIssue
forall a. Maybe a
Nothing Either Status (Maybe BoardIssue)
result)
boardList' ::
Int ->
Int ->
Int ->
GitLab (Either Status (Maybe BoardIssue))
boardList' :: Int -> Int -> Int -> GitLab (Either Status (Maybe BoardIssue))
boardList' Int
projectId Int
boardId Int
listId =
Text -> GitLab (Either Status (Maybe BoardIssue))
forall a. FromJSON a => Text -> GitLab (Either Status (Maybe a))
gitlabOne Text
boardsAddr
where
boardsAddr :: Text
boardsAddr :: Text
boardsAddr =
Text
"/projects/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/lists/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
listId)
createBoardList ::
Project ->
IssueBoard ->
CreateBoardAttrs ->
GitLab (Maybe BoardIssue)
createBoardList :: Project
-> IssueBoard -> CreateBoardAttrs -> GitLab (Maybe BoardIssue)
createBoardList Project
project IssueBoard
board CreateBoardAttrs
attrs = do
Either Status (Maybe BoardIssue)
result <- Int
-> Int
-> CreateBoardAttrs
-> GitLab (Either Status (Maybe BoardIssue))
createBoardList' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board) CreateBoardAttrs
attrs
Maybe BoardIssue -> GitLab (Maybe BoardIssue)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe BoardIssue
-> Either Status (Maybe BoardIssue) -> Maybe BoardIssue
forall b a. b -> Either a b -> b
fromRight Maybe BoardIssue
forall a. Maybe a
Nothing Either Status (Maybe BoardIssue)
result)
createBoardList' ::
Int ->
Int ->
CreateBoardAttrs ->
GitLab (Either Status (Maybe BoardIssue))
createBoardList' :: Int
-> Int
-> CreateBoardAttrs
-> GitLab (Either Status (Maybe BoardIssue))
createBoardList' Int
projectId Int
boardId CreateBoardAttrs
attrs =
Text -> Text -> GitLab (Either Status (Maybe BoardIssue))
forall b.
FromJSON b =>
Text -> Text -> GitLab (Either Status (Maybe b))
gitlabPost Text
boardsAddr Text
T.empty
where
boardsAddr :: Text
boardsAddr :: Text
boardsAddr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/lists"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (CreateBoardAttrs -> String
createBoardAttrs CreateBoardAttrs
attrs)
reorderBoardList ::
Project ->
IssueBoard ->
Int ->
Int ->
GitLab (Either Status (Maybe BoardIssue))
reorderBoardList :: Project
-> IssueBoard
-> Int
-> Int
-> GitLab (Either Status (Maybe BoardIssue))
reorderBoardList Project
project IssueBoard
board =
Int
-> Int -> Int -> Int -> GitLab (Either Status (Maybe BoardIssue))
reorderBoardList' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board)
reorderBoardList' ::
Int ->
Int ->
Int ->
Int ->
GitLab (Either Status (Maybe BoardIssue))
reorderBoardList' :: Int
-> Int -> Int -> Int -> GitLab (Either Status (Maybe BoardIssue))
reorderBoardList' Int
projectId Int
boardId Int
listId Int
newPosition =
Text -> Text -> GitLab (Either Status (Maybe BoardIssue))
forall b. FromJSON b => Text -> Text -> GitLab (Either Status b)
gitlabPut Text
boardsAddr Text
T.empty
where
boardsAddr :: Text
boardsAddr :: Text
boardsAddr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/lists/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
listId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (String
"?position=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
newPosition)
deleteBoardList ::
Project ->
IssueBoard ->
Int ->
GitLab (Either Status ())
deleteBoardList :: Project -> IssueBoard -> Int -> GitLab (Either Status ())
deleteBoardList Project
project IssueBoard
board =
Int -> Int -> Int -> GitLab (Either Status ())
deleteBoardList' (Project -> Int
project_id Project
project) (IssueBoard -> Int
board_id IssueBoard
board)
deleteBoardList' ::
Int ->
Int ->
Int ->
GitLab (Either Status ())
deleteBoardList' :: Int -> Int -> Int -> GitLab (Either Status ())
deleteBoardList' Int
projectId Int
boardId Int
listId =
Text -> GitLab (Either Status ())
gitlabDelete Text
boardsAddr
where
boardsAddr :: Text
boardsAddr :: Text
boardsAddr =
Text
"/projects/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
projectId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/boards/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
boardId)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/lists/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
listId)
data UpdateBoardAttrs = UpdateBoardAttrs
{ UpdateBoardAttrs -> Maybe String
updateBoard_new_name :: Maybe String,
UpdateBoardAttrs -> Maybe Int
updateBoard_assignee_id :: Maybe Int,
UpdateBoardAttrs -> Maybe Int
updateBoard_milestone_id :: Maybe Int,
UpdateBoardAttrs -> Maybe String
updateBoard_labels :: Maybe String,
UpdateBoardAttrs -> Maybe Int
updateBoard_weight :: Maybe Int
}
noUpdateBoardAttrs :: UpdateBoardAttrs
noUpdateBoardAttrs :: UpdateBoardAttrs
noUpdateBoardAttrs =
Maybe String
-> Maybe Int
-> Maybe Int
-> Maybe String
-> Maybe Int
-> UpdateBoardAttrs
UpdateBoardAttrs Maybe String
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing
updateBoardAttrs :: UpdateBoardAttrs -> String
updateBoardAttrs :: UpdateBoardAttrs -> String
updateBoardAttrs UpdateBoardAttrs
attrs =
case [String]
attrsUrl of
[] -> String
""
(String
x : [String]
xs) -> String
"?" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
x String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (String -> String) -> [String] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Char
'&' Char -> String -> String
forall a. a -> [a] -> [a]
:) [String]
xs
where
attrsUrl :: [String]
attrsUrl =
[Maybe String] -> [String]
forall a. [Maybe a] -> [a]
catMaybes
[ (\String
s -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"name=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
s)) (String -> Maybe String) -> Maybe String -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UpdateBoardAttrs -> Maybe String
updateBoard_new_name UpdateBoardAttrs
attrs,
(\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"assignee_id=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UpdateBoardAttrs -> Maybe Int
updateBoard_assignee_id UpdateBoardAttrs
attrs,
(\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"milestone_id=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UpdateBoardAttrs -> Maybe Int
updateBoard_milestone_id UpdateBoardAttrs
attrs,
(\String
s -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"labels=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
s)) (String -> Maybe String) -> Maybe String -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UpdateBoardAttrs -> Maybe String
updateBoard_labels UpdateBoardAttrs
attrs,
(\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"weight=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UpdateBoardAttrs -> Maybe Int
updateBoard_weight UpdateBoardAttrs
attrs
]
data CreateBoardAttrs = CreateBoardAttrs
{ CreateBoardAttrs -> Maybe Int
createBoard_label_id :: Maybe Int,
CreateBoardAttrs -> Maybe Int
createBoard_assignee_id :: Maybe Int,
CreateBoardAttrs -> Maybe Int
createBoard_milestone_id :: Maybe Int
}
noCreateBoardAttrs :: CreateBoardAttrs
noCreateBoardAttrs :: CreateBoardAttrs
noCreateBoardAttrs =
Maybe Int -> Maybe Int -> Maybe Int -> CreateBoardAttrs
CreateBoardAttrs Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing
createBoardAttrs :: CreateBoardAttrs -> String
createBoardAttrs :: CreateBoardAttrs -> String
createBoardAttrs CreateBoardAttrs
attrs =
case [String]
attrsUrl of
[] -> String
""
(String
x : [String]
xs) -> String
"?" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
x String -> String -> String
forall a. Semigroup a => a -> a -> a
<> (String -> String) -> [String] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Char
'&' Char -> String -> String
forall a. a -> [a] -> [a]
:) [String]
xs
where
attrsUrl :: [String]
attrsUrl =
[Maybe String] -> [String]
forall a. [Maybe a] -> [a]
catMaybes
[ (\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"label_id=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CreateBoardAttrs -> Maybe Int
createBoard_label_id CreateBoardAttrs
attrs,
(\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"assignee_id=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CreateBoardAttrs -> Maybe Int
createBoard_assignee_id CreateBoardAttrs
attrs,
(\Int
i -> String -> Maybe String
forall a. a -> Maybe a
Just (String
"milestone_id=" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
i)) (Int -> Maybe String) -> Maybe Int -> Maybe String
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< CreateBoardAttrs -> Maybe Int
createBoard_milestone_id CreateBoardAttrs
attrs
]