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

Feature/update jira plugin #142

Open
wants to merge 3 commits 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"require": {
"doctrine/orm": "^2.7.3",
"symfony/yaml": "2.*",
"guzzlehttp/guzzle": "^6.2"
"guzzlehttp/guzzle": "^6.2",
"lesstif/php-jira-rest-client": "^1.19"
},
"autoload": {
"psr-0": {"": "src/"}
Expand Down
48 changes: 27 additions & 21 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/config.php";


// Create a simple "default" Doctrine ORM configuration for Annotations
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/model"));
$config->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_NEVER);
Expand All @@ -24,30 +25,35 @@
/*
* Base class for all controllers
*/

class ControllerBase
{
protected $entityManager;
protected $entityManager;

// Configured cards sets
public $cardSets;

function __construct($entityManager, $cardSets = [])
{
$this->entityManager = $entityManager;
$this->cardSets = $cardSets;
}

// Get session by id
protected function getSession($id)
{
$session = $this->entityManager->find("Session", $id);
if($session == null)
throw new Exception("Unknown session id!");
return $session;
}

// Get member by id
protected function getMember($id)
// Configured cards sets
public $cardSets;
// Configured Jira
public $jiraConfiguration;

function __construct($entityManager, $cardSets = [])
{
global $jiraConfiguration;
$this->entityManager = $entityManager;
$this->cardSets = $cardSets;
$this->jiraConfiguration = $jiraConfiguration;
}

// Get session by id
protected function getSession($id)
{
$session = $this->entityManager->find("Session", $id);
if ($session == null)
throw new Exception("Unknown session id!");
return $session;
}

// Get member by id
protected function getMember($id)
{
$member = $this->entityManager->find("Member", $id);
return $member;
Expand Down
36 changes: 24 additions & 12 deletions src/controllers/jira-controller.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
<?php

use JiraRestApi\Configuration\ArrayConfiguration;
use JiraRestApi\Issue\IssueService;
use JiraRestApi\JiraException;

/*
* Jira controller class to handle all Jira operations
*/

class JiraController extends ControllerBase
{

public function getIssues()
{
$parameters = array_merge((array) $jiraConfiguration, $_POST);
$parameters = array_replace_recursive($this->jiraConfiguration, $_POST);
$jql = $parameters['jql'];

$CurrentIssueService = new IssueService(new ArrayConfiguration(
array(
'jiraHost' => $parameters['base_url'],
'jiraUser' => $parameters['username'],
'jiraPassword' => $parameters['password']
)
));

$jiraUrl = $parameters['base_url'] . '/rest/api/2/search?jql=project=' . $parameters['project'];
if ($parameters['jql']) {
$jiraUrl .= ' and ' . $parameters['jql'];
if (!$parameters['disable_jira_fields']) {
$jql = 'project = ' . $parameters['project'] . ' ' . $parameters['jql'];
}

if (substr_count(strtolower($parameters['jql']), "order by") == 0 && substr_count(strtolower($parameters['jql']), "order%20by") == 0) {
$jiraUrl .= ' order by priority';
try {
$ret = $CurrentIssueService->search($jql, 0, $parameters['issue-limit']);
$ret->base_url = $parameters['base_url'];
} catch (JiraException $e) {
$ret = "" . $e;
}

$client = new GuzzleHttp\Client();
$res = $client->request('GET', $jiraUrl, [
'auth' => [$parameters['username'], $parameters['password']]
]);
$response = json_decode($res->getBody()->getContents(), true);
return $response;
return $ret;
}
}

Expand Down
60 changes: 35 additions & 25 deletions src/js/jira-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,59 @@ scrum.sources.push({
// Fixed properties and methods
name: "JIRA",
position: 3,
view: "templates/jira_source.html",
view: "templates/jira_source.php",
feedback: false,
jql: 'issuetype=story and status=backlog',
disable_jira_fields : false,
jql: 'AND issuetype in ("User Story", "Offener Punkt") ORDER BY Rank ASC',
// Feedback call for completed poll
completed: function(result) {
completed: function (result) {
},

// Custom properties and methods
loaded: false,
issues: [],
issue: {},

load: function() {
load: function () {
var self = this;
var queryParameters = null;

if (this.base_url == null) {
queryParameters = $.param({
username: this.username,
password: this.password,
jql: this.jql
});
} else {
queryParameters = $.param({
base_url: this.base_url,
username: this.username,
password: this.password,
project: this.project,
jql: this.jql
});
}

var queryParameters = $.param({
base_url: this.base_url,
username: this.username,
password: this.password,
project: this.project,
jql: this.jql
});

this.parent.$http({
url: '/api/jira/getIssues',
method: 'POST',
data: queryParameters,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (response) {
var data = response.data;
.then(function (response) {
var data = response.data;

if (!data || !data.issues) {
self.error = 'Can\'t load Jira issues, check configuration';
} else {
var converter = new showdown.Converter();
// Convert JIRA format to Markdown and then to HTML
response.data.issues.forEach(function(issue) {
var markdown = J2M.toM(issue.fields.description || '');
issue.fields.description = converter.makeHtml(markdown);
});
self.issues = response.data.issues;
if (!data || !data.issues) {
self.error = 'Can\'t load Jira issues, check configuration';
} else {
var converter = new showdown.Converter();
// Convert JIRA format to Markdown and then to HTML
response.data.issues.forEach(function (issue) {
var markdown = J2M.toM(issue.fields.description || '');
issue.fields.description = converter.makeHtml(markdown);
});
self.base_url = response.data.base_url;
self.issues = response.data.issues;
self.issue = self.issues[0];
self.loaded = true;
}
Expand Down
12 changes: 7 additions & 5 deletions src/sample-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@

// Configuration for the server side JIRA controller
$jiraConfiguration = [
'base_url' => '',
'username' => '',
'password' => '',
'project' => '',
'jql' => '',
'base_url' => null,
'issue-limit' => 15,
'disable_jira_fields' => false,
'username' => null,
'password' => null,
'project' => null,
'jql' => null
];

//Configuration for Enable/Disable style elements
Expand Down
85 changes: 0 additions & 85 deletions src/templates/jira_source.html

This file was deleted.

Loading