Skip to content

Commit c888810

Browse files
committed
GitLab: Fix system warning when committing
When checkin.php processes the GitLab webhook, an error occurs: count(): Argument #1 ($var) must be of type Countable|array, null given This is caused by checking a non-existent 'parents' property from the Changeset JSON data. Since we build an array of parents from the JSON data, reuse that to set the changeset's parent. Fixes #346
1 parent 50338db commit c888810

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Source/Source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SourcePlugin extends MantisSourceBase {
3636
* <rev> = changeset revision ID (e.g. SVN rev number, GIT SHA, etc.)
3737
* The match is not case-sensitive.
3838
*/
39-
const CHANGESET_LINKING_REGEX = '/(?:(?<=^|\s)([cdsvp]?):([^:\s][^:\n\t]*):([^:\s]+):)/i';
39+
const CHANGESET_LINKING_REGEX = '/(?:(?<=^|[^\w])([cdsvp]?):([^:\s][^:\n\t]*):([^:\s]+):)/i';
4040

4141
function register() {
4242
$this->name = plugin_lang_get( 'title' );

SourceGitlab/SourceGitlab.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ public function import_commits( $p_repo, $p_commit_ids, $p_branch='' ) {
347347
private function json_commit_changeset( $p_repo, $p_json, $p_branch='' ) {
348348
echo "processing $p_json->id ... ";
349349
if ( !SourceChangeset::exists( $p_repo->id, $p_json->id ) ) {
350-
$t_parents = array();
351-
foreach( $p_json->parent_ids as $t_parent ) {
352-
$t_parents[] = $t_parent;
353-
}
354350
# Message will be replaced by title in gitlab version earlier than 7.2
355351
$t_message = ( !property_exists( $p_json, 'message' ) )
356352
? $p_json->title
@@ -364,9 +360,12 @@ private function json_commit_changeset( $p_repo, $p_json, $p_branch='' ) {
364360
$t_message
365361
);
366362

367-
if ( count( $p_json->parents ) > 0 ) {
368-
$t_parent = $p_json->parents[0];
369-
$t_changeset->parent = $t_parent->id;
363+
$t_parents = array();
364+
foreach( $p_json->parent_ids as $t_parent ) {
365+
$t_parents[] = $t_parent;
366+
}
367+
if( $t_parents ) {
368+
$t_changeset->parent = $t_parents[0];
370369
}
371370

372371
$t_changeset->author_email = $p_json->author_email;

0 commit comments

Comments
 (0)