Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2020-10-05 23:11:52 +0000
committerThomas Wolf2020-10-05 23:40:31 +0000
commit8c0e69877e7aad6d3ec6f17a292e7ec13eb1c0fe (patch)
tree5c1af3041b7b89ea5222c1b7049ece813c6cf68f /org.eclipse.egit.github.core
parent9cf32aab3679d1f36a43addee7a8d88833d6d7d8 (diff)
downloadegit-github-8c0e69877e7aad6d3ec6f17a292e7ec13eb1c0fe.tar.gz
egit-github-8c0e69877e7aad6d3ec6f17a292e7ec13eb1c0fe.tar.xz
egit-github-8c0e69877e7aad6d3ec6f17a292e7ec13eb1c0fe.zip
[token auth] Fetch user for token if needed
There are some places in egit-github that assume that a user name is available. With token auth, the user needs not be given. Make the GitHubClient fetch it automatically if token auth is used. This should work fine for PRs and for issues. For gists, still require the user name be given in the task repository configuration. The code assumes it can get the user name from there in several places where there is no GitHubClient easily accessible. Bug: 567557 Change-Id: I5baab8c21759711fcf46897530c81e7b38f023be Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.github.core')
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
index 4ac386bb..fbd5404d 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/client/GitHubClient.java
@@ -50,6 +50,8 @@ import java.net.Proxy;
import java.net.URL;
import org.eclipse.egit.github.core.RequestError;
+import org.eclipse.egit.github.core.User;
+import org.eclipse.egit.github.core.service.UserService;
import org.eclipse.egit.github.core.util.EncodingUtils;
/**
@@ -159,6 +161,8 @@ public class GitHubClient {
private int remainingRequests = -1;
+ private boolean userSet;
+
/**
* Create default client
*/
@@ -423,6 +427,18 @@ public class GitHubClient {
* @return user or null if not authentication
*/
public String getUser() {
+ if (!userSet && user == null && credentials != null
+ && credentials.startsWith(AUTH_TOKEN)) {
+ userSet = true;
+ try {
+ User authenticatedUser = new UserService(this).getUser();
+ if (authenticatedUser != null) {
+ user = authenticatedUser.getLogin();
+ }
+ } catch (IOException e) {
+ // Ignore here
+ }
+ }
return user;
}

Back to the top