@@ -136,6 +136,35 @@ public function getDiffForPullRequest($user, $repo, $pullId)
136136 return $ this ->processResponse ($ this ->client ->get ($ prepared ['url ' ], $ prepared ['headers ' ]));
137137 }
138138
139+ /**
140+ * Get a file's contents from a repository.
141+ *
142+ * @param string $user The name of the owner of the GitHub repository.
143+ * @param string $repo The name of the GitHub repository.
144+ * @param string $path The content path.
145+ * @param string $ref The name of the commit/branch/tag. Default: the repository’s default branch (usually master)
146+ *
147+ * @return \JHttpResponse
148+ *
149+ * @since __DEPLOY_VERSION__
150+ */
151+ public function getFileContents ($ user , $ repo , $ path , $ ref = null )
152+ {
153+ $ path = "/repos/ $ user/ $ repo/contents/ $ path " ;
154+
155+ $ prepared = $ this ->prepareRequest ($ path );
156+
157+ if ($ ref )
158+ {
159+ $ url = new \JUri ($ prepared ['url ' ]);
160+ $ url ->setVar ('ref ' , $ ref );
161+
162+ $ prepared ['url ' ] = (string ) $ url ;
163+ }
164+
165+ return $ this ->processResponse ($ this ->client ->get ($ prepared ['url ' ], $ prepared ['headers ' ]));
166+ }
167+
139168 /**
140169 * Get the list of modified files for a pull request.
141170 *
@@ -152,7 +181,7 @@ public function getFilesForPullRequest($user, $repo, $pullId)
152181 // Build the request path.
153182 $ path = "/repos/ $ user/ $ repo/pulls/ " . (int ) $ pullId . '/files ' ;
154183
155- $ prepared = $ this ->prepareRequest ($ path, 0 , 0 );
184+ $ prepared = $ this ->prepareRequest ($ path );
156185
157186 return $ this ->processResponse ($ this ->client ->get ($ prepared ['url ' ], $ prepared ['headers ' ]));
158187 }
@@ -243,9 +272,10 @@ protected function processResponse(\JHttpResponse $response, $expectedCode = 200
243272 if ($ response ->code != $ expectedCode )
244273 {
245274 // Decode the error response and throw an exception.
246- $ body = json_decode ($ response ->body );
275+ $ body = json_decode ($ response ->body );
276+ $ error = isset ($ body ->error ) ? $ body ->error : (isset ($ body ->message ) ? $ body ->message : 'Unknown Error ' );
247277
248- throw new Exception \UnexpectedResponse ($ response , $ body -> error , $ response ->code );
278+ throw new Exception \UnexpectedResponse ($ response , $ error , $ response ->code );
249279 }
250280
251281 return $ response ;
0 commit comments