11<?php
22
3- /*
3+ /**
44 * This file is part of the bitbucket-api package.
55 *
66 * (c) Alexandru G. <alex@gentle.ro>
1212namespace Bitbucket \API \Repositories ;
1313
1414use Bitbucket \API ;
15+ use Buzz \Message \MessageInterface ;
1516
1617/**
17- * Repository class
18- *
1918 * Allows you to create a new repository or edit a specific one.
2019 *
2120 * @author Alexandru G. <alex@gentle.ro>
2221 */
2322class Repository extends API \Api
2423{
24+ /**
25+ * Get information associated with an individual repository.
26+ *
27+ * @access public
28+ * @param string $account The team or individual account owning the repository.
29+ * @param string $repo The repository identifier.
30+ * @return MessageInterface
31+ */
32+ public function get ($ account , $ repo )
33+ {
34+ return $ this ->getClient ()->setApiVersion ('2.0 ' )->get (
35+ sprintf ('repositories/%s/%s ' , $ account , $ repo )
36+ );
37+ }
38+
39+ /**
40+ * Create a new repository
41+ *
42+ * If `$params` are omitted, a private git repository will be created,
43+ * with a "no forking" policy.
44+ *
45+ * @access public
46+ * @param string $account The team or individual account owning the repository.
47+ * @param string $repo The repository identifier.
48+ * @param array $params Additional parameters
49+ * @return MessageInterface
50+ *
51+ * @see https://confluence.atlassian.com/x/WwZAGQ
52+ */
53+ public function create ($ account , $ repo , $ params = array ())
54+ {
55+ // Keep BC for now.
56+ // @todo[1]: to be removed.
57+ if (is_array ($ repo )) {
58+ return $ this ->createLegacy ($ account , $ repo );
59+ }
60+
61+ // allow developer to directly specify params as json if (s)he wants.
62+ if (!empty ($ params ) && is_array ($ params )) {
63+ $ params = json_encode (array_merge (
64+ array (
65+ 'scm ' => 'git ' ,
66+ 'name ' => $ repo ,
67+ 'is_private ' => true ,
68+ 'description ' => 'My secret repo ' ,
69+ 'forking_policy ' => 'no_forks ' ,
70+ ),
71+ $ params
72+ ));
73+ }
74+
75+ return $ this ->getClient ()->setApiVersion ('2.0 ' )->post (
76+ sprintf ('repositories/%s/%s ' , $ account , $ repo ),
77+ $ params ,
78+ array ('Content-Type ' => 'application/json ' )
79+ );
80+ }
81+
2582 /**
2683 * Create a new repository
2784 *
@@ -38,8 +95,11 @@ class Repository extends API\Api
3895 * @param string $name The name of the repository
3996 * @param array $params Additional parameters
4097 * @return mixed
98+ *
99+ * @deprecated This API 1.0 endpoint is deprecated.
100+ * @see $this->create() Sintax for using API 2.0 endpoint
41101 */
42- public function create ($ name , array $ params = array ())
102+ private function createLegacy ($ name , array $ params = array ())
43103 {
44104 $ params ['name ' ] = $ name ;
45105
@@ -58,7 +118,7 @@ public function create($name, array $params = array())
58118 * @param array $params Additional parameters
59119 * @return mixed
60120 *
61- * @see https://confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-PUTarepositoryupdate
121+ * @see https://confluence.atlassian.com/x/WwZAGQ
62122 */
63123 public function update ($ account , $ repo , array $ params = array ())
64124 {
@@ -72,17 +132,47 @@ public function update($account, $repo, array $params = array())
72132 * Delete a repository
73133 *
74134 * @access public
75- * @param string $account The team or individual account owning the repository.
76- * @param string $repo The repository identifier.
77- * @return mixed
135+ * @param string $account The team or individual account owning the repository.
136+ * @param string $repo The repository identifier.
137+ * @return MessageInterface
78138 */
79139 public function delete ($ account , $ repo )
80140 {
81- return $ this ->requestDelete (
141+ return $ this ->getClient ()-> setApiVersion ( ' 2.0 ' )-> delete (
82142 sprintf ('repositories/%s/%s ' , $ account , $ repo )
83143 );
84144 }
85145
146+ /**
147+ * Gets the list of accounts watching a repository.
148+ *
149+ * @access public
150+ * @param string $account The team or individual account owning the repository.
151+ * @param string $repo The repository identifier.
152+ * @return MessageInterface
153+ */
154+ public function watchers ($ account , $ repo )
155+ {
156+ return $ this ->getClient ()->setApiVersion ('2.0 ' )->get (
157+ sprintf ('repositories/%s/%s/watchers ' , $ account , $ repo )
158+ );
159+ }
160+
161+ /**
162+ * Gets the list of repository forks.
163+ *
164+ * @access public
165+ * @param string $account The team or individual account owning the repository.
166+ * @param string $repo The repository identifier.
167+ * @return MessageInterface
168+ */
169+ public function forks ($ account , $ repo )
170+ {
171+ return $ this ->getClient ()->setApiVersion ('2.0 ' )->get (
172+ sprintf ('repositories/%s/%s/forks ' , $ account , $ repo )
173+ );
174+ }
175+
86176 /**
87177 * Fork a repository
88178 *
0 commit comments