Skip to content

Commit 70d4b45

Browse files
committed
Move the new config to MantisSourceGitBasePlugin
Since it only applies to git-based plugins, the new config should only be displayed if one of these is installed. The config has been renamed to 'git_default_primary_branch', and the name is defined in a class constant to ensure consistency. A protected method to retrieve the config's value has been added to the base class, to avoid multiple config_get() calls in each sub-class. The original language string has been modified; it is no longer useful to indicate that the config only applies to git-based plugins, because this is now obvious as it is listed in a git-specific section.
1 parent 5803240 commit 70d4b45

File tree

12 files changed

+95
-32
lines changed

12 files changed

+95
-32
lines changed

Source/MantisSourceGitBasePlugin.class.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ abstract class MantisSourceGitBasePlugin extends MantisSourcePlugin
2727
*/
2828
private $valid_branch_regex = '%^(?!/|.*([/.]\.|//|@\{|\\\\)|@$)[^\000-\037\177 ~^:?*[]+(?<!\.lock|[/.])$%';
2929

30+
/**
31+
* @var bool Parent class includes global configuratino
32+
*/
33+
public $configuration = true;
34+
35+
/**
36+
* @var bool Prevent more than one Git-based plugin from processing form
37+
*/
38+
private static $config_form_handled = false;
39+
40+
/**
41+
*
42+
*/
43+
const CFG_DEFAULT_PRIMARY_BRANCH = 'git_default_primary_branch';
44+
3045
/**
3146
* Error constants
3247
*/
@@ -87,4 +102,63 @@ protected function validate_branch_list( $p_list )
87102
$this->ensure_branch_valid( trim( $t_branch ) );
88103
}
89104
}
105+
106+
/**
107+
* Retrieves the default primary branches from Source plugin's config
108+
* @return string
109+
*/
110+
protected function get_default_primary_branches() {
111+
plugin_push_current( 'Source' );
112+
$t_value = plugin_config_get( self::CFG_DEFAULT_PRIMARY_BRANCH, 'master' );
113+
plugin_pop_current();
114+
return $t_value;
115+
}
116+
117+
/**
118+
* Output form elements for configuration options.
119+
*/
120+
public function update_config_form() {
121+
# Prevent more than one Git-based class from outputting form elements.
122+
if( !MantisSourceGitBasePlugin::$config_form_handled ) {
123+
plugin_push_current( 'Source' );
124+
MantisSourceGitBasePlugin::$config_form_handled = true;
125+
?>
126+
<tr class="spacer"></tr>
127+
<tr>
128+
<td colspan="2"><h4><?php echo plugin_lang_get( 'git_title' ) ?></h4></td>
129+
</tr>
130+
<tr>
131+
<td class="category"><?php echo plugin_lang_get( self::CFG_DEFAULT_PRIMARY_BRANCH ) ?></td>
132+
<td>
133+
<input name="<?php echo self::CFG_DEFAULT_PRIMARY_BRANCH ?>"
134+
type="text" class="input-sm" size="50"
135+
value="<?php echo string_attribute( plugin_config_get( self::CFG_DEFAULT_PRIMARY_BRANCH, 'master' ) ) ?>"
136+
/>
137+
<br>
138+
<span class="small"><?php echo plugin_lang_get( 'git_default_primary_branch_info' ) ?></span>
139+
</td>
140+
</tr>
141+
<tr></tr>
142+
<?php
143+
plugin_pop_current();
144+
}
145+
}
146+
147+
/**
148+
* Process form elements for configuration options.
149+
*/
150+
public function update_config() {
151+
# Prevent more than one SVN class from handling form elements.
152+
if( !MantisSourceGitBasePlugin::$config_form_handled ) {
153+
MantisSourceGitBasePlugin::$config_form_handled = true;
154+
155+
plugin_push_current( 'Source' );
156+
$f_default_branch = trim( gpc_get_string( self::CFG_DEFAULT_PRIMARY_BRANCH ) ) ?: 'master';
157+
$t_default_branch = plugin_config_get( self::CFG_DEFAULT_PRIMARY_BRANCH, 'master' );
158+
if ( $f_default_branch != $t_default_branch ) {
159+
plugin_config_set( self::CFG_DEFAULT_PRIMARY_BRANCH, $f_default_branch );
160+
}
161+
plugin_pop_current();
162+
}
163+
}
90164
}

