{-# LANGUAGE OverloadedStrings #-}
module GitLab.API.Commits where
import qualified Data.ByteString.Lazy as BSL
import Data.Either
import Data.Text (Text)
import qualified Data.Text as T
import GitLab.Types
import GitLab.WebRequests.GitLabWebCalls
import Network.HTTP.Client
projectCommits ::
Project ->
GitLab [Commit]
projectCommits :: Project -> GitLab [Commit]
projectCommits Project
project = do
Either (Response ByteString) [Commit]
result <- Int -> GitLab (Either (Response ByteString) [Commit])
projectCommits' (Project -> Int
project_id Project
project)
[Commit] -> GitLab [Commit]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Commit] -> Either (Response ByteString) [Commit] -> [Commit]
forall b a. b -> Either a b -> b
fromRight [] Either (Response ByteString) [Commit]
result)
projectCommits' ::
Int ->
GitLab (Either (Response BSL.ByteString) [Commit])
projectCommits' :: Int -> GitLab (Either (Response ByteString) [Commit])
projectCommits' Int
projectId =
Text -> Text -> GitLab (Either (Response ByteString) [Commit])
forall a.
FromJSON a =>
Text -> Text -> GitLab (Either (Response ByteString) [a])
gitlabWithAttrs (Int -> Text
commitsAddr Int
projectId) Text
"&with_stats=true"
where
commitsAddr :: Int -> Text
commitsAddr :: Int -> Text
commitsAddr 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
"/repository" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/commits"
branchCommits ::
Project ->
Text ->
GitLab [Commit]
branchCommits :: Project -> Text -> GitLab [Commit]
branchCommits Project
project Text
branchName = do
Either (Response ByteString) [Commit]
result <- Int -> Text -> GitLab (Either (Response ByteString) [Commit])
branchCommits' (Project -> Int
project_id Project
project) Text
branchName
[Commit] -> GitLab [Commit]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Commit] -> Either (Response ByteString) [Commit] -> [Commit]
forall b a. b -> Either a b -> b
fromRight [] Either (Response ByteString) [Commit]
result)
branchCommits' ::
Int ->
Text ->
GitLab (Either (Response BSL.ByteString) [Commit])
branchCommits' :: Int -> Text -> GitLab (Either (Response ByteString) [Commit])
branchCommits' Int
projectId Text
branchName = do
Text -> Text -> GitLab (Either (Response ByteString) [Commit])
forall a.
FromJSON a =>
Text -> Text -> GitLab (Either (Response ByteString) [a])
gitlabWithAttrs (Int -> Text
commitsAddr Int
projectId) (Text
"&ref_name=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
branchName)
where
commitsAddr :: Int -> Text
commitsAddr :: Int -> Text
commitsAddr 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
"/repository" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/commits"
commitDetails ::
Project ->
Text ->
GitLab (Maybe Commit)
commitDetails :: Project -> Text -> GitLab (Maybe Commit)
commitDetails Project
project Text
theHash = do
Either (Response ByteString) (Maybe Commit)
result <- Int -> Text -> GitLab (Either (Response ByteString) (Maybe Commit))
commitDetails' (Project -> Int
project_id Project
project) Text
theHash
Maybe Commit -> GitLab (Maybe Commit)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Commit
-> Either (Response ByteString) (Maybe Commit) -> Maybe Commit
forall b a. b -> Either a b -> b
fromRight Maybe Commit
forall a. Maybe a
Nothing Either (Response ByteString) (Maybe Commit)
result)
commitDetails' ::
Int ->
Text ->
GitLab (Either (Response BSL.ByteString) (Maybe Commit))
commitDetails' :: Int -> Text -> GitLab (Either (Response ByteString) (Maybe Commit))
commitDetails' Int
projectId Text
hash =
Text -> GitLab (Either (Response ByteString) (Maybe Commit))
forall a.
FromJSON a =>
Text -> GitLab (Either (Response ByteString) (Maybe a))
gitlabOne (Int -> Text
commitsAddr Int
projectId)
where
commitsAddr :: Int -> Text
commitsAddr :: Int -> Text
commitsAddr 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
"/repository"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/commits"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"/"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
hash