Skip to content

Commit 5b4384e

Browse files
committed
Merge branch 'master' into feature/process_comment
Conflicts: tests/IssueTest.php
2 parents dec5cd1 + 7935b53 commit 5b4384e

File tree

10 files changed

+45
-93
lines changed

10 files changed

+45
-93
lines changed

README.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,18 @@
55
composer require lesstif/php-jira-rest-client dev-master
66
```
77

8-
create config.jira.php file on your project root.
9-
````php
10-
<?php
11-
12-
function getConfig() {
13-
return array(
14-
// JIRA Host config
15-
'host' => 'https://jira.example.com',
16-
'username' => 'username',
17-
'password' => 'password',
18-
19-
// Options
20-
'CURLOPT_SSL_VERIFYHOST' => false,
21-
'CURLOPT_SSL_VERIFYPEER' => false,
22-
'CURLOPT_VERBOSE' => true,
23-
'LOG_FILE' => 'jira-rest-client.log',
24-
'LOG_LEVEL' => 'DEBUG'
25-
);
8+
create config.jira.json file on your project root.
9+
````json
10+
{
11+
"host": "https://jira.example.com",
12+
"username": "username",
13+
"password": "password",
14+
"CURLOPT_SSL_VERIFYHOST": false,
15+
"CURLOPT_SSL_VERIFYPEER": false,
16+
"CURLOPT_VERBOSE": false,
17+
"LOG_FILE": "jira-rest-client.log",
18+
"LOG_LEVEL": "DEBUG"
2619
}
27-
28-
?>
2920
````
3021

3122
# Usage
@@ -35,7 +26,6 @@ function getConfig() {
3526
````php
3627
<?php
3728
require 'vendor/autoload.php';
38-
require_once 'config.jira.php';
3929

4030
use JiraRestApi\Project\ProjectService;
4131

@@ -55,7 +45,6 @@ try {
5545
````php
5646
<?php
5747
require 'vendor/autoload.php';
58-
require_once 'config.jira.php';
5948

6049
use JiraRestApi\Project\ProjectService;
6150

@@ -81,7 +70,6 @@ try {
8170
````php
8271
<?php
8372
require 'vendor/autoload.php';
84-
require_once 'config.jira.php';
8573

8674
use JiraRestApi\Issue\IssueService;
8775
try {
@@ -102,7 +90,6 @@ try {
10290
````php
10391
<?php
10492
require 'vendor/autoload.php';
105-
require_once 'config.jira.php';
10693

10794
use JiraRestApi\Issue\IssueService;
10895
use JiraRestApi\Issue\IssueField;
@@ -135,7 +122,6 @@ try {
135122
````php
136123
<?php
137124
require 'vendor/autoload.php';
138-
require_once 'config.jira.php';
139125

140126
use JiraRestApi\Issue\IssueService;
141127
use JiraRestApi\Issue\IssueField;
@@ -157,7 +143,6 @@ try {
157143
````php
158144
<?php
159145
require 'vendor/autoload.php';
160-
require_once 'config.jira.php';
161146

162147
use JiraRestApi\Issue\IssueService;
163148
use JiraRestApi\Issue\IssueField;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"require": {
77
"php": ">=5.4.0",
88
"netresearch/jsonmapper": "0.4.*",
9-
"monolog/monolog": "~1.12"
9+
"monolog/monolog": "~1.12",
10+
"noodlehaus/config": "0.7.*"
1011
},
1112
"require-dev": {
1213
"phpunit/phpunit": "~4.4"

phpunit.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
<phpunit bootstrap="tests/bootstrap.php" colors="true">
44
<testsuites>
55
<testsuite name="Jira Rest API Test Suite">
6-
<!--
76
<directory>tests/</directory>
8-
-->
9-
<file>tests/ProjectTest.php</file>
10-
<file>tests/IssueTest.php</file>
117
</testsuite>
128
</testsuites>
139

src/JiraClient.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class JIRAException extends \Exception { }
99
use \Monolog\Logger as Logger;
1010
use \Monolog\Handler\StreamHandler;
1111

12+
use \Noodlehaus\Config as Config;
13+
1214
/**
1315
* interact jira server with REST API
1416
*/
@@ -43,8 +45,8 @@ class JiraClient {
4345
// debug curl
4446
protected $CURLOPT_VERBOSE = false;
4547

46-
protected $LOG_FILE = 'jira-rest-client.log';
47-
protected $LOG_LEVEL = Logger::INFO;
48+
protected $LOG_FILE;
49+
protected $LOG_LEVEL;
4850

4951
private function convertLogLevel($log_level) {
5052
if ($log_level == 'DEBUG')
@@ -75,29 +77,24 @@ protected function filterNullVariable($haystack)
7577
return $haystack;
7678
}
7779

78-
public function __construct($config)
79-
{
80+
public function __construct()
81+
{
82+
$config = Config::load('config.jira.json');
83+
8084
$this->json_mapper = new \JsonMapper();
8185
$this->json_mapper->bExceptionOnUndefinedProperty = true;
8286

8387
$this->host = $config['host'];
8488
$this->username = $config['username'];
8589
$this->password = $config['password'];
8690

87-
if (isset($config['CURLOPT_SSL_VERIFYHOST']))
88-
$this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === true ? true: false;
89-
90-
if (isset($config['CURLOPT_SSL_VERIFYPEER']))
91-
$this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === true ? true: false;
91+
$this->CURLOPT_SSL_VERIFYHOST = $config->get('CURLOPT_SSL_VERIFYHOST', false);
9292

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

96-
if (isset($config['LOG_FILE']))
97-
$this->LOG_FILE = $config['LOG_FILE'];
98-
99-
if (isset($config['LOG_LEVEL']))
100-
$this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']);
96+
$this->LOG_FILE = $config->get('LOG_FILE', 'jira-rest-client.log');
97+
$this->LOG_LEVEL = $this->convertLogLevel($config->get('LOG_LEVEL', Logger::INFO));
10198

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

196-
/*
197-
$attachments = array(
198-
'file' => '@' . realpath($upload_file)
199-
);
193+
/* CURLFile support PHP 5.5
194+
$cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file);
195+
$this->log->addDebug('CURLFile=' . var_export($cf, true));
200196
*/
197+
201198
$attachments = realpath($upload_file);
202199
$filename = basename($upload_file);
203200

src/config.jira.example.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"host": "https://jira.example.com",
3+
"username": "username",
4+
"password": "password",
5+
"CURLOPT_SSL_VERIFYHOST": false,
6+
"CURLOPT_SSL_VERIFYPEER": false,
7+
"CURLOPT_VERBOSE": false,
8+
"LOG_FILE": "jira-rest-client.log",
9+
"LOG_LEVEL": "DEBUG"
10+
}

src/issue/IssueService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class IssueService extends \JiraRestApi\JiraClient {
66
private $uri = "/issue";
77

88
public function __construct() {
9-
parent::__construct(getConfig());
9+
parent::__construct();
1010
}
1111

1212
/**

src/project/ProjectService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProjectService extends \JiraRestApi\JiraClient {
66
private $uri = "/project";
77

88
public function __construct() {
9-
parent::__construct(getConfig());
9+
parent::__construct();
1010
}
1111

1212
/**

tests/IssueTest.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use JiraRestApi\Issue\IssueService;
44
use JiraRestApi\Issue\IssueField;
5-
use JiraRestApi\Issue\Comment;
65

76
class IssueTest extends PHPUnit_Framework_TestCase
87
{
@@ -29,7 +28,6 @@ public function testIssue()
2928

3029
public function testCreateIssue()
3130
{
32-
$this->markTestIncomplete();
3331
try {
3432
$issueField = new IssueField();
3533

@@ -63,8 +61,7 @@ public function testCreateIssue()
6361
*
6462
*/
6563
public function testAddAttachment($issueKey)
66-
{
67-
$this->markTestIncomplete();
64+
{
6865
try {
6966

7067
$issueService = new IssueService();
@@ -85,7 +82,7 @@ public function testAddAttachment($issueKey)
8582
*/
8683
public function testUpdateIssue($issueKey)
8784
{
88-
$this->markTestIncomplete();
85+
//$this->markTestIncomplete();
8986
try {
9087
$issueField = new IssueField(true);
9188

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

104101
$issueService->update($issueKey, $issueField);
105-
106-
return $issueKey;
107102
} catch (JIRAException $e) {
108103
$this->assertTrue(FALSE, "update Failed : " . $e->getMessage());
109104
}
110105
}
111106

112-
/**
113-
* Depends testUpdateIssue
114-
*
115-
*/
116-
public function testAddcommnet()
117-
{
118-
$issueKey = "TEST-924";
119-
//$this->markTestIncomplete();
120-
try {
121-
$comment = new Comment();
122-
123-
$body = <<<COMMENT
124-
Adds a new comment to an issue.
125-
* Bullet 1
126-
* Bullet 2
127-
** sub Bullet 1
128-
** sub Bullet 2
129-
COMMENT;
130-
$comment->setBody($body)
131-
->setVisibility('role', 'Users');
132-
;
133-
134-
$issueService = new IssueService();
135-
$ret = $issueService->addComment($issueKey, $comment);
136-
print_r($ret);
137-
} catch (JIRAException $e) {
138-
$this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage());
139-
}
140-
}
141107
}
142108

143109
?>

tests/ProjectTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function testGetProjectLists()
2929

3030
$prjs = $proj->getAllProjects();
3131

32-
$i = 0;
3332
foreach ($prjs as $p) {
3433
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
3534
$p->key, $p->id, $p->name, $p->projectCategory['name']

tests/bootstrap.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
$loader = require __DIR__ . "/../vendor/autoload.php";
1212
$loader->addPsr4('JiraRestApi\\', __DIR__);
1313

14-
require_once __DIR__ . '/../config.jira.php';
15-
1614
date_default_timezone_set('UTC');
1715

18-
?>
16+
?>

0 commit comments

Comments
 (0)