|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Part of the Joomla Framework Github Package |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (C) 2005 - 2018 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\Repositories; |
|
10
|
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
|
12
|
|
|
use Joomla\Http\Response; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* GitHub API class for the Joomla Framework. |
|
16
|
|
|
* |
|
17
|
|
|
* The Repository Statistics API allows you to fetch the data that GitHub uses for |
|
18
|
|
|
* visualizing different types of repository activity. |
|
19
|
|
|
* |
|
20
|
|
|
* @link https://developer.github.com/v3/repos/statistics |
|
21
|
|
|
* |
|
22
|
|
|
* @since 1.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
class Statistics extends AbstractPackage |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Get contributors list with additions, deletions, and commit counts. |
|
28
|
|
|
* |
|
29
|
|
|
* Response include: |
|
30
|
|
|
* total - The Total number of commits authored by the contributor. |
|
31
|
|
|
* |
|
32
|
|
|
* Weekly Hash |
|
33
|
|
|
* |
|
34
|
|
|
* w - Start of the week |
|
35
|
|
|
* a - Number of additions |
|
36
|
|
|
* d - Number of deletions |
|
37
|
|
|
* c - Number of commits |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $owner The owner of the repository. |
|
40
|
|
|
* @param string $repo The repository name. |
|
41
|
|
|
* |
|
42
|
|
|
* @return object |
|
43
|
|
|
* |
|
44
|
|
|
* @since 1.0 |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getListContributors($owner, $repo) |
|
47
|
|
|
{ |
|
48
|
|
|
// Build the request path. |
|
49
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/stats/contributors'; |
|
50
|
|
|
|
|
51
|
|
|
// Send the request. |
|
52
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the last year of commit activity data. |
|
57
|
|
|
* |
|
58
|
|
|
* Returns the last year of commit activity grouped by week. |
|
59
|
|
|
* The days array is a group of commits per day, starting on Sunday. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $owner The owner of the repository. |
|
62
|
|
|
* @param string $repo The repository name. |
|
63
|
|
|
* |
|
64
|
|
|
* @return object |
|
65
|
|
|
* |
|
66
|
|
|
* @since 1.0 |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getActivityData($owner, $repo) |
|
69
|
|
|
{ |
|
70
|
|
|
// Build the request path. |
|
71
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/stats/commit_activity'; |
|
72
|
|
|
|
|
73
|
|
|
// Send the request. |
|
74
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get the number of additions and deletions per week. |
|
79
|
|
|
* |
|
80
|
|
|
* Response returns a weekly aggregate of the number of additions and deletions pushed to a repository. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $owner The owner of the repository. |
|
83
|
|
|
* @param string $repo The repository name. |
|
84
|
|
|
* |
|
85
|
|
|
* @return object |
|
86
|
|
|
* |
|
87
|
|
|
* @since 1.0 |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getCodeFrequency($owner, $repo) |
|
90
|
|
|
{ |
|
91
|
|
|
// Build the request path. |
|
92
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/stats/code_frequency'; |
|
93
|
|
|
|
|
94
|
|
|
// Send the request. |
|
95
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get the weekly commit count for the repository owner and everyone else. |
|
100
|
|
|
* |
|
101
|
|
|
* Returns the total commit counts for the "owner" and total commit counts in "all". "all" is everyone combined, |
|
102
|
|
|
* including the owner in the last 52 weeks. |
|
103
|
|
|
* If you’d like to get the commit counts for non-owners, you can subtract all from owner. |
|
104
|
|
|
* |
|
105
|
|
|
* The array order is oldest week (index 0) to most recent week. |
|
106
|
|
|
* |
|
107
|
|
|
* @param string $owner The owner of the repository. |
|
108
|
|
|
* @param string $repo The repository name. |
|
109
|
|
|
* |
|
110
|
|
|
* @return object |
|
111
|
|
|
* |
|
112
|
|
|
* @since 1.0 |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getParticipation($owner, $repo) |
|
115
|
|
|
{ |
|
116
|
|
|
// Build the request path. |
|
117
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/stats/participation'; |
|
118
|
|
|
|
|
119
|
|
|
// Send the request. |
|
120
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the number of commits per hour in each day. |
|
125
|
|
|
* |
|
126
|
|
|
* Response |
|
127
|
|
|
* Each array contains the day number, hour number, and number of commits: |
|
128
|
|
|
* |
|
129
|
|
|
* 0-6: Sunday - Saturday |
|
130
|
|
|
* 0-23: Hour of day |
|
131
|
|
|
* Number of commits |
|
132
|
|
|
* |
|
133
|
|
|
* For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. |
|
134
|
|
|
* All times are based on the time zone of individual commits. |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $owner The owner of the repository. |
|
137
|
|
|
* @param string $repo The repository name. |
|
138
|
|
|
* |
|
139
|
|
|
* @return object |
|
140
|
|
|
* |
|
141
|
|
|
* @since 1.0 |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getPunchCard($owner, $repo) |
|
144
|
|
|
{ |
|
145
|
|
|
// Build the request path. |
|
146
|
|
|
$path = '/repos/' . $owner . '/' . $repo . '/stats/punch_card'; |
|
147
|
|
|
|
|
148
|
|
|
// Send the request. |
|
149
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Process the response and decode it. |
|
154
|
|
|
* |
|
155
|
|
|
* @param Response $response The response. |
|
156
|
|
|
* @param integer $expectedCode The expected "good" code. |
|
157
|
|
|
* |
|
158
|
|
|
* @return mixed |
|
159
|
|
|
* |
|
160
|
|
|
* @since 1.0 |
|
161
|
|
|
* @throws \DomainException |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function processResponse(Response $response, $expectedCode = 200) |
|
164
|
|
|
{ |
|
165
|
|
|
if (202 == $response->code) |
|
166
|
|
|
{ |
|
167
|
|
|
throw new \DomainException( |
|
168
|
|
|
'GitHub is building the statistics data. Please try again in a few moments.', |
|
169
|
|
|
$response->code |
|
170
|
|
|
); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
return parent::processResponse($response, $expectedCode); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|