10 defined(
'JPATH_PLATFORM') or die;
38 public function create($user, $repo, $title, $base, $head, $body =
'')
41 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls';
54 $response = $this->client->post($this->fetchUrl($path), $data);
57 if ($response->code != 201)
60 $error = json_decode($response->body);
61 throw new DomainException($error->message, $response->code);
64 return json_decode($response->body);
82 public function createComment($user, $repo, $pullId, $body, $commitId, $filePath, $position)
85 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/comments';
91 'commit_id' => $commitId,
93 'position' => $position
98 $response = $this->client->post($this->fetchUrl($path), $data);
101 if ($response->code != 201)
104 $error = json_decode($response->body);
105 throw new DomainException($error->message, $response->code);
108 return json_decode($response->body);
124 public function createCommentReply($user, $repo, $pullId, $body, $inReplyTo)
127 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/comments';
133 'in_reply_to' => (
int) $inReplyTo
138 $response = $this->client->post($this->fetchUrl($path), $data);
141 if ($response->code != 201)
144 $error = json_decode($response->body);
145 throw new DomainException($error->message, $response->code);
148 return json_decode($response->body);
167 public function createFromIssue($user, $repo, $issueId, $base, $head)
170 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls';
175 'issue' => (
int) $issueId,
182 $response = $this->client->post($this->fetchUrl($path), $data);
185 if ($response->code != 201)
188 $error = json_decode($response->body);
189 throw new DomainException($error->message, $response->code);
192 return json_decode($response->body);
206 public function deleteComment($user, $repo, $commentId)
209 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/comments/' . (int) $commentId;
212 $response = $this->client->delete($this->fetchUrl($path));
215 if ($response->code != 204)
218 $error = json_decode($response->body);
219 throw new DomainException($error->message, $response->code);
237 public function edit($user, $repo, $pullId, $title = null, $body = null, $state = null)
240 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId;
243 $data =
new stdClass;
248 $data->title = $title;
260 $data->state = $state;
264 $data = json_encode($data);
267 $response = $this->client->patch($this->fetchUrl($path), $data);
270 if ($response->code != 200)
273 $error = json_decode($response->body);
274 throw new DomainException($error->message, $response->code);
277 return json_decode($response->body);
292 public function editComment($user, $repo, $commentId, $body)
295 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/comments/' . (int) $commentId;
305 $response = $this->client->patch($this->fetchUrl($path), $data);
308 if ($response->code != 200)
311 $error = json_decode($response->body);
312 throw new DomainException($error->message, $response->code);
315 return json_decode($response->body);
329 public function get($user, $repo, $pullId)
332 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId;
335 $response = $this->client->get($this->fetchUrl($path));
338 if ($response->code != 200)
341 $error = json_decode($response->body);
342 throw new DomainException($error->message, $response->code);
345 return json_decode($response->body);
359 public function getComment($user, $repo, $commentId)
362 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/comments/' . (int) $commentId;
365 $response = $this->client->get($this->fetchUrl($path));
368 if ($response->code != 200)
371 $error = json_decode($response->body);
372 throw new DomainException($error->message, $response->code);
375 return json_decode($response->body);
391 public function getComments($user, $repo, $pullId, $page = 0, $limit = 0)
394 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/comments';
397 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
400 if ($response->code != 200)
403 $error = json_decode($response->body);
404 throw new DomainException($error->message, $response->code);
407 return json_decode($response->body);
423 public function getCommits($user, $repo, $pullId, $page = 0, $limit = 0)
426 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/commits';
429 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
432 if ($response->code != 200)
435 $error = json_decode($response->body);
436 throw new DomainException($error->message, $response->code);
439 return json_decode($response->body);
455 public function getFiles($user, $repo, $pullId, $page = 0, $limit = 0)
458 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/files';
461 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
464 if ($response->code != 200)
467 $error = json_decode($response->body);
468 throw new DomainException($error->message, $response->code);
471 return json_decode($response->body);
487 public function getList($user, $repo, $state =
'open', $page = 0, $limit = 0)
490 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls';
493 if ($state !=
'open')
495 $path .=
'?state=' . $state;
499 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
502 if ($response->code != 200)
505 $error = json_decode($response->body);
506 throw new DomainException($error->message, $response->code);
509 return json_decode($response->body);
523 public function isMerged($user, $repo, $pullId)
526 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/merge';
529 $response = $this->client->get($this->fetchUrl($path));
532 if ($response->code == 204)
536 elseif ($response->code == 404)
543 $error = json_decode($response->body);
544 throw new DomainException($error->message, $response->code);
560 public function merge($user, $repo, $pullId, $message =
'')
563 $path =
'/repos/' . $user .
'/' . $repo .
'/pulls/' . (int) $pullId .
'/merge';
568 'commit_message' => $message
573 $response = $this->client->put($this->fetchUrl($path), $data);
576 if ($response->code != 200)
579 $error = json_decode($response->body);
580 throw new DomainException($error->message, $response->code);
583 return json_decode($response->body);