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