|
@@ -6,7 +6,7 @@ namespace Gogs\API\Request {
|
|
|
* Repos is a collection of repos.
|
|
|
*
|
|
|
* @author Joachim M. Giaever (joachim[]giaever.org)
|
|
|
- * @version 0.1.1
|
|
|
+ * @version 0.1.2
|
|
|
*/
|
|
|
final class Repos extends Collection {
|
|
|
|
|
@@ -53,6 +53,40 @@ namespace Gogs\API\Request {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Get a single repository by name.
|
|
|
+ *
|
|
|
+ * If the `owner` is set, the name can be just the
|
|
|
+ * actual name of the repo
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public function get(string $name) {
|
|
|
+
|
|
|
+ if (isset($this->owner) && strpos($name, "/") === false )
|
|
|
+ $name = sprintf("%s/%s", $this->owner->username, $name);
|
|
|
+
|
|
|
+ if ($repo = $this->by_key($name))
|
|
|
+ return $repo;
|
|
|
+
|
|
|
+ $owner = !empty($this->owner) ? $this->owner : (
|
|
|
+ ($pos = strpos($name, "/")) !== false ?
|
|
|
+ new User($this->url, $this->token, substr($name, 0, $pos)) : null
|
|
|
+ );
|
|
|
+
|
|
|
+ $repo = (new Repo(
|
|
|
+ $this->url,
|
|
|
+ $this->token,
|
|
|
+ $owner,
|
|
|
+ ($pos = strpos($name, "/")) ? substr($name, $pos + 1) : $name
|
|
|
+ ))->load();
|
|
|
+
|
|
|
+ $this->add($repo, $repo->full_name);
|
|
|
+
|
|
|
+ return $repo;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* @see Collection
|
|
|
*/
|