summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Action/TaskAssignCategoryLabel.php84
-rw-r--r--app/Action/TaskAssignUser.php81
-rw-r--r--app/Action/TaskClose.php4
-rw-r--r--app/Action/TaskCreation.php81
-rw-r--r--app/Action/TaskOpen.php73
-rw-r--r--app/Controller/Webhook.php2
-rw-r--r--app/Locales/de_DE/translations.php11
-rw-r--r--app/Locales/es_ES/translations.php11
-rw-r--r--app/Locales/fi_FI/translations.php11
-rw-r--r--app/Locales/fr_FR/translations.php11
-rw-r--r--app/Locales/it_IT/translations.php11
-rw-r--r--app/Locales/pl_PL/translations.php11
-rw-r--r--app/Locales/pt_BR/translations.php11
-rw-r--r--app/Locales/ru_RU/translations.php11
-rw-r--r--app/Locales/sv_SE/translations.php11
-rw-r--r--app/Locales/zh_CN/translations.php11
-rw-r--r--app/Model/Action.php21
-rw-r--r--app/Model/GithubWebhook.php209
-rw-r--r--app/Model/Project.php7
-rw-r--r--app/Model/Task.php16
-rw-r--r--app/Schema/Mysql.php11
-rw-r--r--app/Schema/Postgres.php17
-rw-r--r--app/Schema/Sqlite.php11
-rw-r--r--app/Templates/action_index.php2
-rw-r--r--app/Templates/action_params.php4
-rw-r--r--app/Templates/board_task.php20
-rw-r--r--app/Templates/project_layout.php2
-rw-r--r--app/Templates/task_details.php5
-rw-r--r--app/helpers.php23
29 files changed, 766 insertions, 17 deletions
diff --git a/app/Action/TaskAssignCategoryLabel.php b/app/Action/TaskAssignCategoryLabel.php
new file mode 100644
index 00000000..5e1b025e
--- /dev/null
+++ b/app/Action/TaskAssignCategoryLabel.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Set a category automatically according to a label
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskAssignCategoryLabel extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'label' => t('Label'),
+ 'category_id' => t('Category'),
+ );
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'label',
+ );
+ }
+
+ /**
+ * Execute the action (change the category)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'category_id' => isset($data['category_id']) ? $data['category_id'] : $this->getParam('category_id'),
+ );
+
+ return $this->task->update($values, false);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['label'] == $this->getParam('label');
+ }
+}
diff --git a/app/Action/TaskAssignUser.php b/app/Action/TaskAssignUser.php
new file mode 100644
index 00000000..29ea91e6
--- /dev/null
+++ b/app/Action/TaskAssignUser.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Assign a task to someone
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskAssignUser extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'owner_id',
+ );
+ }
+
+ /**
+ * Execute the action (assign the given user)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'owner_id' => $data['owner_id'],
+ );
+
+ return $this->task->update($values, false);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php
index da0744d0..f71d4b0e 100644
--- a/app/Action/TaskClose.php
+++ b/app/Action/TaskClose.php
@@ -24,6 +24,7 @@ class TaskClose extends Base
return array(
Task::EVENT_MOVE_COLUMN,
GithubWebhook::EVENT_COMMIT,
+ GithubWebhook::EVENT_ISSUE_CLOSED,
);
}
@@ -37,6 +38,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::EVENT_ISSUE_CLOSED:
return array();
default:
return array('column_id' => t('Column'));
@@ -53,6 +55,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::EVENT_ISSUE_CLOSED:
return array('task_id');
default:
return array('task_id', 'column_id');
@@ -82,6 +85,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::EVENT_ISSUE_CLOSED:
return true;
default:
return $data['column_id'] == $this->getParam('column_id');
diff --git a/app/Action/TaskCreation.php b/app/Action/TaskCreation.php
new file mode 100644
index 00000000..41d0200c
--- /dev/null
+++ b/app/Action/TaskCreation.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Create automatically a task from a webhook
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskCreation extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_OPENED,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'reference',
+ 'title',
+ );
+ }
+
+ /**
+ * Execute the action (create a new task)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ return $this->task->create(array(
+ 'project_id' => $data['project_id'],
+ 'title' => $data['title'],
+ 'reference' => $data['reference'],
+ 'description' => $data['description'],
+ ));
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/Action/TaskOpen.php b/app/Action/TaskOpen.php
new file mode 100644
index 00000000..6847856c
--- /dev/null
+++ b/app/Action/TaskOpen.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Open automatically a task
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskOpen extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_REOPENED,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array('task_id');
+ }
+
+ /**
+ * Execute the action (close the task)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ return $this->task->open($data['task_id']);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php
index 8a81a0c4..c72dc983 100644
--- a/app/Controller/Webhook.php
+++ b/app/Controller/Webhook.php
@@ -53,6 +53,8 @@ class Webhook extends Base
$this->response->text('Not Authorized', 401);
}
+ $this->githubWebhook->setProjectId($this->request->getIntegerParam('project_id'));
+
$this->githubWebhook->parsePayload(
$this->request->getHeader('X-Github-Event'),
$this->request->getBody()
diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php
index cfb1a7e2..ec570691 100644
--- a/app/Locales/de_DE/translations.php
+++ b/app/Locales/de_DE/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php
index d99b1a3e..05646a74 100644
--- a/app/Locales/es_ES/translations.php
+++ b/app/Locales/es_ES/translations.php
@@ -505,4 +505,15 @@ return array(
'New password for the user "%s"' => 'Nueva contraseña para el usuario "%s"',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/fi_FI/translations.php b/app/Locales/fi_FI/translations.php
index b2372eb9..3bb2185e 100644
--- a/app/Locales/fi_FI/translations.php
+++ b/app/Locales/fi_FI/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php
index 92fa35cf..c1723875 100644
--- a/app/Locales/fr_FR/translations.php
+++ b/app/Locales/fr_FR/translations.php
@@ -505,4 +505,15 @@ return array(
'New password for the user "%s"' => 'Nouveau mot de passe pour l\'utilisateur « %s »',
'Choose an event' => 'Choisir un événement',
'Github commit received' => '« Commit » reçu via Github',
+ 'Github issue opened' => 'Ouverture d\'un ticket sur Github',
+ 'Github issue closed' => 'Fermeture d\'un ticket sur Github',
+ 'Github issue reopened' => 'Réouverture d\'un ticket sur Github',
+ 'Github issue assignee change' => 'Changement d\'assigné sur un ticket Github',
+ 'Github issue label change' => 'Changement de libellé sur un ticket Github',
+ 'Create a task from an external provider' => 'Créer une tâche depuis un fournisseur externe',
+ 'Change the assignee based on an external username' => 'Changer l\'assigné en fonction d\'un utilisateur externe',
+ 'Change the category based on an external label' => 'Changer la catégorie en fonction d\'un libellé externe',
+ 'Reference' => 'Référence',
+ 'Reference: %s' => 'Référence : %s',
+ 'Label' => 'Libellé',
);
diff --git a/app/Locales/it_IT/translations.php b/app/Locales/it_IT/translations.php
index 5db07c99..6acac109 100644
--- a/app/Locales/it_IT/translations.php
+++ b/app/Locales/it_IT/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php
index e065a4d2..3e33ce8b 100644
--- a/app/Locales/pl_PL/translations.php
+++ b/app/Locales/pl_PL/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php
index 0473b592..68946936 100644
--- a/app/Locales/pt_BR/translations.php
+++ b/app/Locales/pt_BR/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/ru_RU/translations.php b/app/Locales/ru_RU/translations.php
index c8e12abd..a949dbd0 100644
--- a/app/Locales/ru_RU/translations.php
+++ b/app/Locales/ru_RU/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/sv_SE/translations.php b/app/Locales/sv_SE/translations.php
index 496a0959..68c0597f 100644
--- a/app/Locales/sv_SE/translations.php
+++ b/app/Locales/sv_SE/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Locales/zh_CN/translations.php b/app/Locales/zh_CN/translations.php
index b8b67a38..ef33881e 100644
--- a/app/Locales/zh_CN/translations.php
+++ b/app/Locales/zh_CN/translations.php
@@ -505,4 +505,15 @@ return array(
// 'New password for the user "%s"' => '',
// 'Choose an event' => '',
// 'Github commit received' => '',
+ // 'Github issue opened' => '',
+ // 'Github issue closed' => '',
+ // 'Github issue reopened' => '',
+ // 'Github issue assignee change' => '',
+ // 'Github issue label change' => '',
+ // 'Create a task from an external provider' => '',
+ // 'Change the assignee based on an external username' => '',
+ // 'Change the category based on an external label' => '',
+ // 'Reference' => '',
+ // 'Reference: %s' => '',
+ // 'Label' => '',
);
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 6b1ebdad..56a1a2bb 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -36,8 +36,9 @@ class Action extends Base
*/
public function getAvailableActions()
{
- return array(
+ $values = array(
'TaskClose' => t('Close a task'),
+ 'TaskOpen' => t('Open a task'),
'TaskAssignSpecificUser' => t('Assign the task to a specific user'),
'TaskAssignCurrentUser' => t('Assign the task to the person who does the action'),
'TaskDuplicateAnotherProject' => t('Duplicate the task to another project'),
@@ -45,7 +46,14 @@ class Action extends Base
'TaskAssignColorUser' => t('Assign a color to a specific user'),
'TaskAssignColorCategory' => t('Assign automatically a color based on a category'),
'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'),
+ 'TaskCreation' => t('Create a task from an external provider'),
+ 'TaskAssignUser' => t('Change the assignee based on an external username'),
+ 'TaskAssignCategoryLabel' => t('Change the category based on an external label'),
);
+
+ asort($values);
+
+ return $values;
}
/**
@@ -56,7 +64,7 @@ class Action extends Base
*/
public function getAvailableEvents()
{
- return array(
+ $values = array(
Task::EVENT_MOVE_COLUMN => t('Move a task to another column'),
Task::EVENT_UPDATE => t('Task modification'),
Task::EVENT_CREATE => t('Task creation'),
@@ -65,7 +73,16 @@ class Action extends Base
Task::EVENT_CREATE_UPDATE => t('Task creation or modification'),
Task::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'),
GithubWebhook::EVENT_COMMIT => t('Github commit received'),
+ GithubWebhook::EVENT_ISSUE_OPENED => t('Github issue opened'),
+ GithubWebhook::EVENT_ISSUE_CLOSED => t('Github issue closed'),
+ GithubWebhook::EVENT_ISSUE_REOPENED => t('Github issue reopened'),
+ GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE => t('Github issue assignee change'),
+ GithubWebhook::EVENT_ISSUE_LABEL_CHANGE => t('Github issue label change'),
);
+
+ asort($values);
+
+ return $values;
}
/**
diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php
index 688ab601..b5f95eeb 100644
--- a/app/Model/GithubWebhook.php
+++ b/app/Model/GithubWebhook.php
@@ -15,11 +15,32 @@ class GithubWebhook extends Base
*
* @var string
*/
- const EVENT_ISSUE_OPENED = 'github.webhook.issue.opened';
- const EVENT_ISSUE_CLOSED = 'github.webhook.issue.closed';
- const EVENT_ISSUE_LABELED = 'github.webhook.issue.labeled';
- const EVENT_ISSUE_COMMENT = 'github.webhook.issue.commented';
- const EVENT_COMMIT = 'github.webhook.commit';
+ const EVENT_ISSUE_OPENED = 'github.webhook.issue.opened';
+ const EVENT_ISSUE_CLOSED = 'github.webhook.issue.closed';
+ const EVENT_ISSUE_REOPENED = 'github.webhook.issue.reopened';
+ const EVENT_ISSUE_ASSIGNEE_CHANGE = 'github.webhook.issue.assignee';
+ const EVENT_ISSUE_LABEL_CHANGE = 'github.webhook.issue.label';
+ const EVENT_ISSUE_COMMENT = 'github.webhook.issue.commented';
+ const EVENT_COMMIT = 'github.webhook.commit';
+
+ /**
+ * Project id
+ *
+ * @access private
+ * @var integer
+ */
+ private $project_id = 0;
+
+ /**
+ * Set the project id
+ *
+ * @access public
+ * @param integer $project_id Project id
+ */
+ public function setProjectId($project_id)
+ {
+ $this->project_id = $project_id;
+ }
/**
* Parse Github events
@@ -76,6 +97,184 @@ class GithubWebhook extends Base
*/
public function parseIssueEvent(array $payload)
{
+ switch ($payload['action']) {
+ case 'opened':
+ $this->handleIssueOpened($payload['issue']);
+ break;
+ case 'closed':
+ $this->handleIssueClosed($payload['issue']);
+ break;
+ case 'reopened':
+ $this->handleIssueReopened($payload['issue']);
+ break;
+ case 'assigned':
+ $this->handleIssueAssigned($payload['issue']);
+ break;
+ case 'unassigned':
+ $this->handleIssueUnassigned($payload['issue']);
+ break;
+ case 'labeled':
+ $this->handleIssueLabeled($payload['issue'], $payload['label']);
+ break;
+ case 'unlabeled':
+ $this->handleIssueUnlabeled($payload['issue'], $payload['label']);
+ break;
+ }
+ }
+
+ /**
+ * Handle new issues
+ *
+ * @access public
+ * @param array $issue Issue data
+ */
+ public function handleIssueOpened(array $issue)
+ {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'reference' => $issue['number'],
+ 'title' => $issue['title'],
+ 'description' => $issue['body']."\n\n[".t('Github Issue').']('.$issue['html_url'].')',
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_OPENED, $event);
+ }
+
+ /**
+ * Handle issue closing
+ *
+ * @access public
+ * @param array $issue Issue data
+ */
+ public function handleIssueClosed(array $issue)
+ {
+ $task = $this->task->getByReference($issue['number']);
+ if ($task) {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'reference' => $issue['number'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_CLOSED, $event);
+ }
+ }
+
+ /**
+ * Handle issue reopened
+ *
+ * @access public
+ * @param array $issue Issue data
+ */
+ public function handleIssueReopened(array $issue)
+ {
+ $task = $this->task->getByReference($issue['number']);
+
+ if ($task) {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'reference' => $issue['number'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_REOPENED, $event);
+ }
+ }
+
+ /**
+ * Handle issue assignee change
+ *
+ * @access public
+ * @param array $issue Issue data
+ */
+ public function handleIssueAssigned(array $issue)
+ {
+ $user = $this->user->getByUsername($issue['assignee']['login']);
+ $task = $this->task->getByReference($issue['number']);
+
+ if ($user && $task) {
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'owner_id' => $user['id'],
+ 'reference' => $issue['number'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ }
+ }
+
+ /**
+ * Handle unassigned issue
+ *
+ * @access public
+ * @param array $issue Issue data
+ */
+ public function handleIssueUnassigned(array $issue)
+ {
+ $task = $this->task->getByReference($issue['number']);
+
+ if ($task) {
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'owner_id' => 0,
+ 'reference' => $issue['number'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event);
+ }
+ }
+
+ /**
+ * Handle labeled issue
+ *
+ * @access public
+ * @param array $issue Issue data
+ * @param array $label Label data
+ */
+ public function handleIssueLabeled(array $issue, array $label)
+ {
+ $task = $this->task->getByReference($issue['number']);
+
+ if ($task) {
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'reference' => $issue['number'],
+ 'label' => $label['name'],
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ }
+ }
+
+ /**
+ * Handle unlabeled issue
+ *
+ * @access public
+ * @param array $issue Issue data
+ * @param array $label Label data
+ */
+ public function handleIssueUnlabeled(array $issue, array $label)
+ {
+ $task = $this->task->getByReference($issue['number']);
+
+ if ($task) {
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'reference' => $issue['number'],
+ 'label' => $label['name'],
+ 'category_id' => 0,
+ );
+
+ $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event);
+ }
}
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 1eabe239..c3e8cc55 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -505,6 +505,13 @@ class Project extends Base
Task::EVENT_MOVE_COLUMN,
Task::EVENT_MOVE_POSITION,
Task::EVENT_ASSIGNEE_CHANGE,
+ GithubWebhook::EVENT_ISSUE_OPENED,
+ GithubWebhook::EVENT_ISSUE_CLOSED,
+ GithubWebhook::EVENT_ISSUE_REOPENED,
+ GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
+ GithubWebhook::EVENT_ISSUE_COMMENT,
+ GithubWebhook::EVENT_COMMIT,
);
$listener = new ProjectModificationDate($this);
diff --git a/app/Model/Task.php b/app/Model/Task.php
index 3e19555f..54dc0a2f 100644
--- a/app/Model/Task.php
+++ b/app/Model/Task.php
@@ -82,6 +82,7 @@ class Task extends Base
$sql = '
SELECT
tasks.id,
+ tasks.reference,
tasks.title,
tasks.description,
tasks.date_creation,
@@ -118,7 +119,7 @@ class Task extends Base
}
/**
- * Fetch one task
+ * Fetch a task by the id
*
* @access public
* @param integer $task_id Task id
@@ -130,6 +131,18 @@ class Task extends Base
}
/**
+ * Fetch a task by the reference (external id)
+ *
+ * @access public
+ * @param string $reference Task reference
+ * @return array
+ */
+ public function getByReference($reference)
+ {
+ return $this->db->table(self::TABLE)->eq('reference', $reference)->findOne();
+ }
+
+ /**
* Count all tasks for a given project and status
*
* @access public
@@ -200,6 +213,7 @@ class Task extends Base
'(SELECT count(*) FROM task_has_subtasks WHERE task_id=tasks.id) AS nb_subtasks',
'(SELECT count(*) FROM task_has_subtasks WHERE task_id=tasks.id AND status=2) AS nb_completed_subtasks',
'tasks.id',
+ 'tasks.reference',
'tasks.title',
'tasks.description',
'tasks.date_creation',
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 196fb856..577fac80 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -4,7 +4,16 @@ namespace Schema;
use Core\Security;
-const VERSION = 27;
+const VERSION = 28;
+
+function version_28($pdo)
+{
+ $pdo->exec("ALTER TABLE tasks ADD COLUMN reference VARCHAR(50) DEFAULT ''");
+ $pdo->exec("ALTER TABLE comments ADD COLUMN reference VARCHAR(50) DEFAULT ''");
+
+ $pdo->exec('CREATE INDEX tasks_reference_idx ON tasks(reference)');
+ $pdo->exec('CREATE INDEX comments_reference_idx ON comments(reference)');
+}
function version_27($pdo)
{
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 3341d4a1..33859513 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -4,7 +4,16 @@ namespace Schema;
use Core\Security;
-const VERSION = 8;
+const VERSION = 9;
+
+function version_9($pdo)
+{
+ $pdo->exec("ALTER TABLE tasks ADD COLUMN reference VARCHAR(50) DEFAULT ''");
+ $pdo->exec("ALTER TABLE comments ADD COLUMN reference VARCHAR(50) DEFAULT ''");
+
+ $pdo->exec('CREATE INDEX tasks_reference_idx ON tasks(reference)');
+ $pdo->exec('CREATE INDEX comments_reference_idx ON comments(reference)');
+}
function version_8($pdo)
{
@@ -22,7 +31,7 @@ function version_6($pdo)
CREATE TABLE task_has_events (
id SERIAL PRIMARY KEY,
date_creation INTEGER NOT NULL,
- event_name TEXT NOT NULL,
+ event_name VARCHAR(50) NOT NULL,
creator_id INTEGER,
project_id INTEGER,
task_id INTEGER,
@@ -37,7 +46,7 @@ function version_6($pdo)
CREATE TABLE subtask_has_events (
id SERIAL PRIMARY KEY,
date_creation INTEGER NOT NULL,
- event_name TEXT NOT NULL,
+ event_name VARCHAR(50) NOT NULL,
creator_id INTEGER,
project_id INTEGER,
subtask_id INTEGER,
@@ -54,7 +63,7 @@ function version_6($pdo)
CREATE TABLE comment_has_events (
id SERIAL PRIMARY KEY,
date_creation INTEGER NOT NULL,
- event_name TEXT NOT NULL,
+ event_name VARCHAR(50) NOT NULL,
creator_id INTEGER,
project_id INTEGER,
comment_id INTEGER,
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index 108c07f2..d9b3787d 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -4,7 +4,16 @@ namespace Schema;
use Core\Security;
-const VERSION = 27;
+const VERSION = 28;
+
+function version_28($pdo)
+{
+ $pdo->exec("ALTER TABLE tasks ADD COLUMN reference TEXT DEFAULT ''");
+ $pdo->exec("ALTER TABLE comments ADD COLUMN reference TEXT DEFAULT ''");
+
+ $pdo->exec('CREATE INDEX tasks_reference_idx ON tasks(reference)');
+ $pdo->exec('CREATE INDEX comments_reference_idx ON comments(reference)');
+}
function version_27($pdo)
{
diff --git a/app/Templates/action_index.php b/app/Templates/action_index.php
index 2647e4a7..30874591 100644
--- a/app/Templates/action_index.php
+++ b/app/Templates/action_index.php
@@ -33,6 +33,8 @@
<?= Helper\in_list($param['value'], $colors_list) ?>
<?php elseif (Helper\contains($param['name'], 'category_id')): ?>
<?= Helper\in_list($param['value'], $categories_list) ?>
+ <?php elseif (Helper\contains($param['name'], 'label')): ?>
+ <?= Helper\escape($param['value']) ?>
<?php endif ?>
</strong>
</li>
diff --git a/app/Templates/action_params.php b/app/Templates/action_params.php
index e3417f32..f647149b 100644
--- a/app/Templates/action_params.php
+++ b/app/Templates/action_params.php
@@ -26,7 +26,11 @@
<?php elseif (Helper\contains($param_name, 'category_id')): ?>
<?= Helper\form_label($param_desc, $param_name) ?>
<?= Helper\form_select('params['.$param_name.']', $categories_list, $values) ?><br/>
+ <?php elseif (Helper\contains($param_name, 'label')): ?>
+ <?= Helper\form_label($param_desc, $param_name) ?>
+ <?= Helper\form_text('params['.$param_name.']', $values) ?>
<?php endif ?>
+
<?php endforeach ?>
<div class="form-actions">
diff --git a/app/Templates/board_task.php b/app/Templates/board_task.php
index 4f3546e2..ca854f37 100644
--- a/app/Templates/board_task.php
+++ b/app/Templates/board_task.php
@@ -1,6 +1,14 @@
<?php if (isset($not_editable)): ?>
- <a href="?controller=task&amp;action=readonly&amp;task_id=<?= $task['id'] ?>&amp;token=<?= $project['token'] ?>">#<?= $task['id'] ?></a> -
+ <a href="?controller=task&amp;action=readonly&amp;task_id=<?= $task['id'] ?>&amp;token=<?= $project['token'] ?>">#<?= $task['id'] ?></a>
+
+ <?php if ($task['reference']): ?>
+ <span class="task-board-reference" title="<?= t('Reference') ?>">
+ (<?= $task['reference'] ?>)
+ </span>
+ <?php endif ?>
+
+ &nbsp;-&nbsp;
<span class="task-board-user">
<?php if (! empty($task['owner_id'])): ?>
@@ -22,7 +30,15 @@
<?php else: ?>
- <a class="task-edit-popover" href="?controller=task&amp;action=edit&amp;task_id=<?= $task['id'] ?>" title="<?= t('Edit this task') ?>">#<?= $task['id'] ?></a> -
+ <a class="task-edit-popover" href="?controller=task&amp;action=edit&amp;task_id=<?= $task['id'] ?>" title="<?= t('Edit this task') ?>">#<?= $task['id'] ?></a>
+
+ <?php if ($task['reference']): ?>
+ <span class="task-board-reference" title="<?= t('Reference') ?>">
+ (<?= $task['reference'] ?>)
+ </span>
+ <?php endif ?>
+
+ &nbsp;-&nbsp;
<span class="task-board-user">
<a class="assignee-popover" href="?controller=board&amp;action=changeAssignee&amp;task_id=<?= $task['id'] ?>" title="<?= t('Change assignee') ?>">
diff --git a/app/Templates/project_layout.php b/app/Templates/project_layout.php
index c8cc9236..3af77a09 100644
--- a/app/Templates/project_layout.php
+++ b/app/Templates/project_layout.php
@@ -1,6 +1,6 @@
<section id="main">
<div class="page-header">
- <h2><?= t('Project "%s"', $project['name']) ?></h2>
+ <h2><?= t('Project "%s"', $project['name']) ?> (#<?= $project['id'] ?>)</h2>
<ul>
<li><a href="?controller=board&amp;action=show&amp;project_id=<?= $project['id'] ?>"><?= t('Back to the board') ?></a></li>
<li><a href="?controller=project"><?= t('All projects') ?></a></li>
diff --git a/app/Templates/task_details.php b/app/Templates/task_details.php
index 018b88f3..8766beac 100644
--- a/app/Templates/task_details.php
+++ b/app/Templates/task_details.php
@@ -4,6 +4,11 @@
<span class="task-score"><?= Helper\escape($task['score']) ?></span>
<?php endif ?>
<ul>
+ <?php if ($task['reference']): ?>
+ <li>
+ <strong><?= t('Reference: %s', $task['reference']) ?></strong>
+ </li>
+ <?php endif ?>
<li>
<?= dt('Created on %B %e, %Y at %k:%M %p', $task['date_creation']) ?>
</li>
diff --git a/app/helpers.php b/app/helpers.php
index c56636e9..5cb7b82e 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -546,3 +546,26 @@ function form_numeric($name, $values = array(), array $errors = array(), array $
{
return form_input('text', $name, $values, $errors, $attributes, $class.' form-numeric');
}
+
+/**
+ * Link
+ *
+ * a('link', 'task', 'show', array('task_id' => $task_id))
+ *
+ * @param string $label Link label
+ * @param string $controller Controller name
+ * @param string $action Action name
+ * @param array $params Url parameters
+ * @param string $class CSS class attribute
+ * @return string
+ */
+function a($label, $controller, $action, array $params = array(), $css = '')
+{
+ $html = '<a href="?controller='.$controller.'&amp;action='.$action;
+
+ foreach ($params as $key => $value) {
+ $html .= '&amp;'.$key.'='.$value;
+ }
+
+ return '" class="'.$class.'"/>'.$label.'</a>';
+}