@@ -14,6 +14,13 @@ const (
1414 repo_url_raw_file = "/projects/:id/repository/blobs/:sha" // Get raw file content for specific commit/branch
1515)
1616
17+ type TreeNode struct {
18+ Name string
19+ Type string
20+ Mode string
21+ Id string
22+ }
23+
1724type BranchCommit struct {
1825 Id string `json:"id,omitempty"`
1926 Tree string `json:"tree,omitempty"`
@@ -52,6 +59,36 @@ type Commit struct {
5259 CreatedAt time.Time
5360}
5461
62+ /*
63+ Get a list of repository files and directories in a project.
64+
65+ GET /projects/:id/repository/tree
66+
67+ Parameters:
68+
69+ id (required) The ID of a project
70+ path (optional) The path inside repository. Used to get contend of subdirectories
71+ ref_name (optional) The name of a repository branch or tag or if not given the default branch
72+
73+ Usage:
74+ pass nil when not using optional parameters
75+ */
76+ func (g * Gitlab ) RepoTree (id , path , ref_name string ) ([]* TreeNode , error ) {
77+
78+ url , opaque := g .ResourceUrlRaw (repo_url_tree , map [string ]string {":id" : id })
79+ url += "&path=" + path
80+ url += "&ref_name=" + ref_name
81+
82+ var treeNodes []* TreeNode
83+
84+ contents , err := g .buildAndExecRequestRaw ("GET" , url , opaque , nil )
85+ if err == nil {
86+ err = json .Unmarshal (contents , & treeNodes )
87+ }
88+
89+ return treeNodes , err
90+ }
91+
5592/*
5693Get a list of repository branches from a project, sorted by name alphabetically.
5794
0 commit comments