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 References class for the Joomla Platform.
14 *
15 * @since 12.3
16 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
17 */
18 class JGithubStatuses extends JGithubObject
19 {
20 /**
21 * Method to create a status.
22 *
23 * @param string $user The name of the owner of the GitHub repository.
24 * @param string $repo The name of the GitHub repository.
25 * @param string $sha The SHA1 value for which to set the status.
26 * @param string $state The state (pending, success, error or failure).
27 * @param string $targetUrl Optional target URL.
28 * @param string $description Optional description for the status.
29 *
30 * @deprecated use repositories->statuses->create()
31 *
32 * @return object
33 *
34 * @since 12.3
35 */
36 public function create($user, $repo, $sha, $state, $targetUrl = null, $description = null)
37 {
38 // Build the request path.
39 $path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
40
41 if (!in_array($state, array('pending', 'success', 'error', 'failure')))
42 {
43 throw new InvalidArgumentException('State must be one of pending, success, error or failure.');
44 }
45
46 // Build the request data.
47 $data = array(
48 'state' => $state,
49 );
50
51 if (!is_null($targetUrl))
52 {
53 $data['target_url'] = $targetUrl;
54 }
55
56 if (!is_null($description))
57 {
58 $data['description'] = $description;
59 }
60
61 // Send the request.
62 $response = $this->client->post($this->fetchUrl($path), json_encode($data));
63
64 // Validate the response code.
65 if ($response->code != 201)
66 {
67 // Decode the error response and throw an exception.
68 $error = json_decode($response->body);
69 throw new DomainException($error->message, $response->code);
70 }
71
72 return json_decode($response->body);
73 }
74
75 /**
76 * Method to list statuses for an SHA.
77 *
78 * @param string $user The name of the owner of the GitHub repository.
79 * @param string $repo The name of the GitHub repository.
80 * @param string $sha SHA1 for which to get the statuses.
81 *
82 * @deprecated use repositories->statuses->getList()
83 *
84 * @return array
85 *
86 * @since 12.3
87 */
88 public function getList($user, $repo, $sha)
89 {
90 // Build the request path.
91 $path = '/repos/' . $user . '/' . $repo . '/statuses/' . $sha;
92
93 // Send the request.
94 $response = $this->client->get($this->fetchUrl($path));
95
96 // Validate the response code.
97 if ($response->code != 200)
98 {
99 // Decode the error response and throw an exception.
100 $error = json_decode($response->body);
101 throw new DomainException($error->message, $response->code);
102 }
103
104 return json_decode($response->body);
105 }
106 }
107