Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Update plugin to latest Kanboard changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed May 30, 2016
1 parent de87189 commit cf915fe
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
6 changes: 3 additions & 3 deletions Controller/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kanboard\Plugin\GithubWebhook\Controller;

use Kanboard\Controller\Base;
use Kanboard\Controller\BaseController;
use Kanboard\Plugin\GithubWebhook\WebhookHandler;

/**
Expand All @@ -11,7 +11,7 @@
* @package controller
* @author Frederic Guillot
*/
class Webhook extends Base
class Webhook extends BaseController
{
/**
* Handle Github webhooks
Expand All @@ -30,6 +30,6 @@ public function handler()
$this->request->getJson()
);

echo $result ? 'PARSED' : 'IGNORED';
$this->response->text($result ? 'PARSED' : 'IGNORED');
}
}
6 changes: 3 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function initialize()

$this->template->hook->attach('template:project:integrations', 'GithubWebhook:project/integrations');

$this->route->addRoute('/webhook/github/:project_id/:token', 'webhook', 'handler', 'GithubWebhook');
$this->route->addRoute('/webhook/github/:project_id/:token', 'Webhook', 'handler', 'GithubWebhook');
}

public function onStartup()
{
Translator::load($this->language->getCurrentLanguage(), __DIR__.'/Locale');
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');

$this->eventManager->register(WebhookHandler::EVENT_COMMIT, t('Github commit received'));
$this->eventManager->register(WebhookHandler::EVENT_ISSUE_OPENED, t('Github issue opened'));
Expand Down Expand Up @@ -53,7 +53,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '1.0.2';
return '1.0.3';
}

public function getPluginHomepage()
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Github Webhook

[![Build Status](https://travis-ci.org/kanboard/plugin-github-webhook.svg?branch=master)](https://travis-ci.org/kanboard/plugin-github-webhook)


Bind Github webhook events to Kanboard automatic actions.

Author
Expand All @@ -15,17 +14,19 @@ Author
Requirements
------------

- Kanboard >= 1.0.29
- Github webhooks configured for a project

Installation
------------

- Decompress the archive in the `plugins` folder
You have the choice between 3 methods:

or
1. Install the plugin from the Kanboard plugin manager in one click
2. Download the zip file and decompress everything under the directory `plugins/GithubWebhook`
3. Clone this repository into the folder `plugins/GithubWebhook`

- Create a folder **plugins/GithubWebhook**
- Copy all files under this directory
Note: Plugin folder is case-sensitive.

Documentation
-------------
Expand Down
2 changes: 1 addition & 1 deletion Template/project/integrations.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h3><i class="fa fa-github fa-fw"></i>&nbsp;<?= t('Github webhooks') ?></h3>
<div class="listing">
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->url->href('webhook', 'handler', array('plugin' => 'GithubWebhook', 'token' => $webhook_token, 'project_id' => $project['id']), false, '', true) ?>"/><br/>
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->url->href('Webhook', 'handler', array('plugin' => 'GithubWebhook', 'token' => $webhook_token, 'project_id' => $project['id']), false, '', true) ?>"/><br/>
<p class="form-help"><a href="https://kanboard.net/plugin/github-webhook" target="_blank"><?= t('Help on Github webhooks') ?></a></p>
</div>
89 changes: 44 additions & 45 deletions Test/WebhookHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
require_once 'tests/units/Base.php';

use Kanboard\Plugin\GithubWebhook\WebhookHandler;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectUserRole;
use Kanboard\Model\User;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\UserModel;
use Kanboard\Core\Security\Role;

class WebhookHandlerTest extends Base
Expand All @@ -16,7 +15,7 @@ public function testIssueOpened()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -32,16 +31,16 @@ public function testIssueAssigned()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$u = new User($this->container);
$u = new UserModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'fguillot')));

$pp = new ProjectUserRole($this->container);
$pp = new ProjectUserRoleModel($this->container);
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));

$g = new WebhookHandler($this->container);
Expand All @@ -55,7 +54,7 @@ public function testIssueAssigned()

public function testIssueAssignedWithNoExistingTask()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -68,10 +67,10 @@ public function testIssueAssignedWithNoExistingTask()

public function testIssueAssignedWithNoExistingUser()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -84,13 +83,13 @@ public function testIssueAssignedWithNoExistingUser()

public function testIssueAssignedWithNoMember()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$u = new User($this->container);
$u = new UserModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'fguillot')));

$g = new WebhookHandler($this->container);
Expand All @@ -103,16 +102,16 @@ public function testIssueAssignedWithNoMember()

public function testIssueAssignedWithMember()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$u = new User($this->container);
$u = new UserModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'fguillot')));

$pp = new ProjectUserRole($this->container);
$pp = new ProjectUserRoleModel($this->container);
$this->assertTrue($pp->addUser(1, 2, ROLE::PROJECT_MANAGER));

$g = new WebhookHandler($this->container);
Expand All @@ -127,10 +126,10 @@ public function testIssueUnassigned()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -146,10 +145,10 @@ public function testIssueClosed()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -163,7 +162,7 @@ public function testIssueClosed()

public function testIssueClosedWithTaskNotFound()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -178,10 +177,10 @@ public function testIssueReopened()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -195,7 +194,7 @@ public function testIssueReopened()

public function testIssueReopenedWithTaskNotFound()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -210,10 +209,10 @@ public function testIssueLabeled()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueLabeled'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -227,7 +226,7 @@ public function testIssueLabeled()

public function testIssueLabeledWithTaskNotFound()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -242,10 +241,10 @@ public function testIssueUnLabeled()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueUnlabeled'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -259,7 +258,7 @@ public function testIssueUnLabeled()

public function testIssueUnLabeledWithTaskNotFound()
{
$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$g = new WebhookHandler($this->container);
Expand All @@ -274,10 +273,10 @@ public function testCommentCreatedWithNoUser()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand All @@ -293,13 +292,13 @@ public function testCommentCreatedWithNotMember()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$u = new User($this->container);
$u = new UserModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'fguillot')));

$g = new WebhookHandler($this->container);
Expand All @@ -315,16 +314,16 @@ public function testCommentCreatedWithUser()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1)));

$u = new User($this->container);
$u = new UserModel($this->container);
$this->assertEquals(2, $u->create(array('username' => 'fguillot')));

$pp = new ProjectUserRole($this->container);
$pp = new ProjectUserRoleModel($this->container);
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));

$g = new WebhookHandler($this->container);
Expand All @@ -340,10 +339,10 @@ public function testPush()
{
$this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onPush'));

$p = new Project($this->container);
$p = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'foobar')));

$tc = new TaskCreation($this->container);
$tc = new TaskCreationModel($this->container);
$this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1)));

$g = new WebhookHandler($this->container);
Expand Down
Loading

0 comments on commit cf915fe

Please sign in to comment.