Update Gitlab webhook

This commit is contained in:
Frederic Guillot
2015-07-17 19:12:08 -04:00
parent 0bc99aef08
commit 31c57a82b9
26 changed files with 356 additions and 28 deletions

View File

@@ -28,6 +28,7 @@ class CommentCreation extends Base
BitbucketWebhook::EVENT_ISSUE_COMMENT,
BitbucketWebhook::EVENT_COMMIT,
GitlabWebhook::EVENT_COMMIT,
GitlabWebhook::EVENT_ISSUE_COMMENT,
);
}

View File

@@ -21,14 +21,16 @@ class GitlabWebhook extends \Core\Base
const EVENT_ISSUE_OPENED = 'gitlab.webhook.issue.opened';
const EVENT_ISSUE_CLOSED = 'gitlab.webhook.issue.closed';
const EVENT_COMMIT = 'gitlab.webhook.commit';
const EVENT_ISSUE_COMMENT = 'gitlab.webhook.issue.commented';
/**
* Supported webhook events
*
* @var string
*/
const TYPE_PUSH = 'push';
const TYPE_ISSUE = 'issue';
const TYPE_PUSH = 'push';
const TYPE_ISSUE = 'issue';
const TYPE_COMMENT = 'comment';
/**
* Project id
@@ -63,6 +65,8 @@ class GitlabWebhook extends \Core\Base
return $this->handlePushEvent($payload);
case self::TYPE_ISSUE;
return $this->handleIssueEvent($payload);
case self::TYPE_COMMENT;
return $this->handleCommentEvent($payload);
}
return false;
@@ -77,15 +81,20 @@ class GitlabWebhook extends \Core\Base
*/
public function getType(array $payload)
{
if (isset($payload['object_kind']) && $payload['object_kind'] === 'issue') {
return self::TYPE_ISSUE;
if (empty($payload['object_kind'])) {
return '';
}
if (isset($payload['commits'])) {
return self::TYPE_PUSH;
switch ($payload['object_kind']) {
case 'issue':
return self::TYPE_ISSUE;
case 'note':
return self::TYPE_COMMENT;
case 'push':
return self::TYPE_PUSH;
default:
return '';
}
return '';
}
/**
@@ -213,4 +222,46 @@ class GitlabWebhook extends \Core\Base
return false;
}
/**
* Parse comment issue events
*
* @access public
* @param array $payload Event data
* @return boolean
*/
public function handleCommentEvent(array $payload)
{
if (! isset($payload['issue'])) {
return false;
}
$task = $this->taskFinder->getByReference($this->project_id, $payload['issue']['id']);
if (! empty($task)) {
$user = $this->user->getByUsername($payload['user']['username']);
if (! empty($user) && ! $this->projectPermission->isMember($this->project_id, $user['id'])) {
$user = array();
}
$event = array(
'project_id' => $this->project_id,
'reference' => $payload['object_attributes']['id'],
'comment' => $payload['object_attributes']['note']."\n\n[".t('By @%s on Gitlab', $payload['user']['username']).']('.$payload['object_attributes']['url'].')',
'user_id' => ! empty($user) ? $user['id'] : 0,
'task_id' => $task['id'],
);
$this->container['dispatcher']->dispatch(
self::EVENT_ISSUE_COMMENT,
new GenericEvent($event)
);
return true;
}
return false;
}
}

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -996,4 +996,6 @@ return array(
'Remote user' => 'Utilisateur distant',
'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => 'Les utilisateurs distants ne stockent pas leur mot de passe dans la base de données de Kanboard, exemples : comptes LDAP, Github ou Google.',
'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => 'Si vous cochez la case « Interdir le formulaire d\'authentification », les identifiants entrés dans le formulaire d\'authentification seront ignorés.',
'By @%s on Gitlab' => 'Par @%s sur Gitlab',
'Gitlab issue comment created' => 'Commentaire créé sur un ticket Gitlab',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -994,4 +994,6 @@ return array(
// 'Remote user' => '',
// 'Remote users do not store their password in Kanboard database, examples: LDAP, Google and Github accounts.' => '',
// 'If you check the box "Disallow login form", credentials entered in the login form will be ignored.' => '',
// 'By @%s on Gitlab' => '',
// 'Gitlab issue comment created' => '',
);

View File

@@ -92,6 +92,7 @@ class Action extends Base
GitlabWebhook::EVENT_COMMIT => t('Gitlab commit received'),
GitlabWebhook::EVENT_ISSUE_OPENED => t('Gitlab issue opened'),
GitlabWebhook::EVENT_ISSUE_CLOSED => t('Gitlab issue closed'),
GitlabWebhook::EVENT_ISSUE_COMMENT => t('Gitlab issue comment created'),
BitbucketWebhook::EVENT_COMMIT => t('Bitbucket commit received'),
BitbucketWebhook::EVENT_ISSUE_OPENED => t('Bitbucket issue opened'),
BitbucketWebhook::EVENT_ISSUE_CLOSED => t('Bitbucket issue closed'),