summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/lib/Util.pm
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/PhabBugz/lib/Util.pm')
-rw-r--r--extensions/PhabBugz/lib/Util.pm103
1 files changed, 16 insertions, 87 deletions
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index 42da79c39..916455e24 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -34,10 +34,7 @@ our @EXPORT_OK = qw(
edit_revision_policy
get_attachment_revisions
get_bug_role_phids
- get_members_by_bmo_id
- get_members_by_phid
get_needs_review
- get_phab_bmo_ids
get_project_phid
get_revisions_by_ids
get_revisions_by_phids
@@ -134,7 +131,13 @@ sub get_bug_role_phids {
push(@bug_users, $bug->qa_contact) if $bug->qa_contact;
push(@bug_users, @{ $bug->cc_users }) if @{ $bug->cc_users };
- return get_members_by_bmo_id(\@bug_users);
+ my $phab_users = Bugzilla::Extension::PhabBugz::User->match(
+ {
+ ids => [ map { $_->id } @bug_users ]
+ }
+ );
+
+ return [ map { $_->phid } @$phab_users ];
}
sub create_private_revision_policy {
@@ -354,84 +357,6 @@ sub set_project_members {
return $result->{result}{object}{phid};
}
-sub get_members_by_bmo_id {
- my $users = shift;
-
- my $result = get_phab_bmo_ids({ ids => [ map { $_->id } @$users ] });
-
- my @phab_ids;
- foreach my $user (@$result) {
- push(@phab_ids, $user->{phid})
- if ($user->{phid} && $user->{phid} =~ /^PHID-USER/);
- }
-
- return \@phab_ids;
-}
-
-sub get_members_by_phid {
- my $phids = shift;
-
- my $result = get_phab_bmo_ids({ phids => $phids });
-
- my @bmo_ids;
- foreach my $user (@$result) {
- push(@bmo_ids, $user->{id})
- if ($user->{phid} && $user->{phid} =~ /^PHID-USER/);
- }
-
- return \@bmo_ids;
-}
-
-sub get_phab_bmo_ids {
- my ($params) = @_;
- my $memcache = Bugzilla->memcached;
-
- # Try to find the values in memcache first
- my @results;
- if ($params->{ids}) {
- my @bmo_ids = @{ $params->{ids} };
- for (my $i = 0; $i < @bmo_ids; $i++) {
- my $phid = $memcache->get({ key => "phab_user_bmo_id_" . $bmo_ids[$i] });
- if ($phid) {
- push(@results, {
- id => $bmo_ids[$i],
- phid => $phid
- });
- splice(@bmo_ids, $i, 1);
- }
- }
- $params->{ids} = \@bmo_ids;
- }
-
- if ($params->{phids}) {
- my @phids = @{ $params->{phids} };
- for (my $i = 0; $i < @phids; $i++) {
- my $bmo_id = $memcache->get({ key => "phab_user_phid_" . $phids[$i] });
- if ($bmo_id) {
- push(@results, {
- id => $bmo_id,
- phid => $phids[$i]
- });
- splice(@phids, $i, 1);
- }
- }
- $params->{phids} = \@phids;
- }
-
- my $result = request('bugzilla.account.search', $params);
-
- # Store new values in memcache for later retrieval
- foreach my $user (@{ $result->{result} }) {
- $memcache->set({ key => "phab_user_bmo_id_" . $user->{id},
- value => $user->{phid} });
- $memcache->set({ key => "phab_user_phid_" . $user->{phid},
- value => $user->{id} });
- push(@results, $user);
- }
-
- return \@results;
-}
-
sub is_attachment_phab_revision {
my ($attachment) = @_;
return ($attachment->contenttype eq PHAB_CONTENT_TYPE
@@ -559,9 +484,13 @@ sub get_needs_review {
$user //= Bugzilla->user;
return unless $user->id;
- my $ids = get_members_by_bmo_id([$user]);
- return [] unless @$ids;
- my $phid_user = $ids->[0];
+ my $phab_user = Bugzilla::Extension::PhabBugz::User->new_from_query(
+ {
+ ids => [ $user->id ]
+ }
+ );
+
+ return [] unless $phab_user;
my $diffs = request(
'differential.revision.search',
@@ -570,7 +499,7 @@ sub get_needs_review {
reviewers => 1,
},
constraints => {
- reviewerPHIDs => [$phid_user],
+ reviewerPHIDs => [$phab_user->phid],
statuses => [qw( needs-review )],
},
order => 'newest',
@@ -584,7 +513,7 @@ sub get_needs_review {
foreach my $diff (@{ $diffs->{result}{data} }) {
my $attachments = delete $diff->{attachments};
my $reviewers = $attachments->{reviewers}{reviewers};
- my $review = first { $_->{reviewerPHID} eq $phid_user } @$reviewers;
+ my $review = first { $_->{reviewerPHID} eq $phab_user->phid } @$reviewers;
$diff->{fields}{review_status} = $review->{status};
push @result, $diff;
}