# Load the revision from Phabricator
my $revision = Bugzilla::Extension::PhabBugz::Revision->new_from_query(
{phids => [$object_phid]});
- $self->process_revision_change($revision, $author, $story_text, 0);
+ $self->process_revision_change($revision, $author, $story_text);
$self->save_last_id($story_id, 'feed');
}
- # Process any build targets as well.
- my $dbh = Bugzilla->dbh;
-
- INFO("Checking for revisions with pending build plan");
- my $build_targets
- = $dbh->selectall_arrayref(
- "SELECT name, value FROM phabbugz WHERE name LIKE 'build_target_%'",
- {Slice => {}});
-
- my $delete_build_target
- = $dbh->prepare("DELETE FROM phabbugz WHERE name = ? AND VALUE = ?");
-
- foreach my $target (@$build_targets) {
- my ($revision_id) = ($target->{name} =~ /^build_target_(\d+)$/);
- my $build_target = $target->{value};
-
- next unless $revision_id && $build_target;
-
- INFO("Processing revision $revision_id with build target $build_target");
-
- my $revision
- = Bugzilla::Extension::PhabBugz::Revision->new_from_query({
- ids => [int($revision_id)]
- });
-
- $self->process_revision_change($revision, $revision->author,
- " created D" . $revision->id, 1);
-
- # Set the build target to a passing status to
- # allow the revision to exit draft state
- request('harbormaster.sendmessage',
- {buildTargetPHID => $build_target, type => 'pass'});
-
- $delete_build_target->execute($target->{name}, $target->{value});
- }
-
if (Bugzilla->datadog) {
my $dd = Bugzilla->datadog();
$dd->increment('bugzilla.phabbugz.feed_query_count');
}
sub process_revision_change {
- state $check = compile($Invocant, Revision, LinkedPhabUser, Str, Bool);
- my ($self, $revision, $changer, $story_text, $from_build_plan) = $check->(@_);
+ state $check = compile($Invocant, Revision, LinkedPhabUser, Str);
+ my ($self, $revision, $changer, $story_text) = $check->(@_);
my $is_new = $story_text =~ /\s+created\s+D\d+/;
# NO BUG ID
# If new revision and bug id was omitted, make revision public
INFO("No bug associated with new revision. Marking public.");
$revision->make_public();
- if ($revision->status eq 'draft' && !$from_build_plan) {
+ if ($revision->status eq 'draft') {
INFO("Moving from draft to needs-review");
$revision->set_status('request-review');
}
}
# Set status to request-review if revision is new and in draft state
- if ($is_new && $revision->status eq 'draft' && !$from_build_plan) {
+ if ($is_new && $revision->status eq 'draft') {
INFO("Moving from draft to needs-review");
$revision->set_status('request-review');
}
bug_revisions
check_user_enter_bug_permission
check_user_permission_for_bug
- set_build_target
);
sub _check_phabricator {
return {result => $target_user->can_enter_product($params->{product}) ? 1 : 0};
}
-sub set_build_target {
- my ($self, $params) = @_;
-
- # Phabricator only supports sending credentials via HTTP Basic Auth
- # so we exploit that function to pass in an API key as the password
- # of basic auth. BMO does not support basic auth but does support
- # use of API keys.
- my $http_auth = Bugzilla->cgi->http('Authorization');
- $http_auth =~ s/^Basic\s+//;
- $http_auth = decode_base64($http_auth);
- my ($login, $api_key) = split(':', $http_auth);
- $params->{'Bugzilla_login'} = $login;
- $params->{'Bugzilla_api_key'} = $api_key;
-
- my $user = Bugzilla->login(LOGIN_REQUIRED);
-
- $self->_validate_phab_user($user);
-
- my $revision_id = $params->{revision_id};
- my $build_target = $params->{build_target};
-
- ThrowUserError('invalid_phabricator_revision_id')
- unless detaint_natural($revision_id);
-
- ThrowUserError('invalid_phabricator_build_target')
- unless $build_target =~ /^PHID-HMBT-[a-zA-Z0-9]+$/;
- trick_taint($build_target);
-
- Bugzilla->dbh->do(
- 'INSERT INTO phabbugz (name, value) VALUES (?, ?)',
- undef, 'build_target_' . $revision_id,
- $build_target
- );
-
- return {result => 1};
-}
-
sub bug_revisions {
state $check = compile(Object, Dict [bug_id => Int]);
my ($self, $params) = $check->(@_);
sub rest_resources {
return [
- # Set build target in Phabricator
- qr{^/phabbugz/build_target/(\d+)/(PHID-HMBT-.*)$},
- {
- POST => {
- method => 'set_build_target',
- params => sub {
- return {revision_id => $_[0], build_target => $_[1]};
- }
- }
- },
-
# Bug permission checks
qr{^/phabbugz/check_bug/(\d+)/(\d+)$},
{