Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-12-05 18:14:49 +0000
committerKevin Sawicki2011-12-05 18:14:49 +0000
commitff7db08b23b3fc53f01a9998a502cc9170a64307 (patch)
treee7e128e05e3d5eb0549f946edc17f59a3e2a2aa3
parent7cc26d2399ce584a18377bc581d94264bf2c7b70 (diff)
downloadegit-github-ff7db08b23b3fc53f01a9998a502cc9170a64307.tar.gz
egit-github-ff7db08b23b3fc53f01a9998a502cc9170a64307.tar.xz
egit-github-ff7db08b23b3fc53f01a9998a502cc9170a64307.zip
Use GitHubClient class to request Gist file contents.
Previously a URL connection was used which failed on Enterprise installs since credentials are needed. Using GitHubClient.getStream is now used instead with configured credentials. Change-Id: Ia18992b0aa79780cd667b06e62022d944312bfc8
-rw-r--r--org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java20
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java12
3 files changed, 25 insertions, 10 deletions
diff --git a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF
index df282604..89777c7b 100644
--- a/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.github.core/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Export-Package: org.eclipse.mylyn.internal.github.core;version="1.1.0";x-friends
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.mylyn.tasks.core;bundle-version="[3.4.0,4.0.0)",
org.eclipse.mylyn.commons.net;bundle-version="[3.4.0,4.0.0)"
-Import-Package: org.eclipse.egit.core;version="[1.2.0,1.3.0)",
+Import-Package: org.apache.http;version="[4.1.0,5.0.0)",
+ org.eclipse.egit.core;version="[1.2.0,1.3.0)",
org.eclipse.egit.github.core;version="[1.2.0,1.3.0)",
org.eclipse.egit.github.core.client;version="[1.2.0,1.3.0)",
org.eclipse.egit.github.core.service;version="[1.2.0,1.3.0)",
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
index 0b41c549..11689e53 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java
@@ -21,9 +21,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.GistFile;
import org.eclipse.egit.github.core.client.GitHubClient;
+import org.eclipse.egit.github.core.client.GitHubRequest;
import org.eclipse.egit.github.core.service.GistService;
-import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
-import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.github.core.GitHub;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -67,7 +66,16 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler {
try {
if (urlAttribute == null)
throw new IOException("Unable to obtain raw file URL from Gist"); //$NON-NLS-1$
- return new URL(urlAttribute.getValue()).openStream();
+ URL url = new URL(urlAttribute.getValue());
+ GitHubClient client = new GitHubClient(url.getHost()) {
+
+ protected String configureUri(String uri) {
+ // No prefix needed since URI is not an actual API URI
+ return uri;
+ }
+ };
+ GistConnector.configureClient(client, repository);
+ return client.getStream(new GitHubRequest().setUri(url.getFile()));
} catch (IOException e) {
throw new CoreException(GitHub.createWrappedStatus(e));
}
@@ -95,12 +103,6 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler {
gist.setFiles(Collections.singletonMap(file.getFilename(), file));
GitHubClient client = GistConnector.createClient(repository);
- AuthenticationCredentials credentials = repository
- .getCredentials(AuthenticationType.REPOSITORY);
- if (credentials != null)
- client.setCredentials(credentials.getUserName(),
- credentials.getPassword());
-
GistService service = new GistService(client);
InputStream input = source.createInputStream(monitor);
try {
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
index c86066f7..de3c6f01 100644
--- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java
@@ -49,6 +49,18 @@ public class GistConnector extends RepositoryConnector {
public static GitHubClient createClient(TaskRepository repository) {
GitHubClient client = GitHubClient.createClient(repository
.getRepositoryUrl());
+ return configureClient(client, repository);
+ }
+
+ /**
+ * Configure client for repository
+ *
+ * @param client
+ * @param repository
+ * @return client
+ */
+ public static GitHubClient configureClient(GitHubClient client,
+ TaskRepository repository) {
GitHub.addCredentials(client, repository);
return GitHub.configureClient(client);
}

Back to the top