1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * GitHub API Data Trees class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/git/trees/
16 *
17 * @since 11.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageDataTrees extends JGithubPackage
21 {
22 /**
23 * Get a Tree
24 *
25 * @param string $owner The name of the owner of the GitHub repository.
26 * @param string $repo The name of the GitHub repository.
27 * @param string $sha The SHA1 value to set the reference to.
28 *
29 * @since 3.3 (CMS)
30 *
31 * @return object
32 */
33 public function get($owner, $repo, $sha)
34 {
35 // Build the request path.
36 $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha;
37
38 return $this->processResponse(
39 $this->client->get($this->fetchUrl($path))
40 );
41 }
42
43 /**
44 * Get a Tree Recursively
45 *
46 * @param string $owner The name of the owner of the GitHub repository.
47 * @param string $repo The name of the GitHub repository.
48 * @param string $sha The SHA1 value to set the reference to.
49 *
50 * @since 3.3 (CMS)
51 *
52 * @return object
53 */
54 public function getRecursively($owner, $repo, $sha)
55 {
56 // Build the request path.
57 $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha . '?recursive=1';
58
59 return $this->processResponse(
60 $this->client->get($this->fetchUrl($path))
61 );
62 }
63
64 /**
65 * Create a Tree.
66 *
67 * The tree creation API will take nested entries as well. If both a tree and a nested path
68 * modifying that tree are specified, it will overwrite the contents of that tree with the
69 * new path contents and write a new tree out.
70 *
71 * Parameters fir the tree:
72 *
73 * tree.path
74 * String of the file referenced in the tree
75 * tree.mode
76 * String of the file mode - one of 100644 for file (blob), 100755 for executable (blob),
77 * 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob
78 * that specifies the path of a symlink
79 * tree.type
80 * String of blob, tree, commit
81 * tree.sha
82 * String of SHA1 checksum ID of the object in the tree
83 * tree.content
84 * String of content you want this file to have - GitHub will write this blob out and use
85 * that SHA for this entry. Use either this or tree.sha
86 *
87 * @param string $owner The name of the owner of the GitHub repository.
88 * @param string $repo The name of the GitHub repository.
89 * @param array $tree Array of Hash objects (of path, mode, type and sha) specifying
90 * a tree structure
91 * @param string $base_tree The SHA1 of the tree you want to update with new data.
92 *
93 * @since 3.3 (CMS)
94 *
95 * @return object
96 */
97 public function create($owner, $repo, $tree, $base_tree = '')
98 {
99 // Build the request path.
100 $path = '/repos/' . $owner . '/' . $repo . '/git/trees';
101
102 $data = array();
103
104 $data['tree'] = $tree;
105
106 if ($base_tree)
107 {
108 $data['base_tree'] = $base_tree;
109 }
110
111 return $this->processResponse(
112 $this->client->post($this->fetchUrl($path), json_encode($data)),
113 201
114 );
115 }
116 }
117