Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add endpoint new tree
  • Loading branch information
rvlander committed Aug 25, 2019
commit eef27826eb15c22dd754a3b54c0a85c062a5dd4c
26 changes: 26 additions & 0 deletions src/GitHub/Data/GitData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ data GitTree = GitTree
instance NFData GitTree where rnf = genericRnf
instance Binary GitTree

data NewTree = NewTree
{ newBaseTree :: !(Name Tree)
, newTreeGitTrees :: !(Vector NewGitTree)
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance NFData NewTree where rnf = genericRnf
instance Binary NewTree

data NewGitTree = NewGitTree
{ newGitTreePath :: !Text
, newGitTreeMode :: !Text
, newGitTreeContent :: !Text
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance NFData NewGitTree where rnf = genericRnf
instance Binary NewGitTree

data GitCommit = GitCommit
{ gitCommitMessage :: !Text
, gitCommitUrl :: !URL
Expand Down Expand Up @@ -233,6 +252,13 @@ instance FromJSON GitTree where
<*> o .: "path"
<*> o .: "mode"


instance ToJSON NewTree where
toJSON (NewTree b tree) = object [ "base_tree" .= b, "tree" .= tree ]

instance ToJSON NewGitTree where
toJSON (NewGitTree path mode content) = object [ "path" .= path, "mode" .= mode, "content" .= content ]

instance FromJSON GitCommit where
parseJSON = withObject "GitCommit" $ \o -> GitCommit
<$> o .: "message"
Expand Down
13 changes: 13 additions & 0 deletions src/GitHub/Endpoints/GitData/Trees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module GitHub.Endpoints.GitData.Trees (
nestedTree,
nestedTree',
nestedTreeR,
createTree,
createTreeR,
module GitHub.Data,
) where

Expand Down Expand Up @@ -57,3 +59,14 @@ nestedTree = nestedTree' Nothing
nestedTreeR :: Name Owner -> Name Repo -> Name Tree -> Request k Tree
nestedTreeR user repo sha =
query ["repos", toPathPart user, toPathPart repo, "git", "trees", toPathPart sha] [("recursive", Just "1")]

-- | Create a tree.
createTree :: Auth -> Name Owner -> Name Repo -> NewTree -> IO (Either Error Tree)
createTree auth user repo newTree =
executeRequest auth $ createTreeR user repo newTree

-- | Create a teference.
-- See <https://developer.github.com/v3/git/refs/#create-a-reference>
createTreeR :: Name Owner -> Name Repo -> NewTree -> Request 'RW Tree
createTreeR user repo newTree =
command Post ["repos", toPathPart user, toPathPart repo , "git", "trees"] (encode newTree)