Page MenuHomeDevCentral

D686.diff
No OneTemporary

D686.diff

diff --git a/app/Analyzers/GitHub/Events/IssueCommentEvent.php b/app/Analyzers/GitHub/Events/IssueCommentEvent.php
new file mode 100644
--- /dev/null
+++ b/app/Analyzers/GitHub/Events/IssueCommentEvent.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Nasqueron\Notifications\Analyzers\GitHub\Events;
+
+/**
+ * IssueCommentEvent payload analyzer
+ *
+ * @link https://developer.github.com/v3/activity/events/types/#issuecommentevent
+ */
+class IssueCommentEvent extends Event {
+
+ /**
+ * Determines if the action is valid.
+ *
+ * @param string $type The action to check
+ * @return bool true if the action is valid; otherwise, false
+ */
+ protected static function isValidAction ($action) {
+ $actions = ['created', 'edited', 'deleted'];
+ return in_array($action, $actions);
+ }
+
+ /**
+ * Gets description for the payload.
+ *
+ * @return string
+ */
+ public function getDescription () {
+ $action = $this->payload->action;
+
+ if (!static::isValidAction($action)) {
+ return trans(
+ 'GitHub.EventsDescriptions.IssueCommentEventUnknown',
+ ['action' => $action]
+ );
+ }
+
+ $key = 'GitHub.EventsDescriptions.IssueCommentEventPerAction.';
+ $key .= $action;
+
+ $comment = $this->payload->comment;
+ $issue = $this->payload->issue;
+
+ return trans(
+ $key,
+ [
+ 'author' => $comment->user->login,
+ 'issueNumber' => $issue->number,
+ 'issueTitle' => $issue->title,
+ 'excerpt' => self::cut($comment->body),
+ ]
+ );
+ }
+
+ /**
+ * Gets link for the payload.
+ *
+ * @return string
+ */
+ public function getLink () {
+ return $this->payload->comment->html_url;
+ }
+
+}
+
diff --git a/resources/lang/en/GitHub.php b/resources/lang/en/GitHub.php
--- a/resources/lang/en/GitHub.php
+++ b/resources/lang/en/GitHub.php
@@ -32,6 +32,13 @@
'ForkEvent' => ':repo_base has been forked to :repo_fork',
+ 'IssueCommentEventPerAction' => [
+ 'created' => ":author added a comment to issue #:issueNumber — :issueTitle: :excerpt",
+ 'edited' => ":author edited a comment to issue #:issueNumber — :issueTitle: :excerpt",
+ 'deleted' => ":author deleted a comment to issue #:issueNumber — :issueTitle",
+ ],
+ 'IssueCommentEventUnknown' => 'Unknown issue comment action: :action',
+
'PingEvent' => '« :zen » — GitHub Webhooks ping zen aphorism.',
'PushEvent' => [
diff --git a/tests/Analyzers/GitHub/Events/EventTest.php b/tests/Analyzers/GitHub/Events/EventTest.php
--- a/tests/Analyzers/GitHub/Events/EventTest.php
+++ b/tests/Analyzers/GitHub/Events/EventTest.php
@@ -67,6 +67,11 @@
'Removed tag on baxterthehacker/public-repo: simple-tag',
'https://github.com/baxterthehacker/public-repo/tags'
],
+ 'IssueCommentEvent' => [
+ 'issue_comment',
+ "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away.",
+ 'https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140'
+ ],
'ForkEvent' => [
'fork',
'baxterthehacker/public-repo has been forked to baxterandthehackers/public-repo',
diff --git a/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Analyzers/GitHub/Events/IssueCommentEventTest.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Analyzers\GitHub\Events;
+
+use Nasqueron\Notifications\Analyzers\GitHub\Events\IssueCommentEvent;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class IssueCommentEventTest extends TestCase {
+
+ /**
+ * @var stdClass
+ */
+ private $payload;
+
+ public function setUp () {
+ $filename = __DIR__ . "/../../../data/payloads/GitHubEvents/issue_comment.json";
+ $this->payload = json_decode(file_get_contents($filename));
+
+ parent::setUp();
+ }
+
+ /**
+ * @dataProvider payloadDescriptionProvider
+ */
+ public function testWhenRepositoryPerAction ($action, $description) {
+ $this->payload->action = $action;
+ $event = new IssueCommentEvent($this->payload);
+ $this->assertSame($description, $event->getDescription());
+ }
+
+ /**
+ * Provides actions and descritions for testWhenRepositoryPerAction
+ *
+ * See https://developer.github.com/v3/activity/events/types/#issuecommentevent
+ */
+ public function payloadDescriptionProvider () {
+ return [
+ ['created', "baxterthehacker added a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away."],
+ ['edited', "baxterthehacker edited a comment to issue #2 — Spelling error in the README file: You are totally right! I'll get this fixed right away."],
+ ['deleted', "baxterthehacker deleted a comment to issue #2 — Spelling error in the README file"],
+ ];
+ }
+
+}
diff --git a/tests/data/payloads/GitHubEvents/issue_comment.json b/tests/data/payloads/GitHubEvents/issue_comment.json
new file mode 100644
--- /dev/null
+++ b/tests/data/payloads/GitHubEvents/issue_comment.json
@@ -0,0 +1,182 @@
+{
+ "action": "created",
+ "issue": {
+ "url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2",
+ "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2/labels{/name}",
+ "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2/comments",
+ "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2/events",
+ "html_url": "https://github.com/baxterthehacker/public-repo/issues/2",
+ "id": 73464126,
+ "number": 2,
+ "title": "Spelling error in the README file",
+ "user": {
+ "login": "baxterthehacker",
+ "id": 6752317,
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/baxterthehacker",
+ "html_url": "https://github.com/baxterthehacker",
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "labels": [
+ {
+ "url": "https://api.github.com/repos/baxterthehacker/public-repo/labels/bug",
+ "name": "bug",
+ "color": "fc2929"
+ }
+ ],
+ "state": "open",
+ "locked": false,
+ "assignee": null,
+ "milestone": null,
+ "comments": 1,
+ "created_at": "2015-05-05T23:40:28Z",
+ "updated_at": "2015-05-05T23:40:28Z",
+ "closed_at": null,
+ "body": "It looks like you accidently spelled 'commit' with two 't's."
+ },
+ "comment": {
+ "url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140",
+ "html_url": "https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140",
+ "issue_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/2",
+ "id": 99262140,
+ "user": {
+ "login": "baxterthehacker",
+ "id": 6752317,
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/baxterthehacker",
+ "html_url": "https://github.com/baxterthehacker",
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "created_at": "2015-05-05T23:40:28Z",
+ "updated_at": "2015-05-05T23:40:28Z",
+ "body": "You are totally right! I'll get this fixed right away."
+ },
+ "repository": {
+ "id": 35129377,
+ "name": "public-repo",
+ "full_name": "baxterthehacker/public-repo",
+ "owner": {
+ "login": "baxterthehacker",
+ "id": 6752317,
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/baxterthehacker",
+ "html_url": "https://github.com/baxterthehacker",
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
+ "type": "User",
+ "site_admin": false
+ },
+ "private": false,
+ "html_url": "https://github.com/baxterthehacker/public-repo",
+ "description": "",
+ "fork": false,
+ "url": "https://api.github.com/repos/baxterthehacker/public-repo",
+ "forks_url": "https://api.github.com/repos/baxterthehacker/public-repo/forks",
+ "keys_url": "https://api.github.com/repos/baxterthehacker/public-repo/keys{/key_id}",
+ "collaborators_url": "https://api.github.com/repos/baxterthehacker/public-repo/collaborators{/collaborator}",
+ "teams_url": "https://api.github.com/repos/baxterthehacker/public-repo/teams",
+ "hooks_url": "https://api.github.com/repos/baxterthehacker/public-repo/hooks",
+ "issue_events_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/events{/number}",
+ "events_url": "https://api.github.com/repos/baxterthehacker/public-repo/events",
+ "assignees_url": "https://api.github.com/repos/baxterthehacker/public-repo/assignees{/user}",
+ "branches_url": "https://api.github.com/repos/baxterthehacker/public-repo/branches{/branch}",
+ "tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/tags",
+ "blobs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/blobs{/sha}",
+ "git_tags_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/tags{/sha}",
+ "git_refs_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/refs{/sha}",
+ "trees_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/trees{/sha}",
+ "statuses_url": "https://api.github.com/repos/baxterthehacker/public-repo/statuses/{sha}",
+ "languages_url": "https://api.github.com/repos/baxterthehacker/public-repo/languages",
+ "stargazers_url": "https://api.github.com/repos/baxterthehacker/public-repo/stargazers",
+ "contributors_url": "https://api.github.com/repos/baxterthehacker/public-repo/contributors",
+ "subscribers_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscribers",
+ "subscription_url": "https://api.github.com/repos/baxterthehacker/public-repo/subscription",
+ "commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/commits{/sha}",
+ "git_commits_url": "https://api.github.com/repos/baxterthehacker/public-repo/git/commits{/sha}",
+ "comments_url": "https://api.github.com/repos/baxterthehacker/public-repo/comments{/number}",
+ "issue_comment_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments{/number}",
+ "contents_url": "https://api.github.com/repos/baxterthehacker/public-repo/contents/{+path}",
+ "compare_url": "https://api.github.com/repos/baxterthehacker/public-repo/compare/{base}...{head}",
+ "merges_url": "https://api.github.com/repos/baxterthehacker/public-repo/merges",
+ "archive_url": "https://api.github.com/repos/baxterthehacker/public-repo/{archive_format}{/ref}",
+ "downloads_url": "https://api.github.com/repos/baxterthehacker/public-repo/downloads",
+ "issues_url": "https://api.github.com/repos/baxterthehacker/public-repo/issues{/number}",
+ "pulls_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls{/number}",
+ "milestones_url": "https://api.github.com/repos/baxterthehacker/public-repo/milestones{/number}",
+ "notifications_url": "https://api.github.com/repos/baxterthehacker/public-repo/notifications{?since,all,participating}",
+ "labels_url": "https://api.github.com/repos/baxterthehacker/public-repo/labels{/name}",
+ "releases_url": "https://api.github.com/repos/baxterthehacker/public-repo/releases{/id}",
+ "created_at": "2015-05-05T23:40:12Z",
+ "updated_at": "2015-05-05T23:40:12Z",
+ "pushed_at": "2015-05-05T23:40:27Z",
+ "git_url": "git://github.com/baxterthehacker/public-repo.git",
+ "ssh_url": "git@github.com:baxterthehacker/public-repo.git",
+ "clone_url": "https://github.com/baxterthehacker/public-repo.git",
+ "svn_url": "https://github.com/baxterthehacker/public-repo",
+ "homepage": null,
+ "size": 0,
+ "stargazers_count": 0,
+ "watchers_count": 0,
+ "language": null,
+ "has_issues": true,
+ "has_downloads": true,
+ "has_wiki": true,
+ "has_pages": true,
+ "forks_count": 0,
+ "mirror_url": null,
+ "open_issues_count": 2,
+ "forks": 0,
+ "open_issues": 2,
+ "watchers": 0,
+ "default_branch": "master"
+ },
+ "sender": {
+ "login": "baxterthehacker",
+ "id": 6752317,
+ "avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/baxterthehacker",
+ "html_url": "https://github.com/baxterthehacker",
+ "followers_url": "https://api.github.com/users/baxterthehacker/followers",
+ "following_url": "https://api.github.com/users/baxterthehacker/following{/other_user}",
+ "gists_url": "https://api.github.com/users/baxterthehacker/gists{/gist_id}",
+ "starred_url": "https://api.github.com/users/baxterthehacker/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/baxterthehacker/subscriptions",
+ "organizations_url": "https://api.github.com/users/baxterthehacker/orgs",
+ "repos_url": "https://api.github.com/users/baxterthehacker/repos",
+ "events_url": "https://api.github.com/users/baxterthehacker/events{/privacy}",
+ "received_events_url": "https://api.github.com/users/baxterthehacker/received_events",
+ "type": "User",
+ "site_admin": false
+ }
+}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 22:50 (20 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2265203
Default Alt Text
D686.diff (15 KB)

Event Timeline