@@ -12,6 +12,11 @@ class SourceBitBucketPlugin extends MantisSourceGitBasePlugin {
1212 const PLUGIN_VERSION = '2.2.0 ' ;
1313 const FRAMEWORK_VERSION_REQUIRED = '2.5.0 ' ;
1414
15+ /**
16+ * Error constants
17+ */
18+ const ERROR_BITBUCKET_API = 'bitbucket_api ' ;
19+
1520 protected $ main_url = "https://bitbucket.org/ " ;
1621 protected $ api_url = 'https://bitbucket.org/api/2.0/ ' ;
1722
@@ -26,6 +31,18 @@ public function register() {
2631 $ this ->contact = 'sergey@mzsl.ru ' ;
2732 }
2833
34+ function errors () {
35+ $ t_errors_list = array (
36+ self ::ERROR_BITBUCKET_API ,
37+ );
38+
39+ foreach ( $ t_errors_list as $ t_error ) {
40+ $ t_errors [$ t_error ] = plugin_lang_get ( 'error_ ' . $ t_error );
41+ }
42+
43+ return array_merge ( parent ::errors (), $ t_errors );
44+ }
45+
2946 public function show_type () {
3047 return plugin_lang_get ( 'bitbucket ' );
3148 }
@@ -201,7 +218,12 @@ private function api_url( $p_path ) {
201218
202219 private function api_json_url ( $ p_repo , $ p_url ) {
203220 $ t_data = $ this ->url_get ( $ p_repo , $ p_url );
204- return json_decode ( utf8_encode ( $ t_data ) );
221+ $ t_json = json_decode ( utf8_encode ( $ t_data ) );
222+ if ( json_last_error () != JSON_ERROR_NONE ) {
223+ error_parameters ( $ t_data );
224+ plugin_error ( self ::ERROR_BITBUCKET_API );
225+ }
226+ return $ t_json ;
205227 }
206228
207229 private function api_json_url_values ( $ p_repo , $ p_url ) {
@@ -342,7 +364,7 @@ public function import_commits( $p_repo, $p_commit_ids, $p_branch = '' ) {
342364 echo "Looking up target commit for $ t_branch ... " ;
343365 $ t_url = $ this ->api_url ( "repositories/ $ t_username/ $ t_reponame/refs/branches/ $ t_branch " );
344366 $ t_json = $ this ->api_json_url ( $ p_repo , $ t_url );
345- if ( false !== $ t_json ) {
367+ if ( null !== $ t_json ) {
346368 $ t_branch = $ t_json ->target ->hash ;
347369 }
348370 }
0 commit comments