Skip to content

Commit 647f41c

Browse files
committed
Merge remote-tracking branch 'origin/master'
Conflicts: Source/MantisSourceBase.class.php SourceCgit/SourceCgit.php SourceGithub/SourceGithub.php SourceGitlab/SourceGitlab.php SourceGitphp/SourceGitphp.php SourceGitweb/SourceGitweb.php
2 parents 682de55 + 3c30d6d commit 647f41c

25 files changed

+399
-59
lines changed

README.md

100755100644
File mode changed.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
# Copyright (c) 2017 Damien Regad
4+
# Licensed under the MIT license
5+
6+
require_once( 'MantisSourcePlugin.class.php' );
7+
8+
/**
9+
* Class MantisSourceGitBasePlugin
10+
*
11+
* Base class providing common methods for all git-based Source Integration
12+
* Plugin classes.
13+
*
14+
*/
15+
abstract class MantisSourceGitBasePlugin extends MantisSourcePlugin
16+
{
17+
/**
18+
* Git branch name validation regex.
19+
* Based on rules defined in man page
20+
* http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
21+
*/
22+
private $valid_branch_regex = '%'
23+
# Must not start with '/'; cannot contain '/.', '//', '@{' or '\';
24+
# cannot be a single '@'.
25+
. '^(?!/|.*([/.]\.|//|@\{|\\\\)|@$)'
26+
# One or more chars, except the following: ASCII control, space,
27+
# tilde, caret, colon, question mark, asterisk, open bracket.
28+
. '[^\000-\037\177 ~^:?*[]+'
29+
# Must not end with '.lock', '/' or '.'
30+
. '(?<!\.lock|[/.])$'
31+
. '%';
32+
33+
/**
34+
* Error constants
35+
*/
36+
const ERROR_INVALID_BRANCH = 'invalid_branch';
37+
38+
/**
39+
* Define plugin's Error strings
40+
* @return array
41+
*/
42+
public function errors() {
43+
$t_errors_list = array(
44+
self::ERROR_INVALID_BRANCH,
45+
);
46+
47+
foreach( $t_errors_list as $t_error ) {
48+
$t_errors[$t_error] = plugin_lang_get( 'error_' . $t_error, 'Source' );
49+
}
50+
51+
return $t_errors;
52+
}
53+
54+
/**
55+
* Determines if given string name is a valid git branch name.
56+
* @param string $p_branch Branch name to validate
57+
* @return bool True if valid
58+
*/
59+
protected function is_branch_valid( $p_branch )
60+
{
61+
return (bool)preg_match( $this->valid_branch_regex, $p_branch );
62+
}
63+
64+
/**
65+
* Triggers an error if the branch is invalid
66+
* @param string $p_branch Branch name to validate
67+
* @return void
68+
*/
69+
protected function ensure_branch_valid( $p_branch )
70+
{
71+
if( !$this->is_branch_valid( $p_branch ) ) {
72+
error_parameters( $p_branch );
73+
plugin_error( self::ERROR_INVALID_BRANCH );
74+
}
75+
}
76+
77+
/**
78+
* Validates a comma-delimited list of git branches.
79+
* Triggers an ERROR_INVALID_BRANCH if one of the branches is invalid
80+
* @param string $p_list Comma-delimited list of branch names (or '*')
81+
* @return void
82+
*/
83+
protected function validate_branch_list( $p_list )
84+
{
85+
if( $p_list == '*' ) {
86+
return;
87+
}
88+
89+
foreach( explode( ',', $p_list ) as $t_branch ) {
90+
$this->ensure_branch_valid( trim( $t_branch ) );
91+
}
92+
}
93+
}

