summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-08-16 09:22:14 (EDT)
committer Steffen Pingel2011-08-16 09:22:14 (EDT)
commitc67bb592efda3576902bef89590b28f4a003b38b (patch)
treea37254b45ee504b63b138650d324be1e2ee1eeca
parent75f1f9b508a3822525c3fe988272c0a12e2942d6 (diff)
downloadorg.eclipse.mylyn.reviews-c67bb592efda3576902bef89590b28f4a003b38b.zip
org.eclipse.mylyn.reviews-c67bb592efda3576902bef89590b28f4a003b38b.tar.gz
org.eclipse.mylyn.reviews-c67bb592efda3576902bef89590b28f4a003b38b.tar.bz2
bug 354753: [patch] decorate user's comments in Gerrit reviews
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java3
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritTaskDataHandler.java60
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java6
-rw-r--r--gerrit/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritRepositorySettingsPage.java2
4 files changed, 59 insertions, 12 deletions
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
index 8486853..9da9411 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritConnector.java
@@ -8,6 +8,7 @@
* Contributors:
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
+ * GitHub, Inc. - fixes for bug 354753
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.core;
@@ -72,6 +73,8 @@ public class GerritConnector extends AbstractRepositoryConnector {
public static final String KEY_REPOSITORY_CONFIG = CONNECTOR_KIND + ".config"; //$NON-NLS-1$
+ public static final String KEY_REPOSITORY_ACCOUNT_ID = CONNECTOR_KIND + ".accountId"; //$NON-NLS-1$
+
private final GerritTaskDataHandler taskDataHandler = new GerritTaskDataHandler(this);
private TaskRepositoryLocationFactory taskRepositoryLocationFactory = new TaskRepositoryLocationFactory();
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritTaskDataHandler.java b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritTaskDataHandler.java
index 0c3b47a..c5ccc51 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritTaskDataHandler.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/GerritTaskDataHandler.java
@@ -8,9 +8,17 @@
* Contributors:
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
+ * GitHub, Inc. - fixes for bug 354753
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.core;
+import com.google.gerrit.common.data.AccountInfo;
+import com.google.gerrit.common.data.ChangeDetail;
+import com.google.gerrit.common.data.ChangeInfo;
+import com.google.gerrit.reviewdb.Account;
+import com.google.gerrit.reviewdb.Change;
+import com.google.gerrit.reviewdb.ChangeMessage;
+
import java.util.Date;
import java.util.Set;
@@ -31,16 +39,11 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
-import com.google.gerrit.common.data.AccountInfo;
-import com.google.gerrit.common.data.ChangeDetail;
-import com.google.gerrit.common.data.ChangeInfo;
-import com.google.gerrit.reviewdb.Change;
-import com.google.gerrit.reviewdb.ChangeMessage;
-
/**
* @author Mikael Kober
* @author Thomas Westling
* @author Steffen Pingel
+ * @author Kevin Sawicki
*/
public class GerritTaskDataHandler extends AbstractTaskDataHandler {
@@ -78,15 +81,42 @@ public class GerritTaskDataHandler extends AbstractTaskDataHandler {
try {
GerritClient client = connector.getClient(repository);
client.refreshConfigOnce(monitor);
+ boolean anonymous = client.isAnonymous();
+ String id = null;
+ if (!anonymous) {
+ id = getAccountId(client, repository, monitor);
+ }
GerritChange review = client.getChange(taskId, monitor);
TaskData taskData = createTaskData(repository, taskId, monitor);
- updateTaskData(repository, taskData, review, !client.isAnonymous());
+ updateTaskData(repository, taskData, review, !anonymous, id);
return taskData;
} catch (GerritException e) {
throw connector.toCoreException(repository, e);
}
}
+ /**
+ * Get account id for repository
+ *
+ * @param client
+ * @param repository
+ * @param monitor
+ * @return account id or null if not found
+ * @throws GerritException
+ */
+ protected String getAccountId(GerritClient client, TaskRepository repository, IProgressMonitor monitor)
+ throws GerritException {
+ String id = repository.getProperty(GerritConnector.KEY_REPOSITORY_ACCOUNT_ID);
+ if (id == null) {
+ Account account = client.getAccount(monitor);
+ if (account != null) {
+ id = account.getId().toString();
+ repository.setProperty(GerritConnector.KEY_REPOSITORY_ACCOUNT_ID, id);
+ }
+ }
+ return id;
+ }
+
@Override
public boolean initializeTaskData(TaskRepository repository, TaskData taskData, ITaskMapping initializationData,
IProgressMonitor monitor) {
@@ -100,7 +130,8 @@ public class GerritTaskDataHandler extends AbstractTaskDataHandler {
throw new UnsupportedOperationException();
}
- public void updateTaskData(TaskRepository repository, TaskData data, GerritChange review, boolean canPublish) {
+ public void updateTaskData(TaskRepository repository, TaskData data, GerritChange review, boolean canPublish,
+ String accountId) {
GerritTaskSchema schema = GerritTaskSchema.getDefault();
ChangeDetail changeDetail = review.getChangeDetail();
@@ -117,13 +148,20 @@ public class GerritTaskDataHandler extends AbstractTaskDataHandler {
setAttributeValue(data, schema.COMPLETED, dateToString(change.getLastUpdatedOn()));
}
int i = 1;
+ String accountName = repository.getUserName();
for (ChangeMessage message : changeDetail.getMessages()) {
TaskCommentMapper mapper = new TaskCommentMapper();
if (message.getAuthor() != null) {
AccountInfo author = changeDetail.getAccounts().get(message.getAuthor());
- IRepositoryPerson person = repository.createPerson((author.getPreferredEmail() != null)
- ? author.getPreferredEmail()
- : author.getId() + ""); //$NON-NLS-1$
+ String userName;
+ String id = author.getId().toString();
+ if (id.equals(accountId)) {
+ userName = accountName;
+ } else {
+ String email = author.getPreferredEmail();
+ userName = (email != null) ? email : id;
+ }
+ IRepositoryPerson person = repository.createPerson(userName);
person.setName(author.getFullName());
mapper.setAuthor(person);
}
diff --git a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
index 7a128dc..9070932 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java
@@ -9,6 +9,7 @@
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
* Sascha Scholz (SAP) - improvements
+ * GitHub, Inc. - fixes for bug 354753
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.core.client;
@@ -600,7 +601,10 @@ public class GerritClient {
return sl.getChanges();
}
- private Account getAccount(IProgressMonitor monitor) throws GerritException {
+ /**
+ * Returns the (possibly cached) account for this client.
+ */
+ public Account getAccount(IProgressMonitor monitor) throws GerritException {
// LoginResult result = execute(monitor, new GerritOperation<LoginResult>() {
// @Override
// public void execute(IProgressMonitor monitor) throws GerritException {
diff --git a/gerrit/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritRepositorySettingsPage.java b/gerrit/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritRepositorySettingsPage.java
index 0b2ebdc..4c9ecbc 100644
--- a/gerrit/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritRepositorySettingsPage.java
+++ b/gerrit/org.eclipse.mylyn.gerrit.ui/src/org/eclipse/mylyn/internal/gerrit/ui/GerritRepositorySettingsPage.java
@@ -8,6 +8,7 @@
* Contributors:
* Sony Ericsson/ST Ericsson - initial API and implementation
* Tasktop Technologies - improvements
+ * GitHub, Inc. - fixes for bug 354753
*********************************************************************/
package org.eclipse.mylyn.internal.gerrit.ui;
@@ -55,6 +56,7 @@ public class GerritRepositorySettingsPage extends AbstractRepositorySettingsPage
public void applyTo(TaskRepository repository) {
super.applyTo(repository);
repository.setProperty(IRepositoryConstants.PROPERTY_CATEGORY, IRepositoryConstants.CATEGORY_REVIEW);
+ repository.removeProperty(GerritConnector.KEY_REPOSITORY_ACCOUNT_ID);
}
@Override