| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 1 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 5 | public function addAttachment(string $path, string $workItemId, string $projectId): Attachment |
|
| 24 | { |
||
| 25 | // First, upload the file |
||
| 26 | 5 | $response = $this->post( |
|
|
|
|||
| 27 | 5 | "{$projectId}/_apis/wit/attachments", |
|
| 28 | 5 | [ |
|
| 29 | 5 | 'headers' => ['Content-Type' => 'application/octet-stream'], |
|
| 30 | 5 | 'query' => ['fileName' => basename($path), 'api-version' => $this->apiVersion], |
|
| 31 | 5 | 'body' => fopen($path, 'r'), |
|
| 32 | 5 | ] |
|
| 33 | 5 | ); |
|
| 34 | |||
| 35 | // Second, attach it to the work item |
||
| 36 | 1 | $this->patch( |
|
| 37 | 1 | "{$projectId}/_apis/wit/workitems/{$workItemId}", |
|
| 38 | 1 | [ |
|
| 39 | 1 | 'headers' => ['Content-Type' => 'application/json-patch+json'], |
|
| 40 | 1 | 'json' => $this->toDevOpsAttachment($response['url']), |
|
| 41 | 1 | ] |
|
| 42 | 1 | ); |
|
| 43 | |||
| 44 | 1 | return $this->fromDevOpsAttachment($response); |
|
| 45 | } |
||
| 47 |