summaryrefslogtreecommitdiff
path: root/app/Model/GithubWebhook.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-25 18:13:13 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-25 18:13:13 -0400
commitc4e6d658e4099bd8152c77a76f486809693205f5 (patch)
tree3f40b34076fe62843023877e463c8538f2339053 /app/Model/GithubWebhook.php
parent7af67934cf67d40e1471b519ecdf06343203c6f6 (diff)
Finish github webhooks integration
Diffstat (limited to 'app/Model/GithubWebhook.php')
-rw-r--r--app/Model/GithubWebhook.php87
1 files changed, 73 insertions, 14 deletions
diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php
index 6624a782..58c2fa54 100644
--- a/app/Model/GithubWebhook.php
+++ b/app/Model/GithubWebhook.php
@@ -48,6 +48,7 @@ class GithubWebhook extends Base
* @access public
* @param string $type Github event type
* @param string $payload Raw Github event (JSON)
+ * @return boolean
*/
public function parsePayload($type, $payload)
{
@@ -58,7 +59,11 @@ class GithubWebhook extends Base
return $this->parsePushEvent($payload);
case 'issues':
return $this->parseIssueEvent($payload);
+ case 'issue_comment':
+ return $this->parseCommentIssueEvent($payload);
}
+
+ return false;
}
/**
@@ -66,6 +71,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $payload Event data
+ * @return boolean
*/
public function parsePushEvent(array $payload)
{
@@ -87,6 +93,8 @@ class GithubWebhook extends Base
$this->event->trigger(self::EVENT_COMMIT, array('task_id' => $task_id) + $task);
}
}
+
+ return true;
}
/**
@@ -94,32 +102,57 @@ class GithubWebhook extends Base
*
* @access public
* @param array $payload Event data
+ * @return boolean
*/
public function parseIssueEvent(array $payload)
{
switch ($payload['action']) {
case 'opened':
- $this->handleIssueOpened($payload['issue']);
- break;
+ return $this->handleIssueOpened($payload['issue']);
case 'closed':
- $this->handleIssueClosed($payload['issue']);
- break;
+ return $this->handleIssueClosed($payload['issue']);
case 'reopened':
- $this->handleIssueReopened($payload['issue']);
- break;
+ return $this->handleIssueReopened($payload['issue']);
case 'assigned':
- $this->handleIssueAssigned($payload['issue']);
- break;
+ return $this->handleIssueAssigned($payload['issue']);
case 'unassigned':
- $this->handleIssueUnassigned($payload['issue']);
- break;
+ return $this->handleIssueUnassigned($payload['issue']);
case 'labeled':
- $this->handleIssueLabeled($payload['issue'], $payload['label']);
- break;
+ return $this->handleIssueLabeled($payload['issue'], $payload['label']);
case 'unlabeled':
- $this->handleIssueUnlabeled($payload['issue'], $payload['label']);
- break;
+ return $this->handleIssueUnlabeled($payload['issue'], $payload['label']);
+ }
+
+ return false;
+ }
+
+ /**
+ * Parse comment issue events
+ *
+ * @access public
+ * @param array $payload Event data
+ * @return boolean
+ */
+ public function parseCommentIssueEvent(array $payload)
+ {
+ $task = $this->taskFinder->getByReference($payload['issue']['number']);
+ $user = $this->user->getByUsername($payload['comment']['user']['login']);
+
+ if ($task && $user) {
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'reference' => $payload['comment']['id'],
+ 'comment' => $payload['comment']['body'],
+ 'user_id' => $user['id'],
+ 'task_id' => $task['id'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_COMMENT, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -127,6 +160,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $issue Issue data
+ * @return boolean
*/
public function handleIssueOpened(array $issue)
{
@@ -138,6 +172,7 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_OPENED, $event);
+ return true;
}
/**
@@ -145,6 +180,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $issue Issue data
+ * @return boolean
*/
public function handleIssueClosed(array $issue)
{
@@ -158,7 +194,10 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_CLOSED, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -166,6 +205,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $issue Issue data
+ * @return boolean
*/
public function handleIssueReopened(array $issue)
{
@@ -179,7 +219,10 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_REOPENED, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -187,6 +230,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $issue Issue data
+ * @return boolean
*/
public function handleIssueAssigned(array $issue)
{
@@ -203,7 +247,10 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -211,6 +258,7 @@ class GithubWebhook extends Base
*
* @access public
* @param array $issue Issue data
+ * @return boolean
*/
public function handleIssueUnassigned(array $issue)
{
@@ -226,7 +274,10 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -235,6 +286,7 @@ class GithubWebhook extends Base
* @access public
* @param array $issue Issue data
* @param array $label Label data
+ * @return boolean
*/
public function handleIssueLabeled(array $issue, array $label)
{
@@ -250,7 +302,10 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ return true;
}
+
+ return false;
}
/**
@@ -259,6 +314,7 @@ class GithubWebhook extends Base
* @access public
* @param array $issue Issue data
* @param array $label Label data
+ * @return boolean
*/
public function handleIssueUnlabeled(array $issue, array $label)
{
@@ -275,6 +331,9 @@ class GithubWebhook extends Base
);
$this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ return true;
}
+
+ return false;
}
}