my ($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()");
- my $attachment = create_revision_attachment($bug, $revision, $timestamp);
-
+ INFO('Checking for revision attachment');
+ my $attachment = create_revision_attachment($bug, $revision, $timestamp, $revision->author->bugzilla_user);
+ INFO('Attachment ' . $attachment->id . ' created or already exists.');
+
# ATTACHMENT OBSOLETES
# fixup attachments on current bug
date => $timestamp,
phab_user_login => $phab_user->name,
phab_user_realname => $phab_user->realname,
- bugzilla_userid => $phab_user->bugzilla_user->id,
- bugzilla_login => $phab_user->bugzilla_user->login,
- bugzilla_realname => $phab_user->bugzilla_user->name,
+ bugzilla_userid => $bug_user->id,
+ bugzilla_login => $bug_user->login,
+ bugzilla_realname => $bug_user->name,
squat_userid => $row->{userid},
squat_login => $row->{login_name},
squat_realname => $row->{realname}
use List::Util qw(first);
use LWP::UserAgent;
use Taint::Util qw(untaint);
+use Try::Tiny;
use base qw(Exporter);
);
sub create_revision_attachment {
- my ( $bug, $revision, $timestamp ) = @_;
+ my ( $bug, $revision, $timestamp, $submitter ) = @_;
my $phab_base_uri = Bugzilla->params->{phabricator_base_uri};
ThrowUserError('invalid_phabricator_uri') unless $phab_base_uri;
($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()");
}
- my $attachment = Bugzilla::Attachment->create(
- {
- bug => $bug,
- creation_ts => $timestamp,
- data => $revision_uri,
- description => $revision->title,
- filename => 'phabricator-D' . $revision->id . '-url.txt',
- ispatch => 0,
- isprivate => 0,
- mimetype => PHAB_CONTENT_TYPE,
+ # If submitter, then switch to that user when creating attachment
+ my ($old_user, $attachment);
+ try {
+ if ($submitter) {
+ $old_user = Bugzilla->user;
+ $submitter->{groups} = [ Bugzilla::Group->get_all ]; # We need to always be able to add attachment
+ Bugzilla->set_user($submitter);
}
- );
- # Insert a comment about the new attachment into the database.
- $bug->add_comment($revision->summary, { type => CMT_ATTACHMENT_CREATED,
- extra_data => $attachment->id });
+ $attachment = Bugzilla::Attachment->create(
+ {
+ bug => $bug,
+ creation_ts => $timestamp,
+ data => $revision_uri,
+ description => $revision->title,
+ filename => 'phabricator-D' . $revision->id . '-url.txt',
+ ispatch => 0,
+ isprivate => 0,
+ mimetype => PHAB_CONTENT_TYPE,
+ }
+ );
+
+ # Insert a comment about the new attachment into the database.
+ $bug->add_comment($revision->summary, { type => CMT_ATTACHMENT_CREATED,
+ extra_data => $attachment->id });
+ }
+ catch {
+ die $_;
+ }
+ finally {
+ Bugzilla->set_user($old_user) if $old_user;
+ };
return $attachment;
}
sub is_attachment_phab_revision {
my ($attachment) = @_;
- return ($attachment->contenttype eq PHAB_CONTENT_TYPE
- && $attachment->attacher->login eq PHAB_AUTOMATION_USER) ? 1 : 0;
+ return $attachment->contenttype eq PHAB_CONTENT_TYPE;
}
sub get_attachment_revisions {