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 Commits class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/git/commits/
16 *
17 * @since 11.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageDataCommits extends JGithubPackage
21 {
22 /**
23 * Get a single commit.
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 commit SHA.
28 *
29 * @return object
30 */
31 public function get($owner, $repo, $sha)
32 {
33 // Build the request path.
34 $path = '/repos/' . $owner . '/' . $repo . '/git/commits/' . $sha;
35
36 return $this->processResponse(
37 $this->client->get($this->fetchUrl($path))
38 );
39 }
40
41 /**
42 * Method to create a commit.
43 *
44 * @param string $owner The name of the owner of the GitHub repository.
45 * @param string $repo The name of the GitHub repository.
46 * @param string $message The commit message.
47 * @param string $tree SHA of the tree object this commit points to.
48 * @param array $parents Array of the SHAs of the commits that were the parents of this commit.
49 * If omitted or empty, the commit will be written as a root commit.
50 * For a single parent, an array of one SHA should be provided.
51 * For a merge commit, an array of more than one should be provided.
52 *
53 * @throws DomainException
54 * @since 12.1
55 *
56 * @return object
57 */
58 public function create($owner, $repo, $message, $tree, array $parents = array())
59 {
60 // Build the request path.
61 $path = '/repos/' . $owner . '/' . $repo . '/git/commits';
62
63 $data = json_encode(
64 array('message' => $message, 'tree' => $tree, 'parents' => $parents)
65 );
66
67 // Send the request.
68 return $this->processResponse(
69 $response = $this->client->post($this->fetchUrl($path), $data),
70 201
71 );
72 }
73 }
74