|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace GitHub\API\Issue; |
| 4 | + |
| 5 | +use GitHub\API\Api; |
| 6 | +use GitHub\API\ApiException; |
| 7 | +use GitHub\API\AuthenticationException; |
| 8 | + |
| 9 | +/** |
| 10 | + * Issue comment |
| 11 | + * |
| 12 | + * @link http://developer.github.com/v3/issues/comments/ |
| 13 | + * @author dsyph3r <d.syph.3r@gmail.com> |
| 14 | + */ |
| 15 | +class Comment extends Api |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Constant for GitHub resource mime type identifier |
| 19 | + * |
| 20 | + * @link http://developer.github.com/v3/issues/comments/#custom-mime-types |
| 21 | + */ |
| 22 | + const MIME_TYPE_RESOURCE = 'issuecomment'; |
| 23 | + |
| 24 | + /** |
| 25 | + * List comments for issue |
| 26 | + * |
| 27 | + * Authentication Required: false|true |
| 28 | + * |
| 29 | + * @link http://developer.github.com/v3/repos/issues/#list-comments-on-an-issue |
| 30 | + * |
| 31 | + * @param string $username User GitHub username |
| 32 | + * @param string $repo Repo name |
| 33 | + * @param int $issueId Id of issue |
| 34 | + * @param string $format Response format of comment |
| 35 | + * FORMAT_RAW|FORMAT_TEXT|FORMAT_HTML|FORMAT_FULL |
| 36 | + * @return array List of comments for issue or FALSE if |
| 37 | + * comments could not be retrieved for issue |
| 38 | + */ |
| 39 | + public function all($username, $repo, $issueId = null, $format = self::FORMAT_RAW) |
| 40 | + { |
| 41 | + $url = "repos/$username/$repo/issues/$issueId/comments"; |
| 42 | + |
| 43 | + return $this->processResponse( |
| 44 | + $this->requestGet($url, array(), $this->setResponseFormatOptions($format, self::MIME_TYPE_RESOURCE, array())) |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Get an issue comment |
| 50 | + * |
| 51 | + * Authentication Required: false|true |
| 52 | + * |
| 53 | + * @link http://developer.github.com/v3/repos/issues/#get-a-single-comment |
| 54 | + * |
| 55 | + * @param string $username User GitHub username |
| 56 | + * @param string $repo Repo name |
| 57 | + * @param int $id ID of comment |
| 58 | + * @param string $format Response format of comment |
| 59 | + * FORMAT_RAW|FORMAT_TEXT|FORMAT_HTML|FORMAT_FULL |
| 60 | + * @return array|bool Details of the comment or FALSE if the request failed |
| 61 | + */ |
| 62 | + public function get($username, $repo, $id, $format = self::FORMAT_RAW) |
| 63 | + { |
| 64 | + $options = $this->setResponseFormatOptions($format, self::MIME_TYPE_RESOURCE, array()); |
| 65 | + |
| 66 | + return $this->processResponse( |
| 67 | + $this->requestGet("repos/$username/$repo/issues/comments/$id", array(), $options) |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Create an issue comment |
| 73 | + * |
| 74 | + * Authentication Required: true |
| 75 | + * |
| 76 | + * @link http://developer.github.com/v3/repos/issues/#create-a-comment |
| 77 | + * |
| 78 | + * @param string $username User GitHub username |
| 79 | + * @param string $repo Repo name |
| 80 | + * @param int $issueId Id of issue |
| 81 | + * @param string $body The comment body |
| 82 | + * @param string $format Response format of comment |
| 83 | + * FORMAT_RAW|FORMAT_TEXT|FORMAT_HTML|FORMAT_FULL |
| 84 | + * @return array Details of the created comment or FALSE if |
| 85 | + * comment failed to create |
| 86 | + */ |
| 87 | + public function create($username, $repo, $issueId, $body, $format = self::FORMAT_RAW) |
| 88 | + { |
| 89 | + $details = array('body' => $body); |
| 90 | + |
| 91 | + $options = $this->setResponseFormatOptions($format, self::MIME_TYPE_RESOURCE, array()); |
| 92 | + |
| 93 | + return $this->processResponse( |
| 94 | + $this->requestPost("repos/$username/$repo/issues/$issueId/comments", $details, $options) |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Edit an issue comment |
| 100 | + * |
| 101 | + * Authentication Required: true |
| 102 | + * |
| 103 | + * @link http://developer.github.com/v3/repos/issues/#edit-a-comment |
| 104 | + * |
| 105 | + * @param string $username User GitHub username |
| 106 | + * @param string $repo Repo name |
| 107 | + * @param int $id ID of issue |
| 108 | + * @param string $body The comment body |
| 109 | + * @param string $format Response format of comment |
| 110 | + * FORMAT_RAW|FORMAT_TEXT|FORMAT_HTML|FORMAT_FULL |
| 111 | + * @return array Details of the updated comment or FALSE if |
| 112 | + * comment failed to update |
| 113 | + */ |
| 114 | + public function update($username, $repo, $id, $body, $format = self::FORMAT_RAW) |
| 115 | + { |
| 116 | + $details = array('body' => $body); |
| 117 | + |
| 118 | + $options = $this->setResponseFormatOptions($format, self::MIME_TYPE_RESOURCE, array()); |
| 119 | + |
| 120 | + return $this->processResponse( |
| 121 | + $this->requestPatch("repos/$username/$repo/issues/comments/$id", $details, $options) |
| 122 | + ); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Delete an issue comment |
| 127 | + * |
| 128 | + * Authentication Required: true |
| 129 | + * |
| 130 | + * @link http://developer.github.com/v3/repos/issues/#delete-a-comment |
| 131 | + * |
| 132 | + * @param string $username User GitHub username |
| 133 | + * @param string $repo Repo name |
| 134 | + * @param int $id ID of comment |
| 135 | + * @param bool Returns TRUE if issue comment was deleted |
| 136 | + */ |
| 137 | + public function delete($username, $repo, $id) |
| 138 | + { |
| 139 | + return $this->processResponse( |
| 140 | + $this->requestDelete("repos/$username/$repo/issues/comments/$id") |
| 141 | + ); |
| 142 | + } |
| 143 | +} |
0 commit comments