Source/Source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function config() {
8383
'bugfix_message' => 'Fix committed to $1 branch.',
8484
'bugfix_message_view_status' => VS_PUBLIC,
8585

86-
'default_master_branch' => 'master',
86+
'default_primary_branch' => 'master',
8787

8888
'remote_checkin' => OFF,
8989
'checkin_urls' => serialize( array( 'localhost' ) ),

Source/lang/strings_english.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ $s_plugin_Source_bugfix_message = 'Bug Fixed Message Template';
100100
$s_plugin_Source_bugfix_message_info = 'Use $1 for branch, $2 for revision, $3 for timestamp, $4 for commit message, $5 for repository name, or $6 for changeset ID.';
101101
$s_plugin_Source_bugfix_message_view_status = 'Bug Fixed Message View State';
102102
$s_plugin_Source_bugfix_message_view_status_info = 'Note: if the changeset\'s author/committer does not have <em>private_bugnote_threshold</em>, the note will be Public regardless of this setting.';
103-
$s_plugin_Source_default_master_branch = 'Default primary branches';
104-
$s_plugin_Source_default_master_branch_info = 'Only for Git-based repositories. Branches by default when creating a repository (comma-separated list or *).';
105103
$s_plugin_Source_reset = 'Reset to default';
106104
$s_plugin_Source_menu_links = 'Main Menu Links';
107105
$s_plugin_Source_show_repo_link = 'Repositories';
@@ -116,6 +114,10 @@ $s_plugin_Source_enable_message = 'Bug Fixed Message';
116114
$s_plugin_Source_enable_porting = 'Porting Status';
117115
$s_plugin_Source_enable_product_matrix = 'Product Matrix Integration';
118116

117+
$s_plugin_Source_git_title = 'Git-based Plugins Integration';
118+
$s_plugin_Source_git_default_primary_branch = 'Default primary branches';
119+
$s_plugin_Source_git_default_primary_branch_info = 'Default Branches to use when creating a repository (comma-separated list or *).';
120+
119121
$s_plugin_Source_branch_mapping = 'Branch Mappings';
120122
$s_plugin_Source_mapping_update = 'Update Mappings';
121123
$s_plugin_Source_mapping_strategy = 'Strategy';

Source/lang/strings_french.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ $s_plugin_Source_bugfix_message = 'Modèle de message de résolution';
9898
$s_plugin_Source_bugfix_message_info = 'Utilisez $1 pour la branche, $2 pour la révision, $3 pour l\'horodatage, $4 pour le message de soumission, ou $5 pour le nom du dépôt.';
9999
$s_plugin_Source_bugfix_message_view_status = 'Type de message de résolution';
100100
$s_plugin_Source_bugfix_message_view_status_info = 'Note: si l\'auteur du jeu de changement n\'a pas le niveau <em>private_bugnote_threshold</em>, la note sera Publique quel que soit la valeur de cette option.';
101-
$s_plugin_Source_default_master_branch = 'Branche par défaut';
102-
$s_plugin_Source_default_master_branch_info = 'Pour les dépôts basés sur Git uniquement. Branches renseignées par defaut lors de la création d\'un dépôt (liste avec séparateur virgule ou *).';
103101
$s_plugin_Source_reset = 'Réinitialiser';
104102
$s_plugin_Source_menu_links = 'Liens du menu principal';
105103
$s_plugin_Source_show_repo_link = 'Dépôts';
@@ -112,6 +110,10 @@ $s_plugin_Source_enable_resolving = 'Résoudre les demandes résolues';
112110
$s_plugin_Source_enable_message = 'Message de résolution';
113111
$s_plugin_Source_enable_porting = 'Etat de portage';
114112

113+
$s_plugin_Source_git_title = 'Intégration de greffons basés sur Git';
114+
$s_plugin_Source_git_default_primary_branch = 'Branche par défaut';
115+
$s_plugin_Source_git_default_primary_branch_info = 'Branches renseignées par défaut lors de la création d\'un dépôt (liste avec séparateur virgule ou *).';
116+
115117
$s_plugin_Source_branch_mapping = 'Associations de branche';
116118
$s_plugin_Source_mapping_update = 'Mettre à jour les associations';
117119
$s_plugin_Source_mapping_strategy = 'Stratégie';

Source/pages/manage_config.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
$f_bugfix_message = gpc_get_string( 'bugfix_message' );
4040
$f_bugfix_message_view_status = gpc_get_int( 'bugfix_message_view_status', VS_PUBLIC );
4141

42-
$f_default_branch = gpc_get_string( 'default_branch' );
43-
4442
function check_urls( $t_urls_in ) {
4543
$t_urls_in = explode( "\n", $t_urls_in );
4644
$t_urls_out = array();
@@ -121,8 +119,6 @@ function maybe_set_option( $name, $value ) {
121119
maybe_set_option( 'bugfix_message', $f_bugfix_message );
122120
maybe_set_option( 'bugfix_message_view_status', $f_bugfix_message_view_status );
123121

124-
maybe_set_option( 'default_branch', $f_default_branch );
125-
126122
maybe_set_option( 'remote_checkin', $f_remote_checkin );
127123
maybe_set_option( 'checkin_urls', serialize( $t_checkin_urls ) );
128124
maybe_set_option( 'remote_imports', $f_remote_imports );

Source/pages/manage_config_page.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@
259259
</tr>
260260

261261
<tr class="spacer"></tr>
262-
<tr>
263-
<td class="category"><?php echo plugin_lang_get( 'default_master_branch' ) ?></td>
264-
<td>
265-
<input name="default_master_branch" type="text" class="input-sm" size="50" value="<?php echo string_attribute( plugin_config_get( 'default_master_branch' ) ) ?>"/>
266-
<br>
267-
<span class="small"><?php echo plugin_lang_get( 'default_master_branch_info' ) ?></span>
268-
</td>
269-
</tr>
270-
271-
<tr class="spacer" />
272262
<tr>
273263
<td class="category"><?php echo plugin_lang_get( 'api_key' ) ?></td>
274264
<td>

SourceBitBucket/SourceBitBucket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function update_repo_form( $p_repo ) {
111111
if( isset($p_repo->info['master_branch']) ) {
112112
$t_master_branch = $p_repo->info['master_branch'];
113113
} else {
114-
$t_master_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
114+
$t_master_branch = $this->get_default_primary_branches();
115115
}
116116
?>
117117
<tr>
@@ -223,7 +223,7 @@ public function import_full( $p_repo, $p_use_cache = true ) {
223223
$t_branch = $p_repo->info['master_branch'];
224224

225225
if( is_blank( $t_branch ) ) {
226-
$t_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
226+
$t_branch = $this->get_default_primary_branches();
227227
}
228228

229229
$t_username = $p_repo->info['bit_username'];

SourceCgit/SourceCgit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function update_repo_form( $p_repo ) {
9393
if ( isset( $p_repo->info['master_branch'] ) ) {
9494
$t_master_branch = $p_repo->info['master_branch'];
9595
} else {
96-
$t_master_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
96+
$t_master_branch = $this->get_default_primary_branches();
9797
}
9898
?>
9999
<tr>
@@ -157,7 +157,7 @@ public function import_full( $p_repo ) {
157157

158158
$t_branch = $p_repo->info['master_branch'];
159159
if ( is_blank( $t_branch ) ) {
160-
$t_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
160+
$t_branch = $this->get_default_primary_branches();
161161
}
162162

163163
$t_branches = array_map( 'trim', explode( ',', $t_branch ) );

SourceGithub/SourceGithub.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function update_repo_form( $p_repo ) {
288288
if ( isset( $p_repo->info['master_branch'] ) ) {
289289
$t_master_branch = $p_repo->info['master_branch'];
290290
} else {
291-
$t_master_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
291+
$t_master_branch = $this->get_default_primary_branches();
292292
}
293293
?>
294294

@@ -572,7 +572,7 @@ public function import_full( $p_repo ) {
572572

573573
$t_branch = $p_repo->info['master_branch'];
574574
if ( is_blank( $t_branch ) ) {
575-
$t_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
575+
$t_branch = $this->get_default_primary_branches();
576576
}
577577

578578
if ($t_branch != '*')
@@ -804,5 +804,4 @@ public static function url_post( $p_url, $p_post_data ) {
804804
);
805805
return (string)$t_response->getBody();
806806
}
807-
808807
}

SourceGitlab/SourceGitlab.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function update_repo_form( $p_repo ) {
115115
if ( isset( $p_repo->info['master_branch'] ) ) {
116116
$t_master_branch = $p_repo->info['master_branch'];
117117
} else {
118-
$t_master_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
118+
$t_master_branch = $this->get_default_primary_branches();
119119
}
120120
?>
121121
<tr>
@@ -249,7 +249,7 @@ public function import_full( $p_repo ) {
249249

250250
$t_branch = $p_repo->info['master_branch'];
251251
if ( is_blank( $t_branch ) ) {
252-
$t_branch = config_get( 'plugin_Source_default_master_branch', 'master' );
252+
$t_branch = $this->get_default_primary_branches();
253253
}
254254

255255
# if we're not allowed everything, populate an array of what we are allowed

0 commit comments

Comments
 (0)