statistics.php
4.83 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API class for the Joomla Platform.
*
* The Repository Statistics API allows you to fetch the data that GitHub uses for
* visualizing different types of repository activity.
*
* @documentation https://developer.github.com/v3/repos/statistics
*
* @since 3.3 (CMS)
* @deprecated 4.0 Use the `joomla/github` package via Composer instead
*/
class JGithubPackageRepositoriesStatistics extends JGithubPackage
{
/**
* Get contributors list with additions, deletions, and commit counts.
*
* Response include:
* total - The Total number of commits authored by the contributor.
*
* Weekly Hash
*
* w - Start of the week
* a - Number of additions
* d - Number of deletions
* c - Number of commits
*
* @param string $owner The owner of the repository.
* @param string $repo The repository name.
*
* @since 1.0
*
* @return object
*/
public function getListContributors($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/stats/contributors';
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
/**
* Get the last year of commit activity data.
*
* Returns the last year of commit activity grouped by week.
* The days array is a group of commits per day, starting on Sunday.
*
* @param string $owner The owner of the repository.
* @param string $repo The repository name.
*
* @since 1.0
*
* @return object
*/
public function getActivityData($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/stats/commit_activity';
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
/**
* Get the number of additions and deletions per week.
*
* Response returns a weekly aggregate of the number of additions and deletions pushed to a repository.
*
* @param string $owner The owner of the repository.
* @param string $repo The repository name.
*
* @since 1.0
*
* @return object
*/
public function getCodeFrequency($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/stats/code_frequency';
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
/**
* Get the weekly commit count for the repo owner and everyone else.
*
* Returns the total commit counts for the "owner" and total commit counts in "all". "all" is everyone combined,
* including the owner in the last 52 weeks.
* If you’d like to get the commit counts for non-owners, you can subtract all from owner.
*
* The array order is oldest week (index 0) to most recent week.
*
* @param string $owner The owner of the repository.
* @param string $repo The repository name.
*
* @since 1.0
*
* @return object
*/
public function getParticipation($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/stats/participation';
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
/**
* Get the number of commits per hour in each day.
*
* Response
* Each array contains the day number, hour number, and number of commits:
*
* 0-6: Sunday - Saturday
* 0-23: Hour of day
* Number of commits
*
* For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays.
* All times are based on the time zone of individual commits.
*
* @param string $owner The owner of the repository.
* @param string $repo The repository name.
*
* @since 1.0
*
* @return object
*/
public function getPunchCard($owner, $repo)
{
// Build the request path.
$path = '/repos/' . $owner . '/' . $repo . '/stats/punch_card';
// Send the request.
return $this->processResponse($this->client->get($this->fetchUrl($path)));
}
/**
* Process the response and decode it.
*
* @param JHttpResponse $response The response.
* @param integer $expectedCode The expected "good" code.
* @param boolean $decode If the should be response be JSON decoded.
*
* @return mixed
*
* @since 1.0
* @throws \DomainException
*/
protected function processResponse(JHttpResponse $response, $expectedCode = 200, $decode = true)
{
if (202 == $response->code)
{
throw new \DomainException(
'GitHub is building the statistics data. Please try again in a few moments.',
$response->code
);
}
return parent::processResponse($response, $expectedCode, $decode);
}
}