1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Github Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package\Data; |
10
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* GitHub API Data Commits class for the Joomla Framework. |
15
|
|
|
* |
16
|
|
|
* @documentation http://developer.github.com/v3/git/commits/ |
17
|
|
|
* |
18
|
|
|
* @since 1.0 |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class Commits extends AbstractPackage |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Get a 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
|
|
|
* 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
|
|
|
* @since 1.0 |
54
|
|
|
* |
55
|
|
|
* @return object |
56
|
|
|
*/ |
57
|
|
|
public function create($owner, $repo, $message, $tree, array $parents = array()) |
58
|
|
|
{ |
59
|
|
|
// Build the request path. |
60
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/git/commits'; |
61
|
|
|
|
62
|
|
|
$data = json_encode( |
63
|
|
|
array('message' => $message, 'tree' => $tree, 'parents' => $parents) |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
// Send the request. |
67
|
|
|
return $this->processResponse( |
68
|
|
|
$response = $this->client->post($this->fetchUrl($path), $data), |
69
|
|
|
201 |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.