Skip to content

Commit 5ff5acc

Browse files
committed
Improve bug resolution and assignment logic
Prior to this, depending on plugin settings, the code in Source_Process_Changesets() would resolve the issue linked to the changeset and assign it, even in the following invalid scenarios: - the changeset's author is a registered user in Mantis, but does not have privilege to handle issues (e.g. reporter access level): the issue is assigned to them anyway. - the changeset was authored by developer 1, but was committed by dev2: the issue is assigned to dev2 instead of dev1. With this commit, the behavior has been changed as follows 1. Issue assignment is determined in the following order: - assign to changeset author, if known user and can handle issues; - assign to committer, if they can handle issues; - otherwise, the changeset is attached but the issue is not assigned. 2. Issue resolution only occurs if a valid handler could be determined in step 1, otherwise the issue's status and resolution remain unchanged. Fixes #80, fixes #104
1 parent 43df359 commit 5ff5acc

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Source/Source.API.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
229229
$t_resolved_threshold = config_get('bug_resolved_status_threshold');
230230
$t_fixed_threshold = config_get('bug_resolution_fixed_threshold');
231231
$t_notfixed_threshold = config_get('bug_resolution_not_fixed_threshold');
232+
$t_handle_bug_threshold = config_get( 'handle_bug_threshold' );
232233

233234
# Link author and committer name/email to user accounts
234235
foreach( $p_changesets as $t_key => $t_changeset ) {
@@ -293,12 +294,27 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
293294
# Start fixing and/or resolving issues
294295
foreach( $t_fixed_bugs as $t_bug_id => $t_changeset ) {
295296

296-
# fake the history entries as the committer/author user ID
297+
# Determine the Mantis user to associate with the issue referenced in
298+
# the changeset:
299+
# - use Author if they can handle the issue
300+
# - use Committer if not
301+
# - if Committer can't handle issue either, it will not be resolved.
302+
# This is used to generate the history entries and set the bug handler
303+
# if the changeset fixes the issue.
297304
$t_user_id = null;
298-
if ( $t_changeset->committer_id > 0 ) {
305+
if ( $t_changeset->user_id > 0 ) {
306+
$t_can_handle_bug = access_has_bug_level( $t_handle_bug_threshold, $t_bug_id, $t_changeset->user_id );
307+
if( $t_can_handle_bug ) {
308+
$t_user_id = $t_changeset->user_id;
309+
}
310+
}
311+
$t_handler_id = $t_user_id;
312+
if( $t_handler_id === null && $t_changeset->committer_id > 0 ) {
299313
$t_user_id = $t_changeset->committer_id;
300-
} else if ( $t_changeset->user_id > 0 ) {
301-
$t_user_id = $t_changeset->user_id;
314+
$t_can_handle_bug = access_has_bug_level( $t_handle_bug_threshold, $t_bug_id, $t_user_id );
315+
if( $t_can_handle_bug ) {
316+
$t_handler_id = $t_user_id;
317+
}
302318
}
303319

304320
if ( !is_null( $t_user_id ) ) {
@@ -350,7 +366,10 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
350366
}
351367
}
352368

353-
} else {
369+
} elseif( $t_handler && $t_handler_id !== null ) {
370+
# We only resolve the issue if an authorized handler has been
371+
# identified; otherwise, it will remain open.
372+
354373
if ( $t_bugfix_status > 0 && $t_bug->status != $t_bugfix_status ) {
355374
$t_bug->status = $t_bugfix_status;
356375
$t_update = true;
@@ -367,10 +386,11 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
367386
$t_bug->fixed_in_version = $t_version;
368387
$t_update = true;
369388
}
370-
}
371389

372-
if ( $t_handler && !is_null( $t_user_id ) ) {
373-
$t_bug->handler_id = $t_user_id;
390+
if( $t_bug->handler_id != $t_handler_id ) {
391+
$t_bug->handler_id = $t_handler_id;
392+
$t_update = true;
393+
}
374394
}
375395

376396
$t_private = plugin_config_get( 'bugfix_message_view_status' ) == VS_PRIVATE;

0 commit comments

Comments
 (0)