Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Bugzilla/API/V1/Github.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions qa/t/rest_github_push_comment.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Loading