diff --git a/SourceGitweb/SourceGitweb.php b/SourceGitweb/SourceGitweb.php index 45a887a..54ef16f 100644 --- a/SourceGitweb/SourceGitweb.php +++ b/SourceGitweb/SourceGitweb.php @@ -18,7 +18,7 @@ require_once( config_get( 'core_path' ) . 'url_api.php' ); class SourceGitwebPlugin extends MantisSourcePlugin { - function register() { + public function register() { $this->name = plugin_lang_get( 'title' ); $this->description = plugin_lang_get( 'description' ); @@ -34,80 +34,48 @@ $this->url = 'http://leetcode.net'; } - function get_types( $p_event ) { - return array( 'gitweb' => plugin_lang_get( 'gitweb' ) ); + public $type = 'gitweb'; + + public function show_type() { + return plugin_lang_get( 'gitweb', 'SourceGitweb' ); } - function show_type( $p_event, $p_type ) { - if ( 'gitweb' == $p_type ) { - return plugin_lang_get( 'gitweb' ); - } - } - - function show_changeset( $p_event, $p_repo, $p_changeset ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function show_changeset( $p_repo, $p_changeset ) { $t_ref = substr( $p_changeset->revision, 0, 8 ); $t_branch = $p_changeset->branch; return "$t_branch $t_ref"; } - function show_file( $p_event, $p_repo, $p_changeset, $p_file ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function show_file( $p_repo, $p_changeset, $p_file ) { return "$p_file->action - $p_file->filename"; } - function uri_base( $p_repo ) { + private function uri_base( $p_repo ) { $t_uri_base = $p_repo->info['gitweb_root'] . '?p=' . $p_repo->info['gitweb_project'] . ';'; return $t_uri_base; } - function url_repo( $p_event, $p_repo, $t_changeset=null ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function url_repo( $p_repo, $t_changeset=null ) { return $this->uri_base( $p_repo ) . ( $t_changeset ? 'h=' . $t_changeset->revision : '' ); } - function url_changeset( $p_event, $p_repo, $p_changeset ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function url_changeset( $p_repo, $p_changeset ) { return $this->uri_base( $p_repo ) . 'a=commitdiff;h=' . $p_changeset->revision; } - function url_file( $p_event, $p_repo, $p_changeset, $p_file ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function url_file( $p_repo, $p_changeset, $p_file ) { return $this->uri_base( $p_repo ) . 'a=blob;f=' . $p_file->filename . ';h=' . $p_file->revision . ';hb=' . $p_changeset->revision; } - function url_diff( $p_event, $p_repo, $p_changeset, $p_file ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function url_diff( $p_repo, $p_changeset, $p_file ) { return $this->uri_base( $p_repo ) . 'a=blobdiff;f=' . $p_file->filename . ';h=' . $p_file->revision . ';hb=' . $p_changeset->revision . ';hpb=' . $p_changeset->parent; } - function update_repo_form( $p_event, $p_repo ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } - + public function update_repo_form( $p_repo ) { $t_gitweb_root = null; $t_gitweb_project = null; @@ -140,11 +108,7 @@ type ) { - return; - } - + public function update_repo( $p_repo ) { $f_gitweb_root = gpc_get_string( 'gitweb_root' ); $f_gitweb_project = gpc_get_string( 'gitweb_project' ); $f_master_branch = gpc_get_string( 'master_branch' ); @@ -156,34 +120,27 @@ return $p_repo; } - function precommit( $p_event ) { + public function precommit( ) { # TODO: Implement real commit sequence. return; } - function commit( $p_event, $p_repo, $p_data ) { - if ( 'gitweb' != $p_repo->type ) { - return; + public function commit( $p_repo, $p_data ) { + # The -d option from curl requires you to encode your own data. + # Once it reaches here it is decoded. Hence we split by a space + # were as the curl command uses a '+' character instead. + # i.e. DATA=`echo $INPUT | sed -e 's/ /+/g'` + list ( , $t_commit_id, $t_branch) = split(' ', $p_data); + list ( , , $t_branch) = split('/', $t_branch); + if ($t_branch != $p_repo->info['master_branch']) + { + return; } - # The -d option from curl requires you to encode your own data. - # Once it reaches here it is decoded. Hence we split by a space - # were as the curl command uses a '+' character instead. - # i.e. DATA=`echo $INPUT | sed -e 's/ /+/g'` - list ( , $t_commit_id, $t_branch) = split(' ', $p_data); - list ( , , $t_branch) = split('/', $t_branch); - if ($t_branch != $p_repo->info['master_branch']) - { - return; - } - - return $this->import_commits($p_repo, null, $t_commit_id, $t_branch); + return $this->import_commits($p_repo, null, $t_commit_id, $t_branch); } - function import_full( $p_event, $p_repo ) { - if ( 'gitweb' != $p_repo->type ) { - return; - } + public function import_full( $p_repo ) { echo '
';
 
 		$t_branch = $p_repo->info['master_branch'];
@@ -221,11 +178,11 @@
 		return $t_changesets;
 	}
 
-	function import_latest( $p_event, $p_repo ) {
-		return $this->import_full( $p_event, $p_repo );
+	public function import_latest( $p_repo ) {
+		return $this->import_full( $p_repo );
 	}
 
-	function import_commits( $p_repo, $p_uri_base, $p_commit_ids, $p_branch='' ) {
+	private function import_commits( $p_repo, $p_uri_base, $p_commit_ids, $p_branch='' ) {
 		static $s_parents = array();
 		static $s_counter = 0;
 
@@ -262,7 +219,7 @@
 		return $t_changesets;
 	}
 
-	function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
+	private function commit_changeset( $p_repo, $p_input, $p_branch='' ) {
 
 		$t_input = str_replace( array(PHP_EOL, '<', '>', ' '), array('', '<', '>', ' '), $p_input );