Source/Source.API.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ function save() {
927927
db_param() . ', ' . db_param() . ' )';
928928
db_query( $t_query, array(
929929
$this->repo_id, $this->revision, $this->parent, $this->branch,
930-
$this->user_id, $this->timestamp, $this->author, $this->message, $this->info,
930+
$this->user_id, $this->timestamp, $this->author, db_mysql_fix_utf8( $this->message ), $this->info,
931931
$this->ported, $this->author_email, $this->committer, $this->committer_email,
932932
$this->committer_id ) );
933933

Source/Source.php

100755100644
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class SourcePlugin extends MantisSourceBase {
1313

1414
static $cache = array();
1515

16+
const PLUGIN_VERSION = self::FRAMEWORK_VERSION;
17+
1618
/**
1719
* Changeset link matching pattern.
1820
* format: '<type>:<reponame>:<revision>:', where
@@ -28,7 +30,7 @@ function register() {
2830
$this->name = plugin_lang_get( 'title' );
2931
$this->description = plugin_lang_get( 'description' );
3032

31-
$this->version = self::FRAMEWORK_VERSION;
33+
$this->version = self::PLUGIN_VERSION;
3234
$this->requires = array(
3335
'MantisCore' => self::MANTIS_VERSION,
3436
);

Source/lang/strings_english.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,4 @@ $s_plugin_Source_import_full_failed = 'Full repository data importing failed.';
147147

148148
$s_plugin_Source_changeset_column_title = 'C';
149149

150+
$s_plugin_Source_error_invalid_branch = 'Invalid characters in Branch name "%1$s".';

Source/lang/strings_german.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,5 @@ $s_plugin_Source_import_latest_failed = 'Partieller Import des Projektarchivs fe
144144
$s_plugin_Source_import_full_failed = 'Vollständiger Import des Projektarchivs fehlgeschlagen.';
145145

146146
$s_plugin_Source_changeset_column_title = 'C';
147+
148+
$s_plugin_Source_error_invalid_branch = 'Ungültige Zeichen in der Zweige "%1$s"';

Source/pages/checkin.php

100755100644
File mode changed.

Source/pages/manage_config.php

100755100644
File mode changed.

Source/pages/manage_config_page.php

100755100644
File mode changed.

SourceBitBucket/SourceBitBucket.php

100755100644
File mode changed.

SourceCgit/SourceCgit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
# Licensed under the MIT license
88

99
if ( !defined('testing') ) {
10-
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourcePlugin.class.php' ) ) {
10+
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
1111
return;
1212
}
1313

1414
require_once( config_get( 'core_path' ) . 'url_api.php' );
1515
}
1616

17-
class SourceCgitPlugin extends MantisSourcePlugin {
17+
class SourceCgitPlugin extends MantisSourceGitBasePlugin {
1818

1919
const PLUGIN_VERSION = '2.0.0';
2020
const FRAMEWORK_VERSION_REQUIRED = '2.0.0';
@@ -122,6 +122,8 @@ public function update_repo( $p_repo ) {
122122
$f_cgit_project = gpc_get_string( 'cgit_project' );
123123
$f_master_branch = gpc_get_string( 'master_branch' );
124124

125+
$this->validate_branch_list( $f_master_branch );
126+
125127
$p_repo->info['cgit_root'] = $f_cgit_root;
126128
$p_repo->info['cgit_project'] = $f_cgit_project;
127129
$p_repo->info['master_branch'] = $f_master_branch;

SourceGithub/SourceGithub.php

100755100644
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
# Copyright (c) 2012 John Reese
44
# Licensed under the MIT license
55

6-
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourcePlugin.class.php' ) ) {
6+
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
77
return;
88
}
99

1010
require_once( config_get( 'core_path' ) . 'json_api.php' );
1111

12-
class SourceGithubPlugin extends MantisSourcePlugin {
12+
class SourceGithubPlugin extends MantisSourceGitBasePlugin {
1313

1414
const PLUGIN_VERSION = '2.0.0';
1515
const FRAMEWORK_VERSION_REQUIRED = '2.0.0';
1616

17-
const ERROR_INVALID_PRIMARY_BRANCH = 'invalid_branch';
18-
1917
public $linkPullRequest = '/pull/%s';
2018

2119
public function register() {
@@ -33,16 +31,6 @@ public function register() {
3331
$this->url = 'https://github.com/mantisbt-plugins/source-integration/';
3432
}
3533

36-
public function errors() {
37-
$t_errors_list = array(
38-
self::ERROR_INVALID_PRIMARY_BRANCH,
39-
);
40-
foreach( $t_errors_list as $t_error ) {
41-
$t_errors[$t_error] = plugin_lang_get( 'error_' . $t_error );
42-
}
43-
return $t_errors;
44-
}
45-
4634
public $type = 'github';
4735

4836
public function show_type() {
@@ -205,9 +193,7 @@ public function update_repo( $p_repo ) {
205193
$f_hub_app_secret = gpc_get_string( 'hub_app_secret' );
206194
$f_master_branch = gpc_get_string( 'master_branch' );
207195

208-
if ( !preg_match( '/^(\*|[a-zA-Z0-9_\., -]*)$/', $f_master_branch ) ) {
209-
plugin_error( self::ERROR_INVALID_PRIMARY_BRANCH );
210-
}
196+
$this->validate_branch_list( $f_master_branch );
211197

212198
$p_repo->info['hub_username'] = $f_hub_username;
213199
$p_repo->info['hub_reponame'] = $f_hub_reponame;
@@ -296,7 +282,7 @@ public function commit( $p_repo, $p_data ) {
296282
$t_commits[] = $t_commit['id'];
297283
}
298284

299-
$t_refData = explode( '/',$p_data['ref'] );
285+
$t_refData = explode( '/', $p_data['ref'], 3 );
300286
$t_branch = $t_refData[2];
301287

302288
return $this->import_commits( $p_repo, $t_commits, $t_branch );

SourceGithub/lang/strings_english.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $s_plugin_SourceGithub_hub_reponame = 'GitHub Repository Name<br/><span class="s
1313
$s_plugin_SourceGithub_hub_app_client_id = 'GitHub Application Client ID<br><span class="small">This is required for private repositories and also allows to get around the <a href="https://developer.github.com/v3/#rate-limiting">Rate Limit</a> when importing data.<br>Create a new <a href="https://github.com/settings/applications">GitHub Application</a> if needed.</span>';
1414
$s_plugin_SourceGithub_hub_app_secret = 'GitHub Application Secret';
1515
$s_plugin_SourceGithub_hub_app_access_token = 'GitHub Application Access Token';
16-
$s_plugin_SourceGithub_master_branch = 'Primary Branches<br/><span class="small">(comma-separated list)</span>';
16+
$s_plugin_SourceGithub_master_branch = 'Primary Branches<br/><span class="small">(comma-separated list or "*" for all branches)</span>';
1717

1818
$s_plugin_SourceGithub_hub_app_client_id_secret_missing = '<span class="small">You must first enter the GitHub Application <em>Client ID</em> &amp; <em>Secret</em> and update the repository before you can authorize.</span>';
1919
$s_plugin_SourceGithub_hub_app_authorize = 'Click to Authorize';
@@ -25,5 +25,3 @@ $s_plugin_SourceGithub_repo_authorization_failed = '<p style="color: red;">Sorry
2525

2626
$s_plugin_SourceGithub_oauth_authorization = 'GitHub OAuth Authorization';
2727
$s_plugin_SourceGithub_back_repo = 'Back to Repository';
28-
29-
$s_plugin_SourceGithub_error_invalid_branch = 'Invalid character in Primary Branch';

SourceGithub/lang/strings_german.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ $s_plugin_SourceGithub_description = 'Integration für GitHub über die VCS Basi
1010

1111
$s_plugin_SourceGithub_hub_username = 'GitHub Benutzername';
1212
$s_plugin_SourceGithub_hub_reponame = 'GitHub Projektarchiv<br/><span class="small">(Klein Leerzeichen)</span>';
13-
$s_plugin_SourceGithub_master_branch = 'Hauptzweige<br/><span class="small">(kommaseparierte Liste)</span>';
14-
15-
$s_plugin_SourceGithub_error_invalid_branch = 'Ungültige Zeichen in der Hauptzweige';
13+
$s_plugin_SourceGithub_master_branch = 'Hauptzweige<br/><span class="small">(kommaseparierte Liste oder "*" für alle)</span>';

SourceGitlab/SourceGitlab.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
# Copyright (c) 2014 Bob Clough
55
# Licensed under the MIT license
66

7-
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourcePlugin.class.php' ) ) {
7+
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
88
return;
99
}
1010

1111
require_once( config_get( 'core_path' ) . 'url_api.php' );
1212
require_once( config_get( 'core_path' ) . 'json_api.php' );
1313

14-
class SourceGitlabPlugin extends MantisSourcePlugin {
14+
class SourceGitlabPlugin extends MantisSourceGitBasePlugin {
1515

1616
const PLUGIN_VERSION = '2.0.0';
1717
const FRAMEWORK_VERSION_REQUIRED = '2.0.0';
1818

19-
const ERROR_INVALID_PRIMARY_BRANCH = 'invalid_branch';
20-
2119
public function register() {
2220
$this->name = plugin_lang_get( 'title' );
2321
$this->description = plugin_lang_get( 'description' );
@@ -33,16 +31,6 @@ public function register() {
3331
$this->url = 'https://github.com/mantisbt-plugins/source-integration/';
3432
}
3533

36-
public function errors() {
37-
$t_errors_list = array(
38-
self::ERROR_INVALID_PRIMARY_BRANCH,
39-
);
40-
foreach( $t_errors_list as $t_error ) {
41-
$t_errors[$t_error] = plugin_lang_get( 'error_' . $t_error );
42-
}
43-
return $t_errors;
44-
}
45-
4634
public $type = 'gitlab';
4735

4836
public function show_type() {
@@ -182,11 +170,9 @@ public function update_repo( $p_repo ) {
182170
}
183171
}
184172
}
185-
$f_master_branch = gpc_get_string( 'master_branch' );
186173

187-
if ( !preg_match( '/^(\*|[a-zA-Z0-9_\., -]*)$/', $f_master_branch ) ) {
188-
plugin_error( self::ERROR_INVALID_PRIMARY_BRANCH );
189-
}
174+
$f_master_branch = gpc_get_string( 'master_branch' );
175+
$this->validate_branch_list( $f_master_branch );
190176

191177
# Update other fields
192178
$p_repo->info['hub_repoid'] = $f_hub_repoid;

SourceGitlab/lang/strings_english.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ $s_plugin_SourceGitlab_hub_app_secret = 'GitLab API Key<br /><span class="small"
1616
$s_plugin_SourceGitlab_master_branch = 'Primary Branches<br/><span class="small">(comma-separated list or *)</span>';
1717

1818
$s_plugin_SourceGitlab_back_repo = 'Back to Repository';
19-
20-
$s_plugin_SourceGitlab_error_invalid_branch = 'Invalid character in Primary Branch';

SourceGitlab/lang/strings_german.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ $s_plugin_SourceGitlab_hub_app_secret = 'GitLab API Key<br /><span class="small"
1515
$s_plugin_SourceGitlab_master_branch = 'Hauptzweige<br/><span class="small">(Komma-separierte Liste oder *)</span>';
1616

1717
$s_plugin_SourceGitlab_back_repo = 'Zurück zum Repository';
18-
19-
$s_plugin_SourceGitlab_error_invalid_branch = 'Ungültige Zeichen in der Hauptzweige';

SourceGitphp/SourceGitphp.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Copyright (c) 2012 John Reese
44
# Licensed under the MIT license
55

6-
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourcePlugin.class.php' ) ) {
6+
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
77
return;
88
}
99

1010
require_once( config_get( 'core_path' ) . 'url_api.php' );
1111

12-
class SourceGitphpPlugin extends MantisSourcePlugin {
12+
class SourceGitphpPlugin extends MantisSourceGitBasePlugin {
1313

1414
const PLUGIN_VERSION = '2.0.0';
1515
const FRAMEWORK_VERSION_REQUIRED = '2.0.0';
@@ -113,6 +113,8 @@ public function update_repo( $p_repo ) {
113113
$f_gitphp_project = gpc_get_string( 'gitphp_project' );
114114
$f_master_branch = gpc_get_string( 'master_branch' );
115115

116+
$this->validate_branch_list( $f_master_branch );
117+
116118
$p_repo->info['gitphp_root'] = $f_gitphp_root;
117119
$p_repo->info['gitphp_project'] = $f_gitphp_project;
118120
$p_repo->info['master_branch'] = $f_master_branch;

SourceGitweb/SourceGitweb.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Copyright (c) 2012 John Reese
44
# Licensed under the MIT license
55

6-
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourcePlugin.class.php' ) ) {
6+
if ( false === include_once( config_get( 'plugin_path' ) . 'Source/MantisSourceGitBasePlugin.class.php' ) ) {
77
return;
88
}
99

1010
require_once( config_get( 'core_path' ) . 'url_api.php' );
1111

12-
class SourceGitwebPlugin extends MantisSourcePlugin {
12+
class SourceGitwebPlugin extends MantisSourceGitBasePlugin {
1313

1414
const PLUGIN_VERSION = '2.0.0';
1515
const FRAMEWORK_VERSION_REQUIRED = '2.0.0';
@@ -149,6 +149,8 @@ public function update_repo( $p_repo ) {
149149
$f_gitweb_pass = gpc_get_string( 'gitweb_pass' );
150150
$f_master_branch = gpc_get_string( 'master_branch' );
151151

152+
$this->validate_branch_list( $f_master_branch );
153+
152154
$p_repo->info['gitweb_root'] = $f_gitweb_root;
153155
$p_repo->info['gitweb_project'] = $f_gitweb_project;
154156
$p_repo->info['gitweb_user'] = $f_gitweb_user;

SourceViewVC/LICENSE

100755100644
File mode changed.

SourceViewVC/SourceViewVC.php

100755100644
File mode changed.

SourceViewVC/lang/strings_english.txt

100755100644
File mode changed.

docs/CONFIGURING.SourceViewVC.md

100755100644
File mode changed.

docs/Classes.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
integration with the MantisBT UI
99
- **MantisSourcePlugin** - Abstract base class for VCS-specific plugins
1010
- **SourceGenericPlugin**
11-
- **SourceBitBucketPlugin**
12-
- **SourceCgitPlugin**
13-
- **SourceGithubPlugin**
14-
- **SourceGitlabPlugin**
15-
- **SourceGitwebPlugin**
11+
- **MantisSourceGitBasePlugin** - Abstract class for git-based plugins
12+
- **SourceBitBucketPlugin**
13+
- **SourceCgitPlugin**
14+
- **SourceGithubPlugin**
15+
- **SourceGitlabPlugin**
16+
- **SourceGitphpPlugin**
17+
- **SourceGitwebPlugin**
1618
- **SourceHgWebPlugin**
1719
- **SourceSVNPlugin** Subversion and derivatives
1820
- **SourceSFSVNPlugin**

0 commit comments

Comments
 (0)