Compare commits

..

No commits in common. "master" and "develop" have entirely different histories.

4 changed files with 8 additions and 117 deletions

View File

@ -3,16 +3,10 @@ Simple PHP library to interface with Gitea API
Designed to make a "Bot" for manipulating labels and issues.
For usage examples see https://git.jhodges.co.uk/jhodges/GiteaBot-examples
For usage examples see https://git.jhodges.co.uk/james/GiteaBot-examples
## Change Log
V1.2.1
* Fixed #1 Added Repo::GetIssues()
* Fixed #2 Only POST changed data on save
* Updated docs
v1.2
* Added namespacing and composer.json

View File

@ -1,10 +0,0 @@
<?php
namespace JHodges\GiteaBot;
class ApiException extends \Exception{
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
}

View File

@ -29,19 +29,16 @@ class Client{
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if($type!='GET' && $type!='FORM'){
if($type!='GET'){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
}
if(!is_null($postFields)) {
if($type=='FORM'){
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
}else{
$postFields = json_encode($postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json',
'Content-Length: '.strlen($postFields), ]);
}
if (!is_null($postFields)) {
$postFields = json_encode($postFields);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json',
'Content-Length: '.strlen($postFields), ]);
}
if($this->user) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
@ -54,29 +51,7 @@ class Client{
if(in_array($status_code,[200,201,204])){
return json_decode($result);
}else{
throw new ApiException($result,$status_code);
throw new \Exception("API $status_code Code: ".$result);
}
}
public function getUserById($id){
$url="{$this->url}users/search?uid={$id}";
$data=$this->request($url,'GET');
return $data->data[0];
}
public function getCurrentUserTimes(\DateTime $since=null, \DateTime $before=null){
$args=[];
if($before){
$args['before'] = $before->format('c');
}
if($since){
$args['since'] = $since->format('c');
}
$url="{$this->url}user/times";
if($args){
$url.='?'.http_build_query($args);
}
$data=$this->request($url,'GET');
return $data;
}
}

View File

@ -51,32 +51,6 @@ class Repo{
return $all_issues;
}
public function getPulls($args=null){
$page=1;
$all_pulls=[];
while(1){
$url="repos/{$this->user}/{$this->repo}/pulls?page=$page";
if($args){
$url.='&'.http_build_query($args);
}
$pulls=$this->client->request($url);
foreach($pulls as $data){
$pull=$data;//new Issue($this,$data);
$all_pulls[]=$pull;
}
if(!$pulls) break;
$page++;
}
return $all_pulls;
}
public function getIssue($id){
$url="repos/{$this->user}/{$this->repo}/issues/{$id}";
$data=$this->client->request($url);
return new Issue($this,$data);
}
public function getLabelByName($name){
$url="repos/{$this->user}/{$this->repo}/labels";
if(!isset($this->cache['lables'])){
@ -115,46 +89,4 @@ class Repo{
return new Issue($this,$data);
}
public function addReleaseAttachment($releaseId,$path){
$url="repos/{$this->user}/{$this->repo}/releases/$releaseId/assets?name=test";
$args=['attachment'=>new \CurlFile($path)];
$data=$this->client->request($url,'FORM',$args);
return $data;
}
public function getTimes(\DateTime $since=null, \DateTime $before=null){
$args=[];
if($before){
$args['before'] = $before->format('c');
}
if($since){
$args['since'] = $since->format('c');
}
$url="repos/{$this->user}/{$this->repo}/times";
if($args){
$url.='?'.http_build_query($args);
}
return $this->client->request($url,'GET');
}
public function getTimesByUsername($username,\DateTime $since=null, \DateTime $before=null){
$args=[];
if($before){
$args['before'] = $before->format('c');
}
if($since){
$args['since'] = $since->format('c');
}
$url="repos/{$this->user}/{$this->repo}/times/{$username}";
if($args){
$url.='?'.http_build_query($args);
}
return $this->client->request($url,'GET');
}
public function getUsers(){
$url="repos/{$this->user}/{$this->repo}/collaborators";
return $this->client->request($url,'GET');
}
}