Repository navigation
Expand file tree
/
Copy pathCommit.php
More file actions
78 lines (62 loc) · 1.69 KB
/
Copy pathCommit.php
File metadata and controls
78 lines (62 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Github\Model;
class Commit extends AbstractModel
{
protected static $_properties = array(
'repo',
'url',
'sha',
'commit',
'author',
'committer',
'message',
'tree',
'parents',
'files',
'stats',
'comments_url'
);
public static function factory(Repo $repo, $sha)
{
return new Commit($repo, $sha);
}
public static function fromArray(Repo $repo, array $data)
{
$commit = Commit::factory($repo, $data['sha']);
if (isset($data['author'])) {
$data['author'] = User::fromArray($data['author']);
}
if (isset($data['committer'])) {
$data['committer'] = User::fromArray($data['committer']);
}
if (isset($data['tree'])) {
}
if (isset($data['commit'])) {
// Bit hacky but oh well, consistent..
// TODO: Improve
$data['commit'] = json_decode(json_encode($data['commit']));
}
if (isset($data['parents'])) {
$parents = array();
foreach ($data['parents'] as $parent) {
$parents[] = Commit::fromArray($repo, $parent);
}
$data['parents'] = $parents;
}
return $commit->hydrate($data);
}
public function __construct(Repo $repo, $sha)
{
$this->repo = $repo;
$this->sha = $sha;
}
public function show()
{
$data = $this->api('git_data')->commits()->show(
$this->repo->owner->login,
$this->repo->name,
$this->sha
);
return Commit::fromArray($this->repo, $data);
}
}