From d5997285c2736bee4e7e21222812e61e7d2fc863 Mon Sep 17 00:00:00 2001 From: Matt Janulewicz Date: Thu, 2 Feb 2017 20:47:15 -0800 Subject: [PATCH 1/3] Initial checkin of SourceGitphp on 1.2.x branch. --- SourceGitphp/LICENSE | 23 ++ SourceGitphp/SourceGitphp.php | 367 ++++++++++++++++++++++++++ SourceGitphp/lang/strings_catalan.txt | 13 + SourceGitphp/lang/strings_english.txt | 13 + SourceGitphp/lang/strings_german.txt | 13 + SourceGitphp/lang/strings_russian.txt | 13 + SourceGitphp/lang/strings_spanish.txt | 13 + SourceGitphp/post-receive.tmpl | 20 ++ 8 files changed, 475 insertions(+) create mode 100644 SourceGitphp/LICENSE create mode 100644 SourceGitphp/SourceGitphp.php create mode 100644 SourceGitphp/lang/strings_catalan.txt create mode 100644 SourceGitphp/lang/strings_english.txt create mode 100644 SourceGitphp/lang/strings_german.txt create mode 100644 SourceGitphp/lang/strings_russian.txt create mode 100644 SourceGitphp/lang/strings_spanish.txt create mode 100644 SourceGitphp/post-receive.tmpl 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..2c7c2126b --- /dev/null +++ b/SourceGitphp/SourceGitphp.php @@ -0,0 +1,367 @@ +name = plugin_lang_get( 'title' ); + $this->description = plugin_lang_get( 'description' ); + + $this->version = '0.18'; + $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..429d3db7d --- /dev/null +++ b/SourceGitphp/lang/strings_catalan.txt @@ -0,0 +1,13 @@ +(incloent ".git")'; +$s_plugin_SourceGitweb_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..8e01c8a3a --- /dev/null +++ b/SourceGitphp/lang/strings_german.txt @@ -0,0 +1,13 @@ +(inkl. ".git")'; +$s_plugin_SourceGitweb_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..b90a9ffb6 --- /dev/null +++ b/SourceGitphp/lang/strings_russian.txt @@ -0,0 +1,13 @@ +(включая ".git")'; +$s_plugin_SourceGitweb_master_branch = 'Главные ветки
(список разделенный запятыми)'; \ No newline at end of file diff --git a/SourceGitphp/lang/strings_spanish.txt b/SourceGitphp/lang/strings_spanish.txt new file mode 100644 index 000000000..9bc385a5f --- /dev/null +++ b/SourceGitphp/lang/strings_spanish.txt @@ -0,0 +1,13 @@ +(incluyendo ".git")'; +$s_plugin_SourceGitweb_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} From 129dfc1809623af7c4c4e8fdb4acebbfbb48a5da Mon Sep 17 00:00:00 2001 From: Matt Janulewicz Date: Thu, 2 Feb 2017 20:51:28 -0800 Subject: [PATCH 2/3] Updating Gitweb->Gitphp in language files. --- SourceGitphp/lang/strings_catalan.txt | 14 +++++++------- SourceGitphp/lang/strings_german.txt | 14 +++++++------- SourceGitphp/lang/strings_russian.txt | 14 +++++++------- SourceGitphp/lang/strings_spanish.txt | 14 +++++++------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/SourceGitphp/lang/strings_catalan.txt b/SourceGitphp/lang/strings_catalan.txt index 429d3db7d..5d91774a6 100644 --- a/SourceGitphp/lang/strings_catalan.txt +++ b/SourceGitphp/lang/strings_catalan.txt @@ -3,11 +3,11 @@ # Copyright (c) 2012 John Reese # Licensed under the MIT license -$s_plugin_SourceGitweb_ = ''; -$s_plugin_SourceGitweb_gitweb = 'Gitweb'; -$s_plugin_SourceGitweb_title = 'Integració Gitweb'; -$s_plugin_SourceGitweb_description = 'Afegeix la integració amb Gitweb al framework d\'Integració de Codi.'; +$s_plugin_SourceGitphp_ = ''; +$s_plugin_SourceGitphp_gitphp = 'Gitphp'; +$s_plugin_SourceGitphp_title = 'Integració Gitphp'; +$s_plugin_SourceGitphp_description = 'Afegeix la integració amb Gitphp al framework d\'Integració de Codi.'; -$s_plugin_SourceGitweb_gitweb_root = 'URL arrel de Gitweb'; -$s_plugin_SourceGitweb_gitweb_project = 'Projecte Gitweb
(incloent ".git")'; -$s_plugin_SourceGitweb_master_branch = 'Branques principals
(llista separada per comes)'; +$s_plugin_SourceGitphp_gitphp_root = 'URL arrel de Gitphp'; +$s_plugin_SourceGitphp_gitphp_project = 'Projecte Gitphp
(incloent ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Branques principals
(llista separada per comes)'; diff --git a/SourceGitphp/lang/strings_german.txt b/SourceGitphp/lang/strings_german.txt index 8e01c8a3a..ce5a282d3 100644 --- a/SourceGitphp/lang/strings_german.txt +++ b/SourceGitphp/lang/strings_german.txt @@ -3,11 +3,11 @@ # Copyright (c) 2012 John Reese # Licensed under the MIT license -$s_plugin_SourceGitweb_ = ''; -$s_plugin_SourceGitweb_gitweb = 'Gitweb'; -$s_plugin_SourceGitweb_title = 'Gitweb Integration'; -$s_plugin_SourceGitweb_description = 'Integration für Gitweb über die VCS Basisintegration.'; +$s_plugin_SourceGitphp_ = ''; +$s_plugin_SourceGitphp_gitphp = 'Gitphp'; +$s_plugin_SourceGitphp_title = 'Gitphp Integration'; +$s_plugin_SourceGitphp_description = 'Integration für Gitphp über die VCS Basisintegration.'; -$s_plugin_SourceGitweb_gitweb_root = 'Gitweb Basis-URL'; -$s_plugin_SourceGitweb_gitweb_project = 'Gitweb Projekt
(inkl. ".git")'; -$s_plugin_SourceGitweb_master_branch = 'Hauptzweige
(kommaseparierte Liste)'; +$s_plugin_SourceGitphp_gitphp_root = 'Gitphp Basis-URL'; +$s_plugin_SourceGitphp_gitphp_project = 'Gitphp Projekt
(inkl. ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Hauptzweige
(kommaseparierte Liste)'; diff --git a/SourceGitphp/lang/strings_russian.txt b/SourceGitphp/lang/strings_russian.txt index b90a9ffb6..ac93c43ff 100644 --- a/SourceGitphp/lang/strings_russian.txt +++ b/SourceGitphp/lang/strings_russian.txt @@ -3,11 +3,11 @@ # Copyright (c) 2010 John Reese # Licensed under the MIT license -$s_plugin_SourceGitweb_ = ''; -$s_plugin_SourceGitweb_gitweb = 'Gitweb'; -$s_plugin_SourceGitweb_title = 'Gitweb интегратор'; -$s_plugin_SourceGitweb_description = 'Добавляет интеграцию Gitweb в Source Integration framework.'; +$s_plugin_SourceGitphp_ = ''; +$s_plugin_SourceGitphp_gitphp = 'Gitphp'; +$s_plugin_SourceGitphp_title = 'Gitphp интегратор'; +$s_plugin_SourceGitphp_description = 'Добавляет интеграцию Gitphp в Source Integration framework.'; -$s_plugin_SourceGitweb_gitweb_root = 'Корневой URL для Gitweb'; -$s_plugin_SourceGitweb_gitweb_project = 'Проект Gitweb
(включая ".git")'; -$s_plugin_SourceGitweb_master_branch = 'Главные ветки
(список разделенный запятыми)'; \ No newline at end of file +$s_plugin_SourceGitphp_gitphp_root = 'Корневой URL для Gitphp'; +$s_plugin_SourceGitphp_gitphp_project = 'Проект Gitphp
(включая ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Главные ветки
(список разделенный запятыми)'; diff --git a/SourceGitphp/lang/strings_spanish.txt b/SourceGitphp/lang/strings_spanish.txt index 9bc385a5f..e502b47a2 100644 --- a/SourceGitphp/lang/strings_spanish.txt +++ b/SourceGitphp/lang/strings_spanish.txt @@ -3,11 +3,11 @@ # Copyright (c) 2012 John Reese # Licensed under the MIT license -$s_plugin_SourceGitweb_ = ''; -$s_plugin_SourceGitweb_gitweb = 'Gitweb'; -$s_plugin_SourceGitweb_title = 'Integración Gitweb'; -$s_plugin_SourceGitweb_description = 'Añade la integración con Gitweb al framework de Integración de Código.'; +$s_plugin_SourceGitphp_ = ''; +$s_plugin_SourceGitphp_gitphp = 'Gitphp'; +$s_plugin_SourceGitphp_title = 'Integración Gitphp'; +$s_plugin_SourceGitphp_description = 'Añade la integración con Gitphp al framework de Integración de Código.'; -$s_plugin_SourceGitweb_gitweb_root = 'URL raíz de Gitweb'; -$s_plugin_SourceGitweb_gitweb_project = 'Proyecto Gitweb
(incluyendo ".git")'; -$s_plugin_SourceGitweb_master_branch = 'Ramas principales
(lista separada por comas)'; +$s_plugin_SourceGitphp_gitphp_root = 'URL raíz de Gitphp'; +$s_plugin_SourceGitphp_gitphp_project = 'Proyecto Gitphp
(incluyendo ".git")'; +$s_plugin_SourceGitphp_master_branch = 'Ramas principales
(lista separada por comas)'; From df937807485c5b9fef1acd8b53b3191d82e4cff4 Mon Sep 17 00:00:00 2001 From: Matt Janulewicz Date: Thu, 2 Feb 2017 20:56:27 -0800 Subject: [PATCH 3/3] Resetting version number. --- SourceGitphp/SourceGitphp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceGitphp/SourceGitphp.php b/SourceGitphp/SourceGitphp.php index 2c7c2126b..9f614d85d 100644 --- a/SourceGitphp/SourceGitphp.php +++ b/SourceGitphp/SourceGitphp.php @@ -14,7 +14,7 @@ public function register() { $this->name = plugin_lang_get( 'title' ); $this->description = plugin_lang_get( 'description' ); - $this->version = '0.18'; + $this->version = '0.10'; $this->requires = array( 'MantisCore' => '1.2.0', 'Source' => '0.16',
([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