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 Repositories Collaborators class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/repos/collaborators
16 *
17 * @since 11.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageRepositoriesCollaborators extends JGithubPackage
21 {
22 /**
23 * List.
24 *
25 * When authenticating as an organization owner of an organization-owned repository, all organization
26 * owners are included in the list of collaborators. Otherwise, only users with access to the repository
27 * are returned in the collaborators list.
28 *
29 * @param string $owner The name of the owner of the GitHub repository.
30 * @param string $repo The name of the GitHub repository.
31 *
32 * @since 3.3 (CMS)
33 *
34 * @return object
35 */
36 public function getList($owner, $repo)
37 {
38 // Build the request path.
39 $path = '/repos/' . $owner . '/' . $repo . '/collaborators';
40
41 return $this->processResponse(
42 $this->client->get($this->fetchUrl($path))
43 );
44 }
45
46 /**
47 * Test if a user is a collaborator.
48 *
49 * @param string $owner The name of the owner of the GitHub repository.
50 * @param string $repo The name of the GitHub repository.
51 * @param string $user The name of the GitHub user.
52 *
53 * @throws UnexpectedValueException
54 * @since 3.3 (CMS)
55 *
56 * @return boolean
57 */
58 public function get($owner, $repo, $user)
59 {
60 // Build the request path.
61 $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
62
63 $response = $this->client->get($this->fetchUrl($path));
64
65 switch ($response->code)
66 {
67 case '204';
68
69 return true;
70 break;
71 case '404';
72
73 return false;
74 break;
75 default;
76 throw new UnexpectedValueException('Unexpected code: ' . $response->code);
77 break;
78 }
79 }
80
81 /**
82 * Add collaborator.
83 *
84 * @param string $owner The name of the owner of the GitHub repository.
85 * @param string $repo The name of the GitHub repository.
86 * @param string $user The name of the GitHub user.
87 *
88 * @since 3.3 (CMS)
89 *
90 * @return object
91 */
92 public function add($owner, $repo, $user)
93 {
94 // Build the request path.
95 $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
96
97 return $this->processResponse(
98 $this->client->put($this->fetchUrl($path), ''),
99 204
100 );
101 }
102
103 /**
104 * Remove collaborator.
105 *
106 * @param string $owner The name of the owner of the GitHub repository.
107 * @param string $repo The name of the GitHub repository.
108 * @param string $user The name of the GitHub user.
109 *
110 * @since 3.3 (CMS)
111 *
112 * @return object
113 */
114 public function remove($owner, $repo, $user)
115 {
116 // Build the request path.
117 $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
118
119 return $this->processResponse(
120 $this->client->delete($this->fetchUrl($path)),
121 204
122 );
123 }
124 }
125