Skip to content

Commit

Permalink
Add GetRepoInfo() and SetRemote() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
netcarver committed Sep 29, 2019
1 parent ee01648 commit 834b108
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
9 changes: 9 additions & 0 deletions BitbucketRepositoryAdaptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public function GetInfo() {
}


public function SetRemote($remote) {

}


public function GetRepoInfo() {
return [];
}


/**
*
Expand Down
2 changes: 2 additions & 0 deletions GitRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public function GetTags();
public function GetCommits($startref, $endref='HEAD');
public function GetChangelog();
public function GetForks($sort);
public function GetRepoInfo();
public function SetRemote($remote);
}
41 changes: 34 additions & 7 deletions GithubRepositoryAdaptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public function GetInfo() {
}


public function SetRemote($remote) {
$m = [];
$ok = preg_match('~^https?://github.com/([^/]++)/(.++)~i', $remote, $m);
if ($ok) {
$this->remote = $remote;
$this->owner = $m[1];
$this->repo = $m[2];
$this->encoded_owner = rawurlencode($m[1]);
$this->encoded_repo = rawurlencode($m[2]);
}
return $ok;
}

/**
*
Expand All @@ -64,17 +76,15 @@ public function __construct($http, $remote, $application, array $options) {
} else {
throw new \Exception('Cache directory is needed.');
}
$ok = preg_match('~^https?://github.com/([^/]++)/(.++)~i', $remote, $m);
$ok = $this->setRemote($remote);
if ($ok) {
$this->headers['Accept'] = 'application/vnd.github.v3+json'; // As requested by the github v3 api documentation.
$this->headers['User-Agent'] = $application;
$this->http = $http;
$this->remote = $remote;
$this->owner = $m[1];
$this->repo = $m[2];
$this->encoded_owner = rawurlencode($m[1]);
$this->encoded_repo = rawurlencode($m[2]);
$this->GetTags();
if (!array_key_exists('no_tags', $options) || false === $options['no_tags']) {
$this->GetTags();
}

} else {
throw new \Exception('Invalid repository signature');
}
Expand Down Expand Up @@ -124,6 +134,22 @@ public function GetReleaseNotes($version=null) {
}


/**
*
*/
public function GetRepoInfo() {
if (null === $this->repo_info) {
$url = "https://api.github.com/repos/{$this->encoded_owner}/{$this->encoded_repo}";
$http_code = null;
$reply = $this->RepositoryRead($url, $http_code);
if (200 == $http_code || 304 == $http_code) {
$this->repo_info = $reply['body'];
}
}
return $this->repo_info;
}


/**
*
*/
Expand Down Expand Up @@ -229,6 +255,7 @@ public function GetChangelog() {




/**
*
*/
Expand Down

0 comments on commit 834b108

Please sign in to comment.