diff --git a/SourceGitphp/LICENSE b/SourceGitphp/LICENSE new file mode 100644 index 000000000..ab2c13220 --- /dev/null +++ b/SourceGitphp/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2012 John Reese + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + diff --git a/SourceGitphp/SourceGitphp.php b/SourceGitphp/SourceGitphp.php new file mode 100644 index 000000000..9f614d85d --- /dev/null +++ b/SourceGitphp/SourceGitphp.php @@ -0,0 +1,367 @@ +name = plugin_lang_get( 'title' ); + $this->description = plugin_lang_get( 'description' ); + + $this->version = '0.10'; + $this->requires = array( + 'MantisCore' => '1.2.0', + 'Source' => '0.16', + ); + + $this->author = 'John Reese'; + $this->contact = 'john@noswap.com'; + $this->url = 'http://noswap.com'; + } + + public $type = 'gitphp'; + + public function show_type() { + return plugin_lang_get( 'gitphp' ); + } + + 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"; + } + + public function show_file( $p_repo, $p_changeset, $p_file ) { + return "$p_file->action - $p_file->filename"; + } + + private function uri_base( $p_repo ) { + $t_uri_base = $p_repo->info['gitphp_root'] . '?p=' . $p_repo->info['gitphp_project'] . '&'; + return $t_uri_base; + } + + public function url_repo( $p_repo, $t_changeset=null ) { + return $this->uri_base( $p_repo ) . ( $t_changeset ? 'h=' . $t_changeset->revision : '' ); + } + + public function url_changeset( $p_repo, $p_changeset ) { + return $this->uri_base( $p_repo ) . 'a=commitdiff&h=' . $p_changeset->revision; + } + + 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; + } + + 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 . '&hp=' . $p_changeset->parent; + } + + public function update_repo_form( $p_repo ) { + $t_gitphp_root = null; + $t_gitphp_project = null; + + if ( isset( $p_repo->info['gitphp_root'] ) ) { + $t_gitphp_root = $p_repo->info['gitphp_root']; + } + + if ( isset( $p_repo->info['gitphp_project'] ) ) { + $t_gitphp_project = $p_repo->info['gitphp_project']; + } + + if ( isset( $p_repo->info['master_branch'] ) ) { + $t_master_branch = $p_repo->info['master_branch']; + } else { + $t_master_branch = 'master'; + } +?> +> + + + +> + + + +> + + + +info['gitphp_root'] = $f_gitphp_root; + $p_repo->info['gitphp_project'] = $f_gitphp_project; + $p_repo->info['master_branch'] = $f_master_branch; + + return $p_repo; + } + + public function precommit( ) { + # TODO: Implement real commit sequence. + return; + } + + public function commit( $p_repo, $p_data ) { + # Handle branch names with '+' character + $p_data = str_replace('_plus_', '+', $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) = explode(' ', $p_data); + list ( , , $t_branch) = explode('/', $t_branch, 3); + + # master_branch contains comma-separated list of branches + $t_branches = explode(',', $p_repo->info['master_branch']); + if (!in_array('*', $t_branches) and !in_array($t_branch, $t_branches)) + { + return; + } + + return $this->import_commits($p_repo, null, $t_commit_id, $t_branch); + } + + public function import_full( $p_repo ) { + echo '
';
+		$t_branch = $p_repo->info['master_branch'];
+		if ( is_blank( $t_branch ) ) {
+			$t_branch = 'master';
+		}
+
+		if ($t_branch != '*')
+		{
+			$t_branches = array_map( 'trim', explode( ',', $t_branch ) );
+		}
+		else
+		{
+			$t_heads_url = $this->uri_base( $p_repo ) . 'a=heads';
+			$t_branches_input = url_get( $t_heads_url );
+
+			$t_branches_input = str_replace( array("\r", "\n", '<', '>', ' '), array('', '', '<', '>', ' '), $t_branches_input );
+
+			$t_branches_input_p1 = strpos( $t_branches_input, '' );
+			$t_branches_input_p2 = strpos( $t_branches_input, '
' ); + + if ( false === $t_input_p1 ) { + $t_input_p1 = strpos( $t_input, '' ); + if ( false === $t_input_p1 ) { + $t_input_p1 = strpos( $t_input, '' ); + } + } + + $t_input_p2 = strpos( $t_input, '.*?.*?.*?.*?(.*?)<.*#mx', $t_gitphp_data, $t_matches ) ) { + foreach( $t_matches[1] as $t_match ) { + $t_parents[] = $t_commit['parent'] = $t_match; + } + } + + # Strip ref links and signoff spans from commit message + $t_commit['message'] = preg_replace( array( '#]*>([^<]*)#', '#]*>(.*?)#' ), + '$1', $t_commit['message'] ); + + # Prepend a # sign to mantis number + $t_commit['message'] = preg_replace( '#(mantis)\s+(\d+)#i', '$1 #$2',$t_commit['message'] ); + + # Parse for changed file data + $t_commit['files'] = array(); + + preg_match_all( '#class="list".*?h=(\w*).*?f=(.*?)".*?<.a>#', + $t_gitphp_files, $t_matches, PREG_SET_ORDER ); + + foreach( $t_matches as $t_file_matches ) { + $t_file = array(); + $t_file['filename'] = str_replace('%2F', '/', $t_file_matches[2]); + $t_file['revision'] = $t_file_matches[1]; + + if ( isset( $t_file_matches[3] ) ) { + if ( $t_file_matches[3] == 'new' or $t_file_matches[3] == 'moved' ) { + $t_file['action'] = 'add'; + } else if ( $t_file_matches[3] == 'deleted' or $t_file_matches[3] == 'similarity' ) { + $t_file['action'] = 'rm'; + } else { + $t_file['action'] = 'mod'; + } + } else { + $t_file['action'] = 'mod'; + } + + $t_commit['files'][] = $t_file; + } + + $t_changeset = new SourceChangeset( $p_repo->id, $t_commit['revision'], $p_branch, + $t_commit['date'], $t_commit['author'], $t_commit['message'], 0, + ( isset( $t_commit['parent'] ) ? $t_commit['parent'] : '' ) ); + + $t_changeset->author_email = $t_commit['author_email']; + $t_changeset->committer = $t_commit['committer']; + $t_changeset->committer_email = $t_commit['committer_email']; + + foreach( $t_commit['files'] as $t_file ) { + $t_changeset->files[] = new SourceFile( 0, $t_file['revision'], $t_file['filename'], $t_file['action'] ); + } + + $t_changeset->save(); + + echo "saved.\n"; + return array( $t_changeset, $t_parents ); + } else { + echo "already exists.\n"; + return array( null, array() ); + } + } +} diff --git a/SourceGitphp/lang/strings_catalan.txt b/SourceGitphp/lang/strings_catalan.txt new file mode 100644 index 000000000..5d91774a6 --- /dev/null +++ b/SourceGitphp/lang/strings_catalan.txt @@ -0,0 +1,13 @@ +(incloent ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Branques principals
(llista separada per comes)'; diff --git a/SourceGitphp/lang/strings_english.txt b/SourceGitphp/lang/strings_english.txt new file mode 100644 index 000000000..b330ffd9a --- /dev/null +++ b/SourceGitphp/lang/strings_english.txt @@ -0,0 +1,13 @@ +(including ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Primary Branches
(comma-separated list)'; diff --git a/SourceGitphp/lang/strings_german.txt b/SourceGitphp/lang/strings_german.txt new file mode 100644 index 000000000..ce5a282d3 --- /dev/null +++ b/SourceGitphp/lang/strings_german.txt @@ -0,0 +1,13 @@ +(inkl. ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Hauptzweige
(kommaseparierte Liste)'; diff --git a/SourceGitphp/lang/strings_russian.txt b/SourceGitphp/lang/strings_russian.txt new file mode 100644 index 000000000..ac93c43ff --- /dev/null +++ b/SourceGitphp/lang/strings_russian.txt @@ -0,0 +1,13 @@ +(включая ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Главные ветки
(список разделенный запятыми)'; diff --git a/SourceGitphp/lang/strings_spanish.txt b/SourceGitphp/lang/strings_spanish.txt new file mode 100644 index 000000000..e502b47a2 --- /dev/null +++ b/SourceGitphp/lang/strings_spanish.txt @@ -0,0 +1,13 @@ +(incluyendo ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Ramas principales
(lista separada por comas)'; diff --git a/SourceGitphp/post-receive.tmpl b/SourceGitphp/post-receive.tmpl new file mode 100644 index 000000000..03a1add6e --- /dev/null +++ b/SourceGitphp/post-receive.tmpl @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copyright (c) 2012 John Reese +# Licensed under the MIT license + +read LINE + +# Handle branch names with '+' character +LINE=`echo $LINE | sed -e 's/+/_plus_/g'` + +LINE=`echo $LINE | sed -e 's/ /+/g'` + +URL="http://localhost/mantisbt/plugin.php?page=Source/checkin" +PROJECT="test" +API_KEY="test" + +CURL=/usr/bin/curl + +echo "Updating Changeset to Mantis Bug Tracker" +${CURL} -sS -d "api_key=${API_KEY}" -d "repo_name=${PROJECT}" -d "data=${LINE}" ${URL}
([a-f0-9]*)#', $t_gitphp_data, $t_matches ); + + $t_commit['revision'] = $t_matches[1]; + + echo "processing $t_commit[revision] ... \n"; + + if ( !SourceChangeset::exists( $p_repo->id, $t_commit['revision'] ) ) { + + # Parse for commit data + # m modifier means "make . include newlines" + # x modifier means "ignore whitespace" + preg_match( '#author(.*?)<.*?(.*?)<.*?committer(.*?)<.*(.*?).*#mx', + $t_gitphp_data, $t_matches ); + + $t_commit['author'] = $t_matches[1]; + # gitphp doesn't parse email address for some reason? + $t_commit['author_email'] = "n/a"; + $t_commit['date'] = date( 'Y-m-d H:i:s', strtotime( $t_matches[2] ) ); + $t_commit['committer'] = $t_matches[3]; + $t_commit['committer_email'] = "n/a"; + $t_commit['message'] = trim( preg_replace( '##', PHP_EOL, $t_matches[4] ) ); + + $t_parents = array(); + + if ( preg_match_all( '#parent