Skip to content

Commit 908a754

Browse files
committed
Only create links for existing bugs
Prior to this, when processing a non-existing bug id referenced in the commit message, the plugin incorrectly created a link to the issue in the Source_bug table, and inserted an entry in the bug_history table. This caused MantisBT timeline to crash as it processed an invalid history entry. This commit fixes the incorrect behavior by checking for referenced bugs' existence in Source_Process_Changesets() function prior to processing them, so only valid bug links and history records are created. Fixes #157
1 parent e242bdf commit 908a754

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Source/Source.API.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,14 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
235235
$p_changesets[ $t_key ] = Source_Parse_Users( $t_changeset );
236236
}
237237

238-
# Parse normal bug links
238+
# Parse normal bug links, excluding non-existing bugs
239239
foreach( $p_changesets as $t_changeset ) {
240-
$t_changeset->bugs = Source_Parse_Buglinks( $t_changeset->message );
240+
$t_bugs = Source_Parse_Buglinks( $t_changeset->message );
241+
foreach( $t_bugs as $t_bug_id ) {
242+
if( bug_exists( $t_bug_id ) ) {
243+
$t_changeset->bugs[] = $t_bug_id;
244+
}
245+
}
241246
}
242247

243248
# Parse fixed bug links
@@ -247,8 +252,13 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
247252
foreach( $p_changesets as $t_changeset ) {
248253
$t_bugs = Source_Parse_Bugfixes( $t_changeset->message );
249254

250-
foreach( $t_bugs as $t_bug_id ) {
251-
$t_fixed_bugs[ $t_bug_id ] = $t_changeset;
255+
foreach( $t_bugs as $t_key => $t_bug_id ) {
256+
# Only process existing bugs
257+
if( bug_exists( $t_bug_id ) ) {
258+
$t_fixed_bugs[$t_bug_id] = $t_changeset;
259+
} else {
260+
unset( $t_bugs[$t_key] );
261+
}
252262
}
253263

254264
# Add the link to the normal set of buglinks
@@ -283,11 +293,6 @@ function Source_Process_Changesets( $p_changesets, $p_repo=null ) {
283293
# Start fixing and/or resolving issues
284294
foreach( $t_fixed_bugs as $t_bug_id => $t_changeset ) {
285295

286-
# make sure the bug exists before processing
287-
if ( !bug_exists( $t_bug_id ) ) {
288-
continue;
289-
}
290-
291296
# fake the history entries as the committer/author user ID
292297
$t_user_id = null;
293298
if ( $t_changeset->committer_id > 0 ) {

0 commit comments

Comments
 (0)