diff --git a/Bugzilla/API/V1/Github.pm b/Bugzilla/API/V1/Github.pm index 38280673c9..7c3f7470b7 100644 --- a/Bugzilla/API/V1/Github.pm +++ b/Bugzilla/API/V1/Github.pm @@ -25,6 +25,8 @@ use Digest::SHA qw(hmac_sha256_hex); use JSON::Validator::Joi qw(joi); use Mojo::Util qw(secure_compare); +use constant BUG_RE => qr/\b[Bb]ug(?:[ -]|: )(\d+)\b/; + sub setup_routes { my ($class, $r) = @_; $r->post('/github/pull_request')->to('V1::Github#pull_request'); @@ -89,7 +91,7 @@ sub pull_request { # Find bug ID in the title and see if bug exists and client # can see it (non-fatal). - my ($bug_id) = $title =~ /\b[Bb]ug[ -](\d+)\b/; + my ($bug_id) = $title =~ BUG_RE; my $bug = Bugzilla::Bug->new($bug_id); if ($bug->{error}) { $template->process('global/code-error.html.tmpl', @@ -263,7 +265,7 @@ sub push_comment { } # Find bug ID in the title and see if bug exists - my ($bug_id) = $message =~ /\b[Bb]ug[ -](\d+)\b/; + my ($bug_id) = $message =~ BUG_RE; next if !$bug_id; # Only include the first line of the commit message diff --git a/qa/t/rest_github_push_comment.t b/qa/t/rest_github_push_comment.t index 0e30fd4ceb..4f8a55747e 100644 --- a/qa/t/rest_github_push_comment.t +++ b/qa/t/rest_github_push_comment.t @@ -361,4 +361,42 @@ foreach my $change_group (@{$history}) { ok($found_status_flag_change, 'Flag change found'); +# Test Git trailer format (Bug: 1234567) +$new_bug = { + product => 'Firefox', + component => 'General', + summary => 'Test Git trailer format', + type => 'defect', + version => 'unspecified', + severity => 'blocker', + description => 'Test bug for Git trailer format', +}; + +$t->post_ok( + $url . 'rest/bug' => {'X-Bugzilla-API-Key' => $api_key} => json => $new_bug) + ->status_is(200)->json_has('/id'); + +my $bug_id_3 = $t->tx->res->json->{id}; + +$payload = { + ref => 'refs/heads/master', + repository => { + full_name => 'mozilla-mobile/firefox-android', + default_branch => 'master', + }, + commits => [{ + author => {username => 'testuser', name => 'Test User'}, + url => 'https://github.com/mozilla-bteam/bmo/commit/abc123', + message => "Fix authentication issue\n\nBug: $bug_id_3", + }] +}; + +$t->post_ok( + $url + . 'rest/github/push_comment' => { + 'X-Hub-Signature-256' => generate_payload_signature($secret, $payload), + 'X-GitHub-Event' => 'push' + } => json => $payload +)->status_is(200)->json_has("/bugs/$bug_id_3/id"); + done_testing();