Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Taiga plugin #150

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions src/controllers/taiga-controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php

/*
* Taiga controller class to handle all Taiga operations
*/
class TaigaController extends ControllerBase
{

public function auth()
{
global $taigaConfiguration;
$parameters = array_merge((array) $taigaConfiguration, $_POST);

$taigaUrl = $parameters['base_url'] . '/api/v1/auth';

$client = new GuzzleHttp\Client();
$res = $client->request('POST', $taigaUrl, [
'json' => [
'type' => $parameters['type'],
'username' => $parameters['username'],
'password' => $parameters['password']
]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
}

public function resolve()
{
global $taigaConfiguration;
$parameters = array_merge((array) $taigaConfiguration, $_POST);

$taigaUrl = $parameters['base_url'] . '/api/v1/resolver?';

$query = '';

if (isset($parameters['project'])) {
$query .= '&project=' . $parameters['project'];
}

if (isset($parameters['us'])) {
$query .= '&us=' . $parameters['us'];
}

if (isset($parameters['issue'])) {
$query .= '&issue=' . $parameters['issue'];
}

if (isset($parameters['task'])) {
$query .= '&task=' . $parameters['task'];
}

if (isset($parameters['milestone'])) {
$query .= '&milestone=' . $parameters['milestone'];
}

if (isset($parameters['wikipage'])) {
$query .= '&wikipage=' . $parameters['wikipage'];
}

if (isset($parameters['ref'])) {
$query .= '&ref=' . $parameters['ref'];
}

$taigaUrl .= substr($query, 1);

$client = new GuzzleHttp\Client();
$res = $client->request('GET', $taigaUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $parameters['auth_token']
]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
}

public function getStoryStatuses()
{
global $taigaConfiguration;
$parameters = array_merge((array) $taigaConfiguration, $_POST);

$taigaUrl = $parameters['base_url'] . '/api/v1/userstory-statuses?project=' . $parameters['project'];

$client = new GuzzleHttp\Client();
$res = $client->request('GET', $taigaUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $parameters['auth_token']
]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
}

public function getStory()
{
global $taigaConfiguration;
$parameters = array_merge((array) $taigaConfiguration, $_POST);

$taigaUrl = $parameters['base_url'] . '/api/v1/userstories/' . $parameters['id'];

$client = new GuzzleHttp\Client();
$res = $client->request('GET', $taigaUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $parameters['auth_token']
]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
}

public function getStories()
{
global $taigaConfiguration;
$parameters = array_merge((array) $taigaConfiguration, $_POST);

$taigaUrl = $parameters['base_url'] . '/api/v1/userstories?project=' . $parameters['project'];
if (isset($parameters['milestone'])) {
$taigaUrl .= '&milestone=' . $parameters['milestone'];
}

# Careful, Taiga's API has an extra underscore here
if (isset($parameters['milestone_isnull'])) {
$taigaUrl .= '&milestone__isnull=' . $parameters['milestone_isnull'];
}

if (isset($parameters['status'])) {
$taigaUrl .= '&status=' . $parameters['status'];
}

if (isset($parameters['status_is_archived'])) {
$taigaUrl .= '&status_is_archived=' . $parameters['status_is_archived'];
}

if (isset($parameters['tags'])) {
$taigaUrl .= '&tags=' . $parameters['tags'];
}

if (isset($parameters['watchers'])) {
$taigaUrl .= '&watchers=' . $parameters['watchers'];
}

if (isset($parameters['assigned_to'])) {
$taigaUrl .= '&assigned_to=' . $parameters['assigned_to'];
}

if (isset($parameters['epic'])) {
$taigaUrl .= '&epic=' . $parameters['epic'];
}

if (isset($parameters['role'])) {
$taigaUrl .= '&role=' . $parameters['role'];
}

if (isset($parameters['status_is_closed'])) {
$taigaUrl .= '&status_is_closed=' . $parameters['status_is_closed'];
}

if (isset($parameters['exclude_status'])) {
$taigaUrl .= '&exclude_status=' . $parameters['exclude_status'];
}

if (isset($parameters['exclude_tags'])) {
$taigaUrl .= '&exclude_tags=' . $parameters['exclude_tags'];
}

if (isset($parameters['exclude_assigned_to'])) {
$taigaUrl .= '&exclude_assigned_to=' . $parameters['exclude_assigned_to'];
}

if (isset($parameters['exclude_role'])) {
$taigaUrl .= '&exclude_role=' . $parameters['exclude_role'];
}

if (isset($parameters['exclude_epic'])) {
$taigaUrl .= '&exclude_epic=' . $parameters['exclude_epic'];
}

$client = new GuzzleHttp\Client();
$res = $client->request('GET', $taigaUrl, [
'headers' => [
'Authorization' => 'Bearer ' . $parameters['auth_token']
]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
}
}

return new TaigaController($entityManager);
169 changes: 169 additions & 0 deletions src/js/taiga-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*globals scrum */

// Add a plugin to load stories from local Taiga server
scrum.sources.push({
// Fixed properties and methods
name: "Taiga",
position: 4,
view: "templates/taiga_source.php",
feedback: false,
// Feedback call for completed poll
completed: function(result) {
},

// Custom properties and methods
loaded: false,
stories: [],
story: {},
statuses: [],
statuses_by_name: [],

load: function() {
var self = this;

var authParameters = $.param({
username: self.username,
password: self.password,
});
if (self.base_url) {
authParameters['base_url'] = self.base_url;
}
if (self.type) {
authParameters['type'] = self.type;
}

self.parent.$http({
url: '/api/taiga/auth',
method: 'POST',
data: authParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
if (!data || !data.auth_token) {
self.error = 'Taiga login failed';
return;
}
self.auth_token = data.auth_token;
var resolveParameters = $.param({
auth_token: self.auth_token,
project: self.project
});
if (self.base_url) {
authParameters['base_url'] = self.base_url;
}
self.parent.$http({
url: '/api/taiga/resolve',
method: 'POST',
data: resolveParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
if (!data || !data.project) {
self.error = 'Unknown project'
return;
}
self.project_id = data.project;
var queryParameters = $.param({
auth_token: self.auth_token,
project: self.project_id,
});
self.parent.$http({
url: '/api/taiga/getStoryStatuses',
method: 'POST',
data: queryParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
if (!data) {
self.error = 'Can\'t fetch story statuses';
return;
}
data.forEach(function(status) {
self.statuses[status.id] = status;
self.statuses_by_name[status.name] = status;
});
var queryParameters = {
auth_token: self.auth_token,
project: self.project_id,
status_is_closed: false,
status_is_archived: false
};
if (self.from == 'backlog') {
queryParameters['milestone_isnull'] = true;
}
if (self.from == 'sprint') {
queryParameters['milestone_isnull'] = false;
}
if (self.status) {
if (self.statuses_by_name[self.status]) {
queryParameters['status'] = self.statuses_by_name[self.status].id;
}
}
queryParameters = $.param(queryParameters);
self.parent.$http({
url: '/api/taiga/getStories',
method: 'POST',
data: queryParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
if (!data) {
self.error = 'Can\'t load stories';
return;
}
self.stories = data;
self.story = self.stories[0];
self.stories.forEach(function(story) {
self.retrieve_description(story.id);
});
});
});
});
});
},

retrieve_description: function(id = self.story.id) {
var self = this;
var queryParameters = $.param({
auth_token: self.auth_token,
id: id
});
self.parent.$http({
url: '/api/taiga/getStory',
method: 'POST',
data: queryParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
if (!data) {
self.error = 'Can\'t load story';
return;
}
var converter = new showdown.Converter();
data.description = converter.makeHtml(data.description);
all_loaded = true;
self.stories.forEach(function(value, index) {
if ( value.id == data.id ) {
self.stories[index] = data;
self.stories[index].loaded = true;
}
if ( ! self.stories[index].loaded ) {
all_loaded = false;
}
});
if (all_loaded) {
self.loaded = true;
self.story = self.stories[0]
}
});
},

reload: function() {
this.loaded = false;
}
});
15 changes: 13 additions & 2 deletions src/sample-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
// Plugin to load issues from JIRA
'JIRA',
// Plugin to load issues from Gitlab
'Gitlab'
'Gitlab',
// Plugin to load issues from Taiga
'Taiga'
];

// Configuration for the server side JIRA controller
Expand All @@ -58,7 +60,16 @@
'jql' => '',
];

// Configuration for the server side Taiga controller
$taigaConfiguration = [
'base_url' => '',
'username' => '',
'password' => '',
'type' => 'normal',
'project' => '',
];

//Configuration for Enable/Disable style elements
$layout_switch = [
'enable_fork_banner' => true
];
];
Loading