From de2c367431c2edb9cbfc598d3960a8b49761790d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 16 Dec 2025 15:42:38 +0100 Subject: [PATCH 1/3] add affected files to push payload event --- src/VCS/Adapter/Git/GitHub.php | 22 ++++++++++++++++++++ tests/VCS/Adapter/GitHubTest.php | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index b0c10b9..10b2976 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -651,6 +651,27 @@ public function getEvent(string $event, string $payload): array $headCommitMessage = $payload['head_commit']['message'] ?? ''; $headCommitUrl = $payload['head_commit']['url'] ?? ''; + $affectedFiles = []; + foreach ($payload['commits'] as $commit) { + foreach ($commit['added'] as $added) { + if (!\in_array($added, $affectedFiles)) { + $affectedFiles[] = $added; + } + } + + foreach ($commit['removed'] as $added) { + if (!\in_array($added, $affectedFiles)) { + $affectedFiles[] = $added; + } + } + + foreach ($commit['modified'] as $added) { + if (!\in_array($added, $affectedFiles)) { + $affectedFiles[] = $added; + } + } + } + return [ 'branchCreated' => $branchCreated, 'branchDeleted' => $branchDeleted, @@ -671,6 +692,7 @@ public function getEvent(string $event, string $payload): array 'external' => false, 'pullRequestNumber' => '', 'action' => '', + 'affectedFiles' => $affectedFiles ]; case 'pull_request': $repositoryId = strval($payload['repository']['id'] ?? ''); diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index 47bc59b..30661c0 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -54,6 +54,37 @@ public function testgetEvent(): void "message": "Update index.js", "url": "https://github.com/vermakhushboo/g4-node-function/commit/b787f03343171ff5a477627796140bfa1d02da09" }, + "commits": [ + { + "id": "ee8bc1b01518f1e4ec326438231ff2b44e752dd3", + "tree_id": "589ff083b5cf40f409a085e736da301b2f4f8853", + "distinct": true, + "message": "Update main.js", + "timestamp": "2025-12-16T15:34:43+01:00", + "url": "https://github.com/Meldiron/starter-function-locally-december/commit/ee8bc1b01518f1e4ec326438231ff2b44e752dd3", + "author": { + "name": "Matej Bačo", + "email": "matejbaco2000@gmail.com", + "date": "2025-12-16T15:34:43+01:00", + "username": "Meldiron" + }, + "committer": { + "name": "GitHub", + "email": "noreply@github.com", + "date": "2025-12-16T15:34:43+01:00", + "username": "web-flow" + }, + "added": [ + "src/lib.js" + ], + "removed": [ + "README.md" + ], + "modified": [ + "src/main.js" + ] + } + ], "sender": { "html_url": "https://github.com/vermakhushboo", "avatar_url": "https://avatars.githubusercontent.com/u/43381712?v=4" @@ -116,6 +147,10 @@ public function testgetEvent(): void $pushResult = $this->vcsAdapter->getEvent('push', $payload_push); $this->assertSame('main', $pushResult['branch']); $this->assertSame('603754812', $pushResult['repositoryId']); + $this->assertCount(3, $pushResult['affectedFiles']); + $this->assertSame('src/lib.js', $pushResult['affectedFiles'][0]); + $this->assertSame('README.md', $pushResult['affectedFiles'][1]); + $this->assertSame('src/main.js', $pushResult['affectedFiles'][2]); $pullRequestResult = $this->vcsAdapter->getEvent('pull_request', $payload_pull_request); $this->assertSame('opened', $pullRequestResult['action']); From d804f608ae2313ecc0d4dd6a244c81edba7fd005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 16 Dec 2025 15:49:54 +0100 Subject: [PATCH 2/3] Improved quality --- src/VCS/Adapter/Git/GitHub.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 10b2976..f92c578 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -652,22 +652,22 @@ public function getEvent(string $event, string $payload): array $headCommitUrl = $payload['head_commit']['url'] ?? ''; $affectedFiles = []; - foreach ($payload['commits'] as $commit) { - foreach ($commit['added'] as $added) { + foreach (($payload['commits'] ?? []) as $commit) { + foreach (($commit['added'] ?? []) as $added) { if (!\in_array($added, $affectedFiles)) { $affectedFiles[] = $added; } } - foreach ($commit['removed'] as $added) { - if (!\in_array($added, $affectedFiles)) { - $affectedFiles[] = $added; + foreach (($commit['removed'] ?? []) as $removed) { + if (!\in_array($removed, $affectedFiles)) { + $affectedFiles[] = $removed; } } - foreach ($commit['modified'] as $added) { - if (!\in_array($added, $affectedFiles)) { - $affectedFiles[] = $added; + foreach (($commit['modified'] ?? []) as $modified) { + if (!\in_array($modified, $affectedFiles)) { + $affectedFiles[] = $modified; } } } From 3b56bac068e9507cd9f85ec54d416c0835896e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 16 Dec 2025 15:53:22 +0100 Subject: [PATCH 3/3] Performance optimization --- src/VCS/Adapter/Git/GitHub.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index f92c578..ad42715 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -654,21 +654,15 @@ public function getEvent(string $event, string $payload): array $affectedFiles = []; foreach (($payload['commits'] ?? []) as $commit) { foreach (($commit['added'] ?? []) as $added) { - if (!\in_array($added, $affectedFiles)) { - $affectedFiles[] = $added; - } + $affectedFiles[$added] = true; } foreach (($commit['removed'] ?? []) as $removed) { - if (!\in_array($removed, $affectedFiles)) { - $affectedFiles[] = $removed; - } + $affectedFiles[$removed] = true; } foreach (($commit['modified'] ?? []) as $modified) { - if (!\in_array($modified, $affectedFiles)) { - $affectedFiles[] = $modified; - } + $affectedFiles[$modified] = true; } } @@ -692,7 +686,7 @@ public function getEvent(string $event, string $payload): array 'external' => false, 'pullRequestNumber' => '', 'action' => '', - 'affectedFiles' => $affectedFiles + 'affectedFiles' => \array_keys($affectedFiles), ]; case 'pull_request': $repositoryId = strval($payload['repository']['id'] ?? '');