fix git
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Http\Controllers\Git;
|
|||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
final class GiteaWebhookController extends Controller
|
final class GiteaWebhookController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,11 +16,52 @@ final class GiteaWebhookController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function __invoke(Request $request): JsonResponse
|
public function __invoke(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
return response()->json([
|
Log::info('Gitea webhook endpoint hit.', [
|
||||||
'message' => 'Gitea webhook received.',
|
|
||||||
'event' => $request->header('X-Gitea-Event'),
|
'event' => $request->header('X-Gitea-Event'),
|
||||||
'delivery' => $request->header('X-Gitea-Delivery'),
|
'delivery' => $request->header('X-Gitea-Delivery'),
|
||||||
'payload' => $request->json()->all(),
|
'authorization_present' => $request->headers->has('Authorization'),
|
||||||
|
'signature_present' => $request->headers->has('X-Gitea-Signature'),
|
||||||
|
]);
|
||||||
|
$event = (string) $request->header('X-Gitea-Event');
|
||||||
|
$payload = $request->json()->all();
|
||||||
|
|
||||||
|
if ($event !== 'push') {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Gitea webhook ignored.',
|
||||||
|
'event' => $event,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commits = $request->input('commits', []);
|
||||||
|
|
||||||
|
Log::info('Gitea push webhook received.', [
|
||||||
|
'repository' => data_get($payload, 'repository.full_name'),
|
||||||
|
'ref' => data_get($payload, 'ref'),
|
||||||
|
'branch' => str_replace('refs/heads/', '', (string) data_get($payload, 'ref')),
|
||||||
|
'before' => data_get($payload, 'before'),
|
||||||
|
'after' => data_get($payload, 'after'),
|
||||||
|
'commit_count' => count($commits),
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($commits as $commit) {
|
||||||
|
Log::info('Gitea commit received.', [
|
||||||
|
'sha' => data_get($commit, 'id'),
|
||||||
|
'message' => data_get($commit, 'message'),
|
||||||
|
'url' => data_get($commit, 'url'),
|
||||||
|
'author_name' => data_get($commit, 'author.name'),
|
||||||
|
'author_email' => data_get($commit, 'author.email'),
|
||||||
|
'timestamp' => data_get($commit, 'timestamp'),
|
||||||
|
'added' => data_get($commit, 'added', []),
|
||||||
|
'modified' => data_get($commit, 'modified', []),
|
||||||
|
'removed' => data_get($commit, 'removed', []),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Gitea push processed.',
|
||||||
|
'repository' => data_get($payload, 'repository.full_name'),
|
||||||
|
'branch' => str_replace('refs/heads/', '', (string) data_get($payload, 'ref')),
|
||||||
|
'commit_count' => count($commits),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user