]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1469881 - Patches posted by Phabricator to Bugzilla don't list the patch author
authordklawren <dklawren@users.noreply.github.com>
Mon, 25 Jun 2018 19:37:53 +0000 (15:37 -0400)
committerGitHub <noreply@github.com>
Mon, 25 Jun 2018 19:37:53 +0000 (15:37 -0400)
extensions/PhabBugz/lib/Feed.pm
extensions/PhabBugz/lib/Revision.pm
extensions/PhabBugz/lib/Util.pm

index 981c95fb3a9b36c0177ae0e3091ae8f410d90460..31dd8bca0b792bb4f7b628e327aa6afb872b739f 100644 (file)
@@ -445,8 +445,10 @@ sub process_revision_change {
 
     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
@@ -641,9 +643,9 @@ sub process_new_user {
                 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}
index d87ca8bd2a21c0b61ce522d9032e018d9df7c409..854cc48d46847dc28d311ff0beaffd275f2fc02a 100644 (file)
@@ -288,7 +288,7 @@ sub _build_author {
       }
     );
     if ($phab_user) {
-        return $self->{author} = $phab_user->bugzilla_user;
+        return $self->{author} = $phab_user;
     }
 }
 
index b24124edea5c26294023bc9629b8e548c0ab103f..c4c9c79929f500d3603711f0cc451a4db3963be9 100644 (file)
@@ -22,6 +22,7 @@ use JSON::XS qw(encode_json decode_json);
 use List::Util qw(first);
 use LWP::UserAgent;
 use Taint::Util qw(untaint);
+use Try::Tiny;
 
 use base qw(Exporter);
 
@@ -39,7 +40,7 @@ our @EXPORT = qw(
 );
 
 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;
@@ -59,22 +60,38 @@ sub create_revision_attachment {
         ($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;
 }
@@ -106,8 +123,7 @@ sub get_bug_role_phids {
 
 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 {