Skip to content

Commit b19958a

Browse files
committed
add attachment impl...
1 parent cbe36cd commit b19958a

File tree

3 files changed

+15
-55
lines changed

3 files changed

+15
-55
lines changed

src/JiraClient.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,22 @@ public function exec($context, $post_data = null, $custom_request = null) {
155155
/**
156156
* file upload
157157
*
158+
* @param context url context
159+
* @param upload_file upload file.
160+
*
161+
* @todo multiple file upload suppport.
162+
*
158163
*/
159-
public function upload($context, $file_list) {
164+
public function upload($context, $upload_file) {
160165
$url = $this->host . $this->api_uri . '/' . preg_replace('/\//', '', $context, 1);
161166

162167
$ch=curl_init();
163168
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
164-
curl_setopt($ch, CURLOPT_URL, $url);
165-
166-
$attachments = array();
167-
168-
$i = 0;
169-
foreach ($file_list as $f) {
170-
$attachments[$i] = array(
171-
'file' => '@' . realpath($f)
172-
);
173-
}
169+
curl_setopt($ch, CURLOPT_URL, $url);
174170

175-
var_dump($attachments);
176-
flush();
171+
$attachments = array(
172+
'file' => '@' . realpath($upload_file)
173+
);
177174

178175
// send file
179176
curl_setopt($ch, CURLOPT_POST, true);

src/issue/IssueService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public function create($issueField) {
5959
* Add one or more file to an issue
6060
*
6161
* @param issueIdOrKey Issue id or key
62-
* @param fileList attachment file array
62+
* @param filePath attachment file.
6363
*
6464
* @return
6565
*/
66-
public function addAttachments($issueIdOrKey, $fileList) {
66+
public function addAttachments($issueIdOrKey, $filePath) {
6767

6868
$this->log->addInfo("addAttachments=\n");
6969

70-
$ret = $this->upload($this->uri . "/$issueIdOrKey/attachments", $fileList);
70+
$ret = $this->upload($this->uri . "/$issueIdOrKey/attachments", $filePath);
7171

7272
$issue = $this->json_mapper->map(
7373
json_decode($ret), new Issue()

tests/IssueTest.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,53 +60,16 @@ public function testAddAttachment()
6060
{
6161
$this->markTestIncomplete();
6262
try {
63-
$fileList = array(
64-
'screen_capture.png',
65-
'bug-description.pdf'
66-
);
67-
63+
6864
$issueService = new IssueService();
6965

70-
$ret = $issueService->addAttachments("TEST-879", $fileList);
71-
72-
print_r($ret);
73-
} catch (JIRAException $e) {
74-
$this->assertTrue(FALSE, "Attach Failed : " . $e->getMessage());
75-
}
76-
}
77-
78-
79-
static function addAttachments($issueIdOrKey, $fileList) {
80-
$c = new IssueService();
66+
$ret = $issueService->addAttachments("TEST-879", 'screen_capture.png');
8167

82-
$ret = $c->upload("/issue/$issueIdOrKey/attachments", $fileList);
83-
84-
$issue = $c->json_mapper->map(
85-
json_decode($ret), new Issue()
86-
);
87-
88-
return $issue;
89-
}
90-
91-
public function testRefection()
92-
{
93-
//$this->markTestIncomplete();
94-
try {
95-
$fileList = array(
96-
'screen_capture.png',
97-
'bug-description.pdf'
98-
);
99-
100-
$this->addAttachments("TEST-879", $fileList);
101-
10268
print_r($ret);
10369
} catch (JIRAException $e) {
10470
$this->assertTrue(FALSE, "Attach Failed : " . $e->getMessage());
10571
}
10672
}
107-
108-
109-
11073
}
11174

11275
?>

0 commit comments

Comments
 (0)