Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatasha Carson2019-03-08 18:53:17 -0500
committerNatasha Carson2019-03-26 20:02:33 -0400
commitafa2a4ff1c3c8efcc55582989c82c8e517eca821 (patch)
treede0f89f35e45c994897aa9db92d6c380546ba278
parentf2cf4c5a560940df3f4f9e336a857f5417385ff0 (diff)
downloadorg.eclipse.mylyn.reviews-m_3_25_x.tar.gz
org.eclipse.mylyn.reviews-m_3_25_x.tar.xz
org.eclipse.mylyn.reviews-m_3_25_x.zip
485981: retrieve patchset and project details via RESTR_3_25_0m_3_25_x
* Opening a review failed with "Couldn't update model" when opening a task from the Task List of a repo that has already been opened once; resolved by attempting re-authentication * NPE when retrieving patch sets on from reviews.tasktop.com; resolved * 404 error when Hudson is the Owner of the review; resolved by providing support for Hudson/Jenkins unique identifier (Hudson email is not a valid {account-id}) * ArrayIndexOutofBoundsException related to comparing patchset diffs of files; resolved Change-Id: Ie778b1cd10ac8c335f32487f039cf5553fe80349 Signed-off-by: Natasha Carson <natasha.carson@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient.java3
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java70
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient29.java8
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java7
4 files changed, 60 insertions, 28 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 ea42ad76..29e80195 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
@@ -626,7 +626,8 @@ public abstract class GerritClient extends ReviewsClient {
if (e.getResponseCode() == HttpStatus.SC_NOT_FOUND) {
reviewerResult.addError(new ReviewerResult.Error(null, reviewerId));
}
-
+ } catch (GerritLoginException e) {
+ reviewerResult.addError(new ReviewerResult.Error(null, reviewerId));
}
//Now that the reviewer has been removed, remove that reviewers approvals on the change
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java
index 88385a89..e27d12f6 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient212.java
@@ -63,6 +63,7 @@ import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountDiffPreference;
+import com.google.gerrit.reviewdb.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.ApprovalCategory;
import com.google.gerrit.reviewdb.Change;
@@ -82,6 +83,8 @@ import com.google.gerrit.reviewdb.UserIdentity;
public class GerritClient212 extends GerritClient29 {
+ private final String SELF_ACCOUNT_ID = "self"; //$NON-NLS-1$
+
protected GerritClient212(TaskRepository repository, Version version) {
super(repository, version);
}
@@ -132,13 +135,30 @@ public class GerritClient212 extends GerritClient29 {
// Use REST API, RCP was removed in 2.13
PatchSetDetail patchSetDetail = new PatchSetDetail();
CommitInfo commitInfo = retrieveCommitInfo(idTarget, monitor);
- AccountInfo accInfo = retrieveAccountInfo(commitInfo.getAuthor().getEmail(), monitor);
+
+ AccountInfo accInfo = adaptAccountInfo(commitInfo, monitor);
patchSetDetail.setInfo(adaptRestPatchSetInfo(commitInfo, accInfo, idTarget, monitor));
patchSetDetail.setPatchSet(adaptRestPatchSet(commitInfo, accInfo, idTarget, monitor));
patchSetDetail.setPatches(adaptRestPatches(idTarget, monitor));
return patchSetDetail;
}
+ private AccountInfo adaptAccountInfo(CommitInfo commitInfo, IProgressMonitor monitor) throws GerritException {
+ String accountId = commitInfo.getAuthor().getEmail();
+ for (int retries = 0;; retries++) {
+ try {
+ return retrieveAccountInfo(accountId, monitor);
+ } catch (GerritException e) {
+ if (retries < 3) {
+ accountId = commitInfo.getAuthor().getName();
+ continue;
+ } else {
+ throw e;
+ }
+ }
+ }
+ }
+
@Override
protected PatchScriptX getPatchScript(final Patch.Key key, final PatchSet.Id leftId, final PatchSet.Id rightId,
final IProgressMonitor monitor) throws GerritException {
@@ -147,10 +167,14 @@ public class GerritClient212 extends GerritClient29 {
}
String fileName = key.getFileName();
- AccountDiffPreference diffPrefs = adaptAccountDiffPref(
- retrieveAccountInfo(retrieveCommitInfo(rightId, monitor).getAuthor().getEmail(), monitor),
- retrieveDiffPrefInfo(retrieveCommitInfo(rightId, monitor).getAuthor().getEmail(), monitor));
-
+ CommitInfo commitInfo = retrieveCommitInfo(rightId, monitor);
+ AccountInfo accInfo = adaptAccountInfo(commitInfo, monitor);
+ AccountDiffPreference diffPrefs;
+ try {
+ diffPrefs = adaptAccountDiffPref(accInfo, retrieveDiffPrefInfo(monitor));
+ } catch (GerritException e) {
+ diffPrefs = null;
+ }
DiffInfo diffInfo;
if (leftId == null) {
diffInfo = retrieveDiffInfoAgainstBase(rightId, fileName, monitor);
@@ -240,24 +264,29 @@ public class GerritClient212 extends GerritClient29 {
throws GerritException {
List<DiffContent> diffContent = diffInfo.getContent(); // content differences in file
List<Edit> editsInFile = new ArrayList<>();
- int contentSize = 0;
+ int contentSize_A = 0;
+ int contentSize_B = 0;
for (DiffContent diff : diffContent) {
if (diff.getAb() != null) { // if ab, do nothing; this is not an Edit.
- contentSize += diff.getAb().size();
+ contentSize_A += diff.getAb().size();
+ contentSize_B += diff.getAb().size();
} else if (diff.getA() != null && diff.getB() != null) {
- Edit edit = new Edit(contentSize, contentSize + diff.getA().size() - 1, contentSize,
- contentSize + diff.getB().size() - 1);
+ Edit edit = new Edit(contentSize_A, contentSize_A + diff.getA().size() - 1, contentSize_B,
+ contentSize_B + diff.getB().size() - 1);
editsInFile.add(edit);
- contentSize += diff.getA().size();
+ contentSize_A += diff.getA().size();
+ contentSize_B += diff.getB().size();
patchScriptX.setIntralineDifference(true); // this behavior might not be correct
} else if (diff.getA() != null) { // content only on side a (deleted in b)
- Edit edit = new Edit(contentSize, contentSize + diff.getA().size() - 1, contentSize, contentSize);
+ Edit edit = new Edit(contentSize_A, contentSize_A + diff.getA().size() - 1, contentSize_B,
+ contentSize_B);
editsInFile.add(edit);
- contentSize += diff.getA().size();
+ contentSize_A += diff.getA().size();
} else if (diff.getB() != null) { // content only on side b (added in b)
- Edit edit = new Edit(contentSize, contentSize, contentSize, contentSize + diff.getB().size() - 1);
+ Edit edit = new Edit(contentSize_A, contentSize_A, contentSize_B,
+ contentSize_B + diff.getB().size() - 1);
editsInFile.add(edit);
- contentSize += diff.getB().size();
+ contentSize_B += diff.getB().size();
}
}
return editsInFile;
@@ -266,7 +295,9 @@ public class GerritClient212 extends GerritClient29 {
private AccountDiffPreference adaptAccountDiffPref(AccountInfo accInfo, DiffPreferencesInfo diffPrefInfo) {
AccountDiffPreference accDiffPref = new AccountDiffPreference(new Account.Id(accInfo.getId()));
accDiffPref.setContext(diffPrefInfo.getContext());
- accDiffPref.setIgnoreWhitespace(diffPrefInfo.getIgnoreWhitespace());
+ accDiffPref.setIgnoreWhitespace(diffPrefInfo.getIgnoreWhitespace() != null
+ ? diffPrefInfo.getIgnoreWhitespace()
+ : Whitespace.IGNORE_NONE);
accDiffPref.setIntralineDifference(diffPrefInfo.isIntralineDifference());
accDiffPref.setLineLength(diffPrefInfo.getLineLength());
accDiffPref.setShowTabs(diffPrefInfo.isShowTabs());
@@ -514,8 +545,8 @@ public class GerritClient212 extends GerritClient29 {
return getRestClient().executeGetRestRequest(commitQuery, mapTypeToken, monitor);
}
- private AccountInfo retrieveAccountInfo(String emailAsId, IProgressMonitor monitor) throws GerritException {
- String accQuery = String.format("/accounts/%s", encode(emailAsId)); //$NON-NLS-1$
+ private AccountInfo retrieveAccountInfo(String accountId, IProgressMonitor monitor) throws GerritException {
+ String accQuery = String.format("/accounts/%s", encode(accountId)); //$NON-NLS-1$
return getRestClient().executeGetRestRequest(accQuery, AccountInfo.class, monitor);
}
@@ -565,9 +596,8 @@ public class GerritClient212 extends GerritClient29 {
return getRestClient().executeGetRestRequest(query, ProjectAccessInfo.class, monitor);
}
- private DiffPreferencesInfo retrieveDiffPrefInfo(String emailAsId, IProgressMonitor monitor)
- throws GerritException {
- String query = String.format("/accounts/self/preferences.diff", encode(emailAsId)); //$NON-NLS-1$
+ private DiffPreferencesInfo retrieveDiffPrefInfo(IProgressMonitor monitor) throws GerritException {
+ String query = String.format("/accounts/self/preferences.diff"); //$NON-NLS-1$
return getRestClient().executeGetRestRequest(query, DiffPreferencesInfo.class, monitor);
}
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient29.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient29.java
index 5fba7c11..3c6e364a 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient29.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritClient29.java
@@ -296,7 +296,6 @@ public class GerritClient29 extends GerritClient {
@Override
public ChangeDetailX getChangeDetail(int reviewId, IProgressMonitor monitor) throws GerritException {
- ChangeDetailX changeDetail = null;
String query = "/changes/" + Integer.toString(reviewId) + "/detail/?o=ALL_REVISIONS&o=MESSAGES"; //$NON-NLS-1$//$NON-NLS-2$
ChangeInfo28 changeInfo = (ChangeInfo28) getRestClient().executeGetRestRequest(query, ChangeInfo28.class,
monitor);
@@ -330,7 +329,7 @@ public class GerritClient29 extends GerritClient {
AccountInfoCache accountInfoCache = new AccountInfoCache(listAccountInfo);
- changeDetail = new ChangeDetailX();
+ ChangeDetailX changeDetail = new ChangeDetailX();
changeDetail.setDateCreated(changeInfo.getCreated());
changeDetail.setLastModified(changeInfo.getUpdated());
changeDetail.setStarred(changeInfo.getStarred() != null ? true : false);
@@ -391,8 +390,9 @@ public class GerritClient29 extends GerritClient {
List<RelatedChangeAndCommitInfo> listCommitInfo = relatedChangesInfo.getCommitInfo();
boolean needed = true;
for (RelatedChangeAndCommitInfo relatedChangeAndCommitInfo : listCommitInfo) {
- if (relatedChangeAndCommitInfo.getCommitInfo().getCommit().equalsIgnoreCase(
- changeInfo28.getCurrentRevision())) {
+ if (relatedChangeAndCommitInfo.getCommitInfo()
+ .getCommit()
+ .equalsIgnoreCase(changeInfo28.getCurrentRevision())) {
needed = false;
} else {
if (relatedChangeAndCommitInfo.getChangeNumber() > 0) {
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
index 41b72357..e64d6275 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHttpClient.java
@@ -313,7 +313,7 @@ public class GerritHttpClient {
}
public <T> T execute(Request<T> request, IProgressMonitor monitor) throws IOException, GerritException {
- return execute(request, true, monitor);
+ return execute(request, !isAnonymous(), monitor);
}
public <T> T execute(Request<T> request, boolean authenticateIfNeeded, IProgressMonitor monitor)
@@ -378,8 +378,9 @@ public class GerritHttpClient {
} finally {
WebUtil.releaseConnection(method, monitor);
}
- if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
- // login or re-authenticate due to an expired session
+ if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN
+ || code == HttpURLConnection.HTTP_NOT_FOUND) {
+ // login or re-authenticate due to an expired session, or resource that is specified by the URL is not found or is not visible to the calling user
authenticate(openIdProvider, monitor);
this.obtainedXsrfKey = false;

Back to the top