Skip to content

Commit 3668a5a

Browse files
author
Your Name
committed
updated with automatic trigger
1 parent c1b1daa commit 3668a5a

7 files changed

Lines changed: 143 additions & 87 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"require": {
3030
"php": ">=8.0",
3131
"adhocore/jwt": "^1.1",
32-
"utopia-php/cache": "1.0.*"
32+
"utopia-php/cache": "1.0.*",
33+
"utopia-php/fetch": "1.0.*"
3334
},
3435
"require-dev": {
3536
"phpunit/phpunit": "^9.4",

composer.lock

Lines changed: 44 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ services:
3131
- GITEA__webhook__ALLOWED_HOST_LIST=*
3232
- GITEA__webhook__SKIP_TLS_VERIFY=true
3333
- GITEA__webhook__DELIVER_TIMEOUT=10
34+
- GITEA__server__LOCAL_ROOT_URL=http://gitea:3000/
3435
ports:
3536
- "3000:3000"
3637
volumes:

src/VCS/Adapter/Git.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,17 @@ abstract public function createBranch(string $owner, string $repositoryName, str
7070
* @return array<mixed> Created PR details
7171
*/
7272
abstract public function createPullRequest(string $owner, string $repositoryName, string $title, string $head, string $base, string $body = ''): array;
73+
74+
/**
75+
* Create a webhook on a repository
76+
*
77+
* @param string $owner Owner of the repository
78+
* @param string $repositoryName Name of the repository
79+
* @param string $url Webhook URL to send events to
80+
* @param string $secret Webhook secret for signature validation
81+
* @param array<string> $events Events to trigger the webhook
82+
* @return int Webhook ID
83+
*/
84+
abstract public function createWebhook(string $owner, string $repositoryName, string $url, string $secret, array $events = ['push', 'pull_request']): int;
85+
7386
}

src/VCS/Adapter/Git/GitHub.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function createPullRequest(string $owner, string $repositoryName, string
109109
throw new Exception('Not implemented');
110110
}
111111

112+
/**
113+
* Create a webhook on a repository
114+
*
115+
* Note: Not applicable for GitHub - webhooks are managed via GitHub Apps
116+
*/
117+
public function createWebhook(string $owner, string $repositoryName, string $url, string $secret, array $events = ['push', 'pull_request']): int
118+
{
119+
throw new Exception('Not applicable for GitHub - webhooks are managed via GitHub Apps');
120+
}
121+
112122
/**
113123
* Create a file in a repository
114124
*

src/VCS/Adapter/Git/Gitea.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,43 @@ public function createPullRequest(string $owner, string $repositoryName, string
473473
return $responseBody;
474474
}
475475

476+
/**
477+
* Create a webhook on a repository
478+
*
479+
* @param string $owner Owner of the repository
480+
* @param string $repositoryName Name of the repository
481+
* @param string $url Webhook URL to send events to
482+
* @param string $secret Webhook secret for signature validation
483+
* @param array<string> $events Events to trigger the webhook
484+
* @return int Webhook ID
485+
*/
486+
public function createWebhook(string $owner, string $repositoryName, string $url, string $secret, array $events = ['push', 'pull_request']): int
487+
{
488+
$response = $this->call(
489+
self::METHOD_POST,
490+
"/repos/{$owner}/{$repositoryName}/hooks",
491+
['Authorization' => "token $this->accessToken"],
492+
[
493+
'type' => 'gitea',
494+
'active' => true,
495+
'events' => $events,
496+
'config' => [
497+
'url' => $url,
498+
'content_type' => 'json',
499+
'secret' => $secret,
500+
],
501+
]
502+
);
503+
504+
$responseHeaders = $response['headers'] ?? [];
505+
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
506+
if ($responseHeadersStatusCode >= 400) {
507+
throw new Exception("Failed to create webhook: HTTP {$responseHeadersStatusCode}");
508+
}
509+
510+
return (int) ($response['body']['id'] ?? 0);
511+
}
512+
476513
public function createComment(string $owner, string $repositoryName, int $pullRequestNumber, string $comment): string
477514
{
478515
$url = "/repos/{$owner}/{$repositoryName}/issues/{$pullRequestNumber}/comments";

0 commit comments

Comments
 (0)