Allow sync of Github comments without common username and add unit tests

This commit is contained in:
Frederic Guillot
2015-06-20 19:21:35 -04:00
parent 22b26d0b4d
commit 7b947ebdbd
17 changed files with 2125 additions and 14 deletions

View File

@@ -80,7 +80,7 @@ class GithubWebhook extends \Core\Base
$task_id = $this->task->getTaskIdFromText($commit['message']);
if (! $task_id) {
if (empty($task_id)) {
continue;
}
@@ -90,7 +90,7 @@ class GithubWebhook extends \Core\Base
continue;
}
if ($task['is_active'] == Task::STATUS_OPEN && $task['project_id'] == $this->project_id) {
if ($task['project_id'] == $this->project_id) {
$this->container['dispatcher']->dispatch(
self::EVENT_COMMIT,
new GenericEvent(array('task_id' => $task_id) + $task)
@@ -140,15 +140,20 @@ class GithubWebhook extends \Core\Base
public function parseCommentIssueEvent(array $payload)
{
$task = $this->taskFinder->getByReference($this->project_id, $payload['issue']['number']);
$user = $this->user->getByUsername($payload['comment']['user']['login']);
if (! empty($task) && ! empty($user)) {
if (! empty($task)) {
$user = $this->user->getByUsername($payload['comment']['user']['login']);
if (! empty($user) && ! $this->projectPermission->isMember($this->project_id, $user['id'])) {
$user = array();
}
$event = array(
'project_id' => $this->project_id,
'reference' => $payload['comment']['id'],
'comment' => $payload['comment']['body'],
'user_id' => $user['id'],
'comment' => $payload['comment']['body']."\n\n[".t('By @%s on Github', $payload['comment']['user']['login']).']('.$payload['comment']['html_url'].')',
'user_id' => ! empty($user) ? $user['id'] : 0,
'task_id' => $task['id'],
);
@@ -257,7 +262,7 @@ class GithubWebhook extends \Core\Base
$user = $this->user->getByUsername($issue['assignee']['login']);
$task = $this->taskFinder->getByReference($this->project_id, $issue['number']);
if (! empty($user) && ! empty($task)) {
if (! empty($user) && ! empty($task) && $this->projectPermission->isMember($this->project_id, $user['id'])) {
$event = array(
'project_id' => $this->project_id,