Page MenuHomeDevCentral

D3500.id.diff
No OneTemporary

D3500.id.diff

diff --git a/app/Analyzers/GitHub/Events/OrganizationEvent.php b/app/Analyzers/GitHub/Events/OrganizationEvent.php
new file mode 100644
--- /dev/null
+++ b/app/Analyzers/GitHub/Events/OrganizationEvent.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Nasqueron\Notifications\Analyzers\GitHub\Events;
+
+/**
+ * OrganizationEvent payload analyzer
+ *
+ * @link https://docs.github.com/en/webhooks/webhook-events-and-payloads#organization
+ */
+class OrganizationEvent extends Event {
+
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $action The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction (string $action) : bool {
+ $actions = ['renamed', 'deleted', 'member_added', 'member_invited', 'member_removed'];
+ return in_array($action, $actions);
+ }
+
+ /**
+ * Gets description for the payload
+ */
+ public function getDescription () : string {
+ $action = $this->payload->action;
+
+ if (!static::isValidAction($action)) {
+ return trans(
+ 'GitHub.EventsDescriptions.OrganizationEventUnknown',
+ ['action' => $action]
+ );
+ }
+
+ $key = 'GitHub.EventsDescriptions.OrganizationEventPerAction.';
+ $key .= $action;
+
+ return $message;
+ }
+
+ /**
+ * Gets link for the payload
+ */
+ public function getLink () : string {
+ return $this->payload->repository->html_url;
+ }
+}
diff --git a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
--- a/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
+++ b/app/Analyzers/GitHub/GitHubPayloadAnalyzer.php
@@ -91,7 +91,9 @@
public function isAdministrativeEvent () : bool {
$administrativeEvents = [
'membership', // Member added to team
+ 'organization', // Member invited to team
'ping', // Special ping pong event, fired on new hook
+ 'projects_v2', // Project created or edited
'repository', // Repository created
];
diff --git a/tests/Analyzers/GitHub/Events/OrganizationEventTest.php b/tests/Analyzers/GitHub/Events/OrganizationEventTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Analyzers/GitHub/Events/OrganizationEventTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Analyzers\GitHub\Events;
+
+use Nasqueron\Notifications\Analyzers\GitHub\Events\RepositoryEvent;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class RepositoryEventTest extends TestCase {
+
+ /**
+ * @var \stdClass
+ */
+ private $payload;
+
+ public function setUp (): void {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/repository.json";
+ $this->payload = json_decode(file_get_contents($filename));
+
+ parent::setUp();
+ }
+
+ public function testWhenRepositoryIsForked () {
+ $payload = clone $this->payload;
+ $payload->repository->fork = true;
+ $event = new RepositoryEvent($payload);
+
+ $this->assertStringContainsString("fork", $event->getDescription());
+ }
+
+ public function testWhenRepositoryContainsDescription () {
+ $payload = clone $this->payload;
+ $payload->repository->description = "Lorem ipsum dolor";
+ $event = new RepositoryEvent($payload);
+
+ $this->assertStringContainsString("Lorem ipsum dolor", $event->getDescription());
+ }
+
+ public function testWhenRepositoryIsForkedAndContainsDescription () {
+ $payload = clone $this->payload;
+ $payload->repository->fork = true;
+ $payload->repository->description = "Lorem ipsum dolor";
+ $event = new RepositoryEvent($payload);
+
+ $this->assertStringContainsString("fork", $event->getDescription());
+ $this->assertStringContainsString("Lorem ipsum dolor", $event->getDescription());
+ }
+
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction ($action, $description) {
+ $this->payload->action = $action;
+ $event = new RepositoryEvent($this->payload);
+ $this->assertSame($description, $event->getDescription());
+ }
+
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#repositoryevent
+ */
+ public function payloadDescriptionProvider () {
+ return [
+ ['created', "New repository baxterandthehackers/new-repository"],
+ ['deleted', "Repository baxterandthehackers/new-repository deleted (danger zone)"],
+ ['publicized', "Repository baxterandthehackers/new-repository is now public"],
+ ['privatized', "Repository baxterandthehackers/new-repository is now private"],
+ ['quuxed', "Unknown repository action: quuxed"],
+ ];
+ }
+
+}
diff --git a/tests/Analyzers/GitHub/Events/UnknownEventTest.php b/tests/Analyzers/GitHub/Events/UnknownEventTest.php
--- a/tests/Analyzers/GitHub/Events/UnknownEventTest.php
+++ b/tests/Analyzers/GitHub/Events/UnknownEventTest.php
@@ -21,7 +21,7 @@
}
public function testUnknownEvent () {
- $this->assertInstanceOf("Nasqueron\Notifications\Analyzers\GitHub\Events\UnknownEvent", $this->event);
+ $this->assertInstanceOf(UnknownEvent::class, $this->event);
$this->assertSame("Some quux happened", $this->event->getDescription());
$this->assertEmpty($this->event->getLink());
}
diff --git a/tests/data/payloads/GitHubEvents/organization_member_invited.json b/tests/data/payloads/GitHubEvents/organization_member_invited.json
new file mode 100644
--- /dev/null
+++ b/tests/data/payloads/GitHubEvents/organization_member_invited.json
@@ -0,0 +1,90 @@
+{
+ "action": "member_invited",
+ "invitation": {
+ "id": 57083161,
+ "node_id": "OI_kwDOAFWIqs4DZwUZ",
+ "login": "aceppaluni",
+ "email": null,
+ "role": "direct_member",
+ "created_at": "2024-10-08T20:59:47.000+02:00",
+ "failed_at": null,
+ "failed_reason": null,
+ "inviter": {
+ "login": "dereckson",
+ "id": 135563,
+ "node_id": "MDQ6VXNlcjEzNTU2Mw==",
+ "avatar_url": "https://avatars.githubusercontent.com/u/135563?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/dereckson",
+ "html_url": "https://github.com/dereckson",
+ "followers_url": "https://api.github.com/users/dereckson/followers",
+ "following_url": "https://api.github.com/users/dereckson/following{/other_user}",
+ "gists_url": "https://api.github.com/users/dereckson/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/dereckson/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/dereckson/subscriptions",
+ "organizations_url": "https://api.github.com/users/dereckson/orgs",
+ "repos_url": "https://api.github.com/users/dereckson/repos",
+ "events_url": "https://api.github.com/users/dereckson/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/dereckson/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "team_count": 1,
+ "invitation_teams_url": "https://api.github.com/organizations/5605546/invitations/57083161/teams",
+ "invitation_source": "member"
+ },
+ "user": {
+ "login": "aceppaluni",
+ "id": 113948612,
+ "node_id": "U_kgDOBsq3xA",
+ "avatar_url": "https://avatars.githubusercontent.com/u/113948612?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/aceppaluni",
+ "html_url": "https://github.com/aceppaluni",
+ "followers_url": "https://api.github.com/users/aceppaluni/followers",
+ "following_url": "https://api.github.com/users/aceppaluni/following{/other_user}",
+ "gists_url": "https://api.github.com/users/aceppaluni/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/aceppaluni/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/aceppaluni/subscriptions",
+ "organizations_url": "https://api.github.com/users/aceppaluni/orgs",
+ "repos_url": "https://api.github.com/users/aceppaluni/repos",
+ "events_url": "https://api.github.com/users/aceppaluni/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/aceppaluni/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "organization": {
+ "login": "nasqueron",
+ "id": 5605546,
+ "node_id": "MDEyOk9yZ2FuaXphdGlvbjU2MDU1NDY=",
+ "url": "https://api.github.com/orgs/nasqueron",
+ "repos_url": "https://api.github.com/orgs/nasqueron/repos",
+ "events_url": "https://api.github.com/orgs/nasqueron/events",
+ "hooks_url": "https://api.github.com/orgs/nasqueron/hooks",
+ "issues_url": "https://api.github.com/orgs/nasqueron/issues",
+ "members_url": "https://api.github.com/orgs/nasqueron/members{/member}",
+ "public_members_url": "https://api.github.com/orgs/nasqueron/public_members{/member}",
+ "avatar_url": "https://avatars.githubusercontent.com/u/5605546?v=4",
+ "description": "Central hub of a budding community of creative people, writers, developers and thinkers."
+ },
+ "sender": {
+ "login": "dereckson",
+ "id": 135563,
+ "node_id": "MDQ6VXNlcjEzNTU2Mw==",
+ "avatar_url": "https://avatars.githubusercontent.com/u/135563?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/dereckson",
+ "html_url": "https://github.com/dereckson",
+ "followers_url": "https://api.github.com/users/dereckson/followers",
+ "following_url": "https://api.github.com/users/dereckson/following{/other_user}",
+ "gists_url": "https://api.github.com/users/dereckson/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/dereckson/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/dereckson/subscriptions",
+ "organizations_url": "https://api.github.com/users/dereckson/orgs",
+ "repos_url": "https://api.github.com/users/dereckson/repos",
+ "events_url": "https://api.github.com/users/dereckson/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/dereckson/received_events",
+ "type": "User",
+ "site_admin": false
+ }
+}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 27, 17:24 (48 m, 38 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3109785
Default Alt Text
D3500.id.diff (10 KB)

Event Timeline