Skip to content

Commit

Permalink
Fetch user github avatar from webhook payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
vermakhushboo committed Nov 11, 2024
1 parent a032ed0 commit e107580
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ public function getEvent(string $event, string $payload): array
$commitHash = $payload['after'] ?? '';
$owner = $payload['repository']['owner']['name'] ?? '';
$authorUrl = $payload['sender']['html_url'];
$authorAvatarUrl = $payload['sender']['avatar_url'] ?? '';
$headCommitAuthor = $payload['head_commit']['author']['name'] ?? '';
$headCommitMessage = $payload['head_commit']['message'] ?? '';
$headCommitUrl = $payload['head_commit']['url'] ?? '';
Expand All @@ -598,6 +599,7 @@ public function getEvent(string $event, string $payload): array
'owner' => $owner,
'authorUrl' => $authorUrl,
'headCommitAuthor' => $headCommitAuthor,
'authorAvatarUrl' => $authorAvatarUrl,
'headCommitMessage' => $headCommitMessage,
'headCommitUrl' => $headCommitUrl,
'external' => false,
Expand All @@ -615,6 +617,7 @@ public function getEvent(string $event, string $payload): array
$owner = $payload['repository']['owner']['login'] ?? '';
$authorUrl = $payload['sender']['html_url'];
$commitHash = $payload['pull_request']['head']['sha'] ?? '';
$authorAvatarUrl = $payload['pull_request']['user']['avatar_url'] ?? '';
$headCommitUrl = $repositoryUrl . "/commits/" . $commitHash;
$external = $payload['pull_request']['head']['user']['login'] !== $payload['pull_request']['base']['user']['login'];

Expand All @@ -629,6 +632,7 @@ public function getEvent(string $event, string $payload): array
'owner' => $owner,
'authorUrl' => $authorUrl,
'headCommitUrl' => $headCommitUrl,
'authorAvatarUrl' => $authorAvatarUrl,
'external' => $external,
'pullRequestNumber' => $pullRequestNumber,
'action' => $action,
Expand Down
7 changes: 6 additions & 1 deletion tests/VCS/Adapter/GitHubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function testgetEvent(): void
"url": "https://github.com/vermakhushboo/g4-node-function/commit/b787f03343171ff5a477627796140bfa1d02da09"
},
"sender": {
"html_url": "https://github.com/vermakhushboo"
"html_url": "https://github.com/vermakhushboo",
"avatar_url": "https://avatars.githubusercontent.com/u/43381712?v=4"
}
}';

Expand All @@ -78,6 +79,10 @@ public function testgetEvent(): void
"user": {
"login": "vermakhushboo"
}
},
"user" : {
"login": "vermakhushboo",
"avatar_url": "https://avatars.githubusercontent.com/u/43381712?v=4"
}
},
"repository": {
Expand Down

0 comments on commit e107580

Please sign in to comment.