summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2013-07-31 12:50:10 (EDT)
committerGerrit Code Review @ Eclipse.org2013-08-13 08:03:28 (EDT)
commit218959f01e2bd9533b6b034afb1f8722d255a9e8 (patch)
tree73b90c86b927e3421436fdd4b82e86cd934b48c7
parent42ea6a7628ca5f346177723ff0774e9509631a9d (diff)
downloadorg.eclipse.mylyn.reviews-218959f01e2bd9533b6b034afb1f8722d255a9e8.zip
org.eclipse.mylyn.reviews-218959f01e2bd9533b6b034afb1f8722d255a9e8.tar.gz
org.eclipse.mylyn.reviews-218959f01e2bd9533b6b034afb1f8722d255a9e8.tar.bz2
414078: reviewer with no activity shown as <Unknown> in Reviewers listrefs/changes/18/15018/4
Bug: 414078 Change-Id: Icd3b90336f7c3aa9cf0710c00e1a36866c908c5e Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=414078 Signed-off-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java47
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewerInfo.java9
-rw-r--r--org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInfoTest.java8
3 files changed, 60 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index 343d1aa..5ff18b4 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -76,6 +76,8 @@ import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Version;
import com.google.gerrit.common.data.AccountDashboardInfo;
+import com.google.gerrit.common.data.AccountInfo;
+import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.common.data.AccountService;
import com.google.gerrit.common.data.ApprovalDetail;
import com.google.gerrit.common.data.ChangeDetail;
@@ -287,14 +289,51 @@ public class GerritClient extends ReviewsClient {
getChangeDetailService(monitor).changeDetailX(id, this);
}
});
- if (changeDetail.getApprovals() == null && isVersion26OrLater(monitor)) {
- ChangeInfo changeInfo = getChangeInfo(reviewId, monitor);
- changeDetail.setApprovals(changeInfo.convertToApprovalDetails());
- changeDetail.setApprovalTypes(changeInfo.convertToApprovalTypes());
+ if (isVersion26OrLater(monitor)) {
+ if (changeDetail.getApprovals() == null) {
+ ChangeInfo changeInfo = getChangeInfo(reviewId, monitor);
+ changeDetail.setApprovals(changeInfo.convertToApprovalDetails());
+ changeDetail.setApprovalTypes(changeInfo.convertToApprovalTypes());
+ }
+ List<ReviewerInfo> reviewers = listReviewers(reviewId, monitor);
+ if (!hasAllReviewers(changeDetail.getAccounts(), reviewers)) {
+ merge(changeDetail.getAccounts(), reviewers);
+ }
}
return changeDetail;
}
+ private List<ReviewerInfo> listReviewers(final int reviewId, IProgressMonitor monitor) throws GerritException {
+ final String uri = "/changes/" + reviewId + "/reviewers/"; //$NON-NLS-1$ //$NON-NLS-2$
+ TypeToken<List<ReviewerInfo>> reviewersListType = new TypeToken<List<ReviewerInfo>>() {
+ };
+ return executeGetRestRequest(uri, reviewersListType.getType(), monitor);
+ }
+
+ private boolean hasAllReviewers(AccountInfoCache accounts, List<ReviewerInfo> reviewers) {
+ for (ReviewerInfo reviewer : reviewers) {
+ AccountInfo cachedAccount = accounts.get(new Account.Id(reviewer.getId()));
+ if (cachedAccount == null || isAnonymous(cachedAccount)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isAnonymous(AccountInfo accountInfo) {
+ return accountInfo.getFullName() == null && accountInfo.getPreferredEmail() == null;
+ }
+
+ private void merge(AccountInfoCache accounts, List<ReviewerInfo> reviewers) {
+ Set<com.google.gerrit.common.data.AccountInfo> accountInfos = new HashSet<com.google.gerrit.common.data.AccountInfo>(
+ reviewers.size());
+ for (ReviewerInfo reviewer : reviewers) {
+ accountInfos.add(reviewer.toAccountInfo());
+ }
+ AccountInfoCache accountInfoCache = new AccountInfoCache(accountInfos);
+ accounts.merge(accountInfoCache);
+ }
+
public ChangeInfo getChangeInfo(final int reviewId, IProgressMonitor monitor) throws GerritException {
final String uri = "/changes/" + reviewId + "/revisions/current/review"; //$NON-NLS-1$ //$NON-NLS-2$
return executeGetRestRequest(uri, ChangeInfo.class, monitor);
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewerInfo.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewerInfo.java
index 2a808df..2cc2f6f 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewerInfo.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/rest/ReviewerInfo.java
@@ -54,4 +54,13 @@ public class ReviewerInfo extends AccountInfo {
}
return approvalDetail;
}
+
+ public com.google.gerrit.common.data.AccountInfo toAccountInfo() {
+ Account.Id accountId = new Account.Id(getId());
+ Account account = new Account(accountId);
+ account.setFullName(getName());
+ account.setPreferredEmail(getEmail());
+ com.google.gerrit.common.data.AccountInfo accountInfo = new com.google.gerrit.common.data.AccountInfo(account);
+ return accountInfo;
+ }
}
diff --git a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInfoTest.java b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInfoTest.java
index df46145..db53e09 100644
--- a/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInfoTest.java
+++ b/org.eclipse.mylyn.gerrit.tests/src/org/eclipse/mylyn/gerrit/tests/core/client/rest/ReviewerInfoTest.java
@@ -78,6 +78,7 @@ public class ReviewerInfoTest extends TestCase {
assertEquals("john.doe@example.com", reviewerInfo.getEmail());
assertNull(reviewerInfo.getUsername());
+ // toApprovalDetail
PatchSet dummyPatchSet = new PatchSet(new PatchSet.Id(new Change.Id(1), 1));
ApprovalDetail approvalDetail = reviewerInfo.toApprovalDetail(dummyPatchSet);
assertNotNull(approvalDetail);
@@ -93,6 +94,13 @@ public class ReviewerInfoTest extends TestCase {
assertNotNull(vrif);
assertEquals(1000096, vrif.getAccountId().get());
assertEquals(1, vrif.getValue());
+
+ // toAccountInfo
+ com.google.gerrit.common.data.AccountInfo accountInfo = reviewerInfo.toAccountInfo();
+ assertNotNull(accountInfo);
+ assertEquals(1000096, accountInfo.getId().get());
+ assertEquals("john.doe@example.com", accountInfo.getPreferredEmail());
+ assertEquals("John Doe", accountInfo.getFullName());
}
private ReviewerInfo parseFile(String path) throws IOException {