mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-11-01 12:32:29 +01:00
Added an example code
This commit is contained in:
@ -29,6 +29,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2.0",
|
"php": ">=7.2.0",
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
|
"ext-json": "*",
|
||||||
"cedx/enum": "^7.3.0",
|
"cedx/enum": "^7.3.0",
|
||||||
"guzzlehttp/guzzle": "^6.3.3"
|
"guzzlehttp/guzzle": "^6.3.3"
|
||||||
},
|
},
|
||||||
|
|||||||
18
example/main.php
Normal file
18
example/main.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
use Gitea\{PushEvent};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the payload of a Gitea push event.
|
||||||
|
* @return PushEvent The parsed payload.
|
||||||
|
* @throws UnexpectedValueException The request headers or the request body are invalid.
|
||||||
|
*/
|
||||||
|
function main(): PushEvent {
|
||||||
|
if (!isset($_SERVER['HTTP_X_GITEA_DELIVERY']) || !isset($_SERVER['HTTP_X_GITEA_EVENT']))
|
||||||
|
throw new UnexpectedValueException('Invalid payload data.');
|
||||||
|
|
||||||
|
$data = json_decode((string) file_get_contents('php://input'));
|
||||||
|
if (!is_object($data)) throw new UnexpectedValueException('Invalid payload data.');
|
||||||
|
|
||||||
|
return PushEvent::fromJson($data);
|
||||||
|
}
|
||||||
@ -1,17 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace yii\gitea\models;
|
namespace Gitea\Models;
|
||||||
|
|
||||||
use GuzzleHttp\Psr7\{Uri};
|
use GuzzleHttp\Psr7\{Uri};
|
||||||
use Psr\Http\Message\{UriInterface};
|
use Psr\Http\Message\{UriInterface};
|
||||||
use yii\base\{Model};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a commit.
|
* Represents a commit.
|
||||||
* @property \DateTime|null $timestamp The commit date.
|
* @property \DateTime|null $timestamp The commit date.
|
||||||
* @property UriInterface|null $url The URL to the commit's history.
|
* @property UriInterface|null $url The URL to the commit's history.
|
||||||
*/
|
*/
|
||||||
class PayloadCommit extends Model {
|
class PayloadCommit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PayloadUser|null The person who authored the commit.
|
* @var PayloadUser|null The person who authored the commit.
|
||||||
@ -97,16 +96,6 @@ class PayloadCommit extends Model {
|
|||||||
return $this->url;
|
return $this->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation rules for attributes.
|
|
||||||
* @return array[] The validation rules.
|
|
||||||
*/
|
|
||||||
function rules(): array {
|
|
||||||
return [
|
|
||||||
[['id', 'message'], 'trim']
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the commit date.
|
* Sets the commit date.
|
||||||
* @param \DateTime|string|null $value The new commit date.
|
* @param \DateTime|string|null $value The new commit date.
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace yii\gitea\models;
|
namespace Gitea\Models;
|
||||||
|
|
||||||
use yii\base\{Model};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the GPG verification of a commit.
|
* Represents the GPG verification of a commit.
|
||||||
*/
|
*/
|
||||||
class PayloadCommitVerification extends Model {
|
class PayloadCommitVerification {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool Value indicating whether the verification has succeeded.
|
* @var bool Value indicating whether the verification has succeeded.
|
||||||
@ -55,15 +53,4 @@ class PayloadCommitVerification extends Model {
|
|||||||
'verified' => 'isVerified'
|
'verified' => 'isVerified'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation rules for attributes.
|
|
||||||
* @return array[] The validation rules.
|
|
||||||
*/
|
|
||||||
function rules(): array {
|
|
||||||
return [
|
|
||||||
[['payload', 'reason', 'signature'], 'trim'],
|
|
||||||
['isVerified', 'boolean', 'falseValue' => false, 'trueValue' => true]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace yii\gitea\models;
|
namespace Gitea\Models;
|
||||||
|
|
||||||
use yii\base\{Model};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the author or committer of a commit.
|
* Represents the author or committer of a commit.
|
||||||
*/
|
*/
|
||||||
class PayloadUser extends Model {
|
class PayloadUser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string The mail address.
|
* @var string The mail address.
|
||||||
@ -36,16 +34,4 @@ class PayloadUser extends Model {
|
|||||||
'username' => isset($map->username) && is_string($map->username) ? $map->username : ''
|
'username' => isset($map->username) && is_string($map->username) ? $map->username : ''
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation rules for attributes.
|
|
||||||
* @return array[] The validation rules.
|
|
||||||
*/
|
|
||||||
function rules(): array {
|
|
||||||
return [
|
|
||||||
[['email', 'name', 'username'], 'trim'],
|
|
||||||
['email', 'filter', 'filter' => 'mb_strtolower'],
|
|
||||||
['email', 'email']
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
namespace yii\gitea\models;
|
namespace Gitea\Models;
|
||||||
|
|
||||||
use yii\base\{Model};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a set of permissions.
|
* Represents a set of permissions.
|
||||||
*/
|
*/
|
||||||
class Permission extends Model {
|
class Permission {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool Value indicating whether administrator access is allowed.
|
* @var bool Value indicating whether administrator access is allowed.
|
||||||
@ -36,14 +34,4 @@ class Permission extends Model {
|
|||||||
'push' => isset($map->push) && is_bool($map->push) ? $map->push : false
|
'push' => isset($map->push) && is_bool($map->push) ? $map->push : false
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the validation rules for attributes.
|
|
||||||
* @return array[] The validation rules.
|
|
||||||
*/
|
|
||||||
function rules(): array {
|
|
||||||
return [
|
|
||||||
[['admin', 'pull', 'push'], 'boolean', 'falseValue' => false, 'trueValue' => true]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user