Skip to content

Commit

Permalink
Merge branch 'master' into feature/process_comment
Browse files Browse the repository at this point in the history
Conflicts:
	tests/IssueTest.php
  • Loading branch information
lesstif committed Mar 9, 2015
2 parents dec5cd1 + 7935b53 commit 5b4384e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 93 deletions.
37 changes: 11 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,18 @@
composer require lesstif/php-jira-rest-client dev-master
```

create config.jira.php file on your project root.
````php
<?php

function getConfig() {
return array(
// JIRA Host config
'host' => 'https://jira.example.com',
'username' => 'username',
'password' => 'password',

// Options
'CURLOPT_SSL_VERIFYHOST' => false,
'CURLOPT_SSL_VERIFYPEER' => false,
'CURLOPT_VERBOSE' => true,
'LOG_FILE' => 'jira-rest-client.log',
'LOG_LEVEL' => 'DEBUG'
);
create config.jira.json file on your project root.
````json
{
"host": "https://jira.example.com",
"username": "username",
"password": "password",
"CURLOPT_SSL_VERIFYHOST": false,
"CURLOPT_SSL_VERIFYPEER": false,
"CURLOPT_VERBOSE": false,
"LOG_FILE": "jira-rest-client.log",
"LOG_LEVEL": "DEBUG"
}

?>
````

# Usage
Expand All @@ -35,7 +26,6 @@ function getConfig() {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Project\ProjectService;

Expand All @@ -55,7 +45,6 @@ try {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Project\ProjectService;

Expand All @@ -81,7 +70,6 @@ try {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
try {
Expand All @@ -102,7 +90,6 @@ try {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
Expand Down Expand Up @@ -135,7 +122,6 @@ try {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
Expand All @@ -157,7 +143,6 @@ try {
````php
<?php
require 'vendor/autoload.php';
require_once 'config.jira.php';

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"require": {
"php": ">=5.4.0",
"netresearch/jsonmapper": "0.4.*",
"monolog/monolog": "~1.12"
"monolog/monolog": "~1.12",
"noodlehaus/config": "0.7.*"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
Expand Down
4 changes: 0 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Jira Rest API Test Suite">
<!--
<directory>tests/</directory>
-->
<file>tests/ProjectTest.php</file>
<file>tests/IssueTest.php</file>
</testsuite>
</testsuites>

Expand Down
37 changes: 17 additions & 20 deletions src/JiraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class JIRAException extends \Exception { }
use \Monolog\Logger as Logger;
use \Monolog\Handler\StreamHandler;

use \Noodlehaus\Config as Config;

/**
* interact jira server with REST API
*/
Expand Down Expand Up @@ -43,8 +45,8 @@ class JiraClient {
// debug curl
protected $CURLOPT_VERBOSE = false;

protected $LOG_FILE = 'jira-rest-client.log';
protected $LOG_LEVEL = Logger::INFO;
protected $LOG_FILE;
protected $LOG_LEVEL;

private function convertLogLevel($log_level) {
if ($log_level == 'DEBUG')
Expand Down Expand Up @@ -75,29 +77,24 @@ protected function filterNullVariable($haystack)
return $haystack;
}

public function __construct($config)
{
public function __construct()
{
$config = Config::load('config.jira.json');

$this->json_mapper = new \JsonMapper();
$this->json_mapper->bExceptionOnUndefinedProperty = true;

$this->host = $config['host'];
$this->username = $config['username'];
$this->password = $config['password'];

if (isset($config['CURLOPT_SSL_VERIFYHOST']))
$this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === true ? true: false;

if (isset($config['CURLOPT_SSL_VERIFYPEER']))
$this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === true ? true: false;
$this->CURLOPT_SSL_VERIFYHOST = $config->get('CURLOPT_SSL_VERIFYHOST', false);

if (isset($config['CURLOPT_VERBOSE']))
$this->CURLOPT_VERBOSE = $config['CURLOPT_VERBOSE'] === true ? true: false;
$this->CURLOPT_SSL_VERIFYPEER = $config->get('CURLOPT_SSL_VERIFYPEER', false);
$this->CURLOPT_VERBOSE = $config->get('CURLOPT_VERBOSE', false);

if (isset($config['LOG_FILE']))
$this->LOG_FILE = $config['LOG_FILE'];

if (isset($config['LOG_LEVEL']))
$this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']);
$this->LOG_FILE = $config->get('LOG_FILE', 'jira-rest-client.log');
$this->LOG_LEVEL = $this->convertLogLevel($config->get('LOG_LEVEL', Logger::INFO));

// create logger
$this->log = new Logger('JiraClient');
Expand Down Expand Up @@ -193,11 +190,11 @@ public function upload($context, $upload_file) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);

/*
$attachments = array(
'file' => '@' . realpath($upload_file)
);
/* CURLFile support PHP 5.5
$cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file);
$this->log->addDebug('CURLFile=' . var_export($cf, true));
*/

$attachments = realpath($upload_file);
$filename = basename($upload_file);

Expand Down
10 changes: 10 additions & 0 deletions src/config.jira.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"host": "https://jira.example.com",
"username": "username",
"password": "password",
"CURLOPT_SSL_VERIFYHOST": false,
"CURLOPT_SSL_VERIFYPEER": false,
"CURLOPT_VERBOSE": false,
"LOG_FILE": "jira-rest-client.log",
"LOG_LEVEL": "DEBUG"
}
2 changes: 1 addition & 1 deletion src/issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class IssueService extends \JiraRestApi\JiraClient {
private $uri = "/issue";

public function __construct() {
parent::__construct(getConfig());
parent::__construct();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectService extends \JiraRestApi\JiraClient {
private $uri = "/project";

public function __construct() {
parent::__construct(getConfig());
parent::__construct();
}

/**
Expand Down
38 changes: 2 additions & 36 deletions tests/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use JiraRestApi\Issue\IssueService;
use JiraRestApi\Issue\IssueField;
use JiraRestApi\Issue\Comment;

class IssueTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -29,7 +28,6 @@ public function testIssue()

public function testCreateIssue()
{
$this->markTestIncomplete();
try {
$issueField = new IssueField();

Expand Down Expand Up @@ -63,8 +61,7 @@ public function testCreateIssue()
*
*/
public function testAddAttachment($issueKey)
{
$this->markTestIncomplete();
{
try {

$issueService = new IssueService();
Expand All @@ -85,7 +82,7 @@ public function testAddAttachment($issueKey)
*/
public function testUpdateIssue($issueKey)
{
$this->markTestIncomplete();
//$this->markTestIncomplete();
try {
$issueField = new IssueField(true);

Expand All @@ -102,42 +99,11 @@ public function testUpdateIssue($issueKey)
$issueService = new IssueService();

$issueService->update($issueKey, $issueField);

return $issueKey;
} catch (JIRAException $e) {
$this->assertTrue(FALSE, "update Failed : " . $e->getMessage());
}
}

/**
* Depends testUpdateIssue
*
*/
public function testAddcommnet()
{
$issueKey = "TEST-924";
//$this->markTestIncomplete();
try {
$comment = new Comment();

$body = <<<COMMENT
Adds a new comment to an issue.
* Bullet 1
* Bullet 2
** sub Bullet 1
** sub Bullet 2
COMMENT;
$comment->setBody($body)
->setVisibility('role', 'Users');
;

$issueService = new IssueService();
$ret = $issueService->addComment($issueKey, $comment);
print_r($ret);
} catch (JIRAException $e) {
$this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage());
}
}
}

?>
1 change: 0 additions & 1 deletion tests/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function testGetProjectLists()

$prjs = $proj->getAllProjects();

$i = 0;
foreach ($prjs as $p) {
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
$p->key, $p->id, $p->name, $p->projectCategory['name']
Expand Down
4 changes: 1 addition & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
$loader = require __DIR__ . "/../vendor/autoload.php";
$loader->addPsr4('JiraRestApi\\', __DIR__);

require_once __DIR__ . '/../config.jira.php';

date_default_timezone_set('UTC');

?>
?>

0 comments on commit 5b4384e

Please sign in to comment.