10 defined(
'JPATH_PLATFORM') or die;
36 public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = null)
39 $path =
'/repos/' . $user .
'/' . $repo .
'/issues';
44 $labels = array_values($labels);
51 'assignee' => $assignee,
52 'milestone' => $milestone,
59 $response = $this->client->post($this->fetchUrl($path), $data);
62 if ($response->code != 201)
65 $error = json_decode($response->body);
66 throw new DomainException($error->message, $response->code);
69 return json_decode($response->body);
84 public function createComment($user, $repo, $issueId, $body)
87 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/' . (int) $issueId .
'/comments';
97 $response = $this->client->post($this->fetchUrl($path), $data);
100 if ($response->code != 201)
103 $error = json_decode($response->body);
104 throw new DomainException($error->message, $response->code);
107 return json_decode($response->body);
122 public function createLabel($user, $repo, $name, $color)
125 $path =
'/repos/' . $user .
'/' . $repo .
'/labels';
136 $response = $this->client->post($this->fetchUrl($path), $data);
139 if ($response->code != 201)
142 $error = json_decode($response->body);
143 throw new DomainException($error->message, $response->code);
146 return json_decode($response->body);
160 public function deleteComment($user, $repo, $commentId)
163 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/comments/' . (int) $commentId;
166 $response = $this->client->delete($this->fetchUrl($path));
169 if ($response->code != 204)
172 $error = json_decode($response->body);
173 throw new DomainException($error->message, $response->code);
188 public function deleteLabel($user, $repo, $label)
191 $path =
'/repos/' . $user .
'/' . $repo .
'/labels/' . $label;
194 $response = $this->client->delete($this->fetchUrl($path));
197 if ($response->code != 204)
200 $error = json_decode($response->body);
201 throw new DomainException($error->message, $response->code);
222 public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = null)
225 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/' . (int) $issueId;
228 $data =
new stdClass;
233 $data->title = $title;
245 $data->state = $state;
249 if (isset($assignee))
251 $data->assignee = $assignee;
255 if (isset($milestone))
257 $data->milestone = $milestone;
266 $labels = array_values($labels);
269 $data->labels = $labels;
273 $data = json_encode($data);
276 $response = $this->client->patch($this->fetchUrl($path), $data);
279 if ($response->code != 200)
282 $error = json_decode($response->body);
283 throw new DomainException($error->message, $response->code);
286 return json_decode($response->body);
301 public function editComment($user, $repo, $commentId, $body)
304 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/comments/' . (int) $commentId;
314 $response = $this->client->patch($this->fetchUrl($path), $data);
317 if ($response->code != 200)
320 $error = json_decode($response->body);
321 throw new DomainException($error->message, $response->code);
324 return json_decode($response->body);
340 public function editLabel($user, $repo, $label, $name, $color)
343 $path =
'/repos/' . $user .
'/' . $repo .
'/labels/' . $label;
354 $response = $this->client->patch($this->fetchUrl($path), $data);
357 if ($response->code != 200)
360 $error = json_decode($response->body);
361 throw new DomainException($error->message, $response->code);
364 return json_decode($response->body);
378 public function get($user, $repo, $issueId)
381 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/' . (int) $issueId;
384 $response = $this->client->get($this->fetchUrl($path));
387 if ($response->code != 200)
390 $error = json_decode($response->body);
391 throw new DomainException($error->message, $response->code);
394 return json_decode($response->body);
408 public function getComment($user, $repo, $commentId)
411 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/comments/' . (int) $commentId;
414 $response = $this->client->get($this->fetchUrl($path));
417 if ($response->code != 200)
420 $error = json_decode($response->body);
421 throw new DomainException($error->message, $response->code);
424 return json_decode($response->body);
440 public function getComments($user, $repo, $issueId, $page = 0, $limit = 0)
443 $path =
'/repos/' . $user .
'/' . $repo .
'/issues/' . (int) $issueId .
'/comments';
446 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
449 if ($response->code != 200)
452 $error = json_decode($response->body);
453 throw new DomainException($error->message, $response->code);
456 return json_decode($response->body);
470 public function getLabel($user, $repo, $name)
473 $path =
'/repos/' . $user .
'/' . $repo .
'/labels/' . $name;
476 $response = $this->client->get($this->fetchUrl($path));
479 if ($response->code != 200)
482 $error = json_decode($response->body);
483 throw new DomainException($error->message, $response->code);
486 return json_decode($response->body);
499 public function getLabels($user, $repo)
502 $path =
'/repos/' . $user .
'/' . $repo .
'/labels';
505 $response = $this->client->get($this->fetchUrl($path));
508 if ($response->code != 200)
511 $error = json_decode($response->body);
512 throw new DomainException($error->message, $response->code);
515 return json_decode($response->body);
534 public function getList($filter = null, $state = null, $labels = null, $sort = null, $direction = null,
JDate $since = null, $page = 0, $limit = 0)
542 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
545 if ($response->code != 200)
548 $error = json_decode($response->body);
549 throw new DomainException($error->message, $response->code);
552 return json_decode($response->body);
575 public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null,
576 $sort = null, $direction = null,
JDate $since = null, $page = 0, $limit = 0)
579 $path =
'/repos/' . $user .
'/' . $repo .
'/issues';
581 $uri =
new JUri($this->fetchUrl($path, $page, $limit));
585 $uri->setVar(
'milestone', $milestone);
590 $uri->setVar(
'state', $state);
595 $uri->setVar(
'assignee', $assignee);
600 $uri->setVar(
'mentioned', $mentioned);
605 $uri->setVar(
'labels', $labels);
610 $uri->setVar(
'sort', $sort);
615 $uri->setVar(
'direction', $direction);
620 $uri->setVar(
'since', $since->toISO8601());
624 $response = $this->client->get((
string) $uri);
627 if ($response->code != 200)
630 $error = json_decode($response->body);
631 throw new DomainException($error->message, $response->code);
634 return json_decode($response->body);