|
1
|
|
|
<?php |
|
2
|
|
|
namespace FlexyProject\GitHub\Receiver\Repositories; |
|
3
|
|
|
|
|
4
|
|
|
use FlexyProject\GitHub\AbstractApi; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* The Commits API class provides access to repository's commits. |
|
8
|
|
|
* |
|
9
|
|
|
* @link https://developer.github.com/v3/repos/commits/ |
|
10
|
|
|
* @package FlexyProject\GitHub\Receiver\Repositories |
|
11
|
|
|
*/ |
|
12
|
|
|
class Commits extends AbstractRepositories |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* List commits on a repository |
|
17
|
|
|
* |
|
18
|
|
|
* @link https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $sha |
|
21
|
|
|
* @param string|null $path |
|
22
|
|
|
* @param string|null $author |
|
23
|
|
|
* @param string|null $since |
|
24
|
|
|
* @param string|null $until |
|
25
|
|
|
* |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
|
View Code Duplication |
public function listCommits(string $sha = AbstractApi::BRANCH_MASTER, string $path = null, string $author = null, |
|
|
|
|
|
|
29
|
|
|
string $since = null, string $until = null): array |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits?:args', |
|
32
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), http_build_query([ |
|
33
|
|
|
"sha" => $sha, |
|
34
|
|
|
"path" => $path, |
|
35
|
|
|
"author" => $author, |
|
36
|
|
|
"since" => $since, |
|
37
|
|
|
"until" => $until |
|
38
|
|
|
]))); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get a single commit |
|
43
|
|
|
* |
|
44
|
|
|
* @link https://developer.github.com/v3/repos/commits/#get-a-single-commit |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $sha |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getSingleCommit(string $sha): array |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:sha', |
|
53
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $sha)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Compare two commits |
|
58
|
|
|
* |
|
59
|
|
|
* @link https://developer.github.com/v3/repos/commits/#compare-two-commits |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $base |
|
62
|
|
|
* @param string $head |
|
63
|
|
|
* |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function compareTwoCommits(string $base, string $head): array |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/compare/:base...:head', |
|
69
|
|
|
$this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $base, $head)); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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.