From a9116696c05ac09c90869e13faa0995ad607fcaa Mon Sep 17 00:00:00 2001 From: Kasi Date: Sun, 10 Jun 2018 19:08:31 +0100 Subject: [PATCH 1/2] Added Tree API functionality --- gitea/tree.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 gitea/tree.go diff --git a/gitea/tree.go b/gitea/tree.go new file mode 100644 index 0000000..85a081f --- /dev/null +++ b/gitea/tree.go @@ -0,0 +1,39 @@ +// 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 TreeEntry 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 Tree struct { + SHA string `json:"sha"` + URL string `json:"url"` + Entries []TreeEntry `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) (*Tree, error) { + t := new(Tree) + 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 +} + From 6f4435902540a8f58c9b7eedbce5df9ba9aa8241 Mon Sep 17 00:00:00 2001 From: Kasi Date: Wed, 13 Jun 2018 11:10:15 +0100 Subject: [PATCH 2/2] Renamed Tree structures --- gitea/tree.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gitea/tree.go b/gitea/tree.go index 85a081f..e6d7fa4 100644 --- a/gitea/tree.go +++ b/gitea/tree.go @@ -9,7 +9,7 @@ import ( ) // TreeEntry represents the subtree structure within a tree. -type TreeEntry struct { +type GitTreeEntry struct { Path string `json:"path"` Mode string `json:"mode"` Type string `json:"type"` @@ -19,16 +19,16 @@ type TreeEntry struct { } // Tree represents the tree structure. -type Tree struct { +type GitTreeResponse struct { SHA string `json:"sha"` URL string `json:"url"` - Entries []TreeEntry `json:"tree,omitempty"` + 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) (*Tree, error) { - t := new(Tree) +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" @@ -36,4 +36,3 @@ func (c *Client) GetTree(user string, repo string, tree string, recursive bool) err := c.getParsedResponse("GET", Path, nil, nil, t) return t, err } -