Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Added Tree API functionality #109

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
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
38 changes: 38 additions & 0 deletions gitea/tree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package gitea

import (
"fmt"
)

// TreeEntry represents the subtree structure within a tree.
type GitTreeEntry struct {
Path string `json:"path"`
Mode string `json:"mode"`
Type string `json:"type"`
Size int64 `json:"size,omitempty"`
SHA string `json:"sha"`
URL string `json:"url"`
}

// Tree represents the tree structure.
type GitTreeResponse struct {
SHA string `json:"sha"`
URL string `json:"url"`
Entries []GitTreeEntry `json:"tree,omitempty"`
Truncated bool `json:"truncated"`
}

// GetTree gets information on a tree given the owner, repo, and sha or ref.
func (c *Client) GetTree(user string, repo string, tree string, recursive bool) (*GitTreeResponse, error) {
t := new(GitTreeResponse)
var Path = fmt.Sprintf("/repos/%s/%s/trees/%s", user, repo, tree)
if recursive {
Path += "?recursive=1"
}
err := c.getParsedResponse("GET", Path, nil, nil, t)
return t, err
}