Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query GitHub for current user when using PAT #258

wants to merge 1 commit into from
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.


Just for now

@@ -176,7 +176,10 @@ public HostedRepository repository(String name) {
public HostUser user(String username) {
var details = request.get("users/" + URLEncoder.encode(username, StandardCharsets.UTF_8)).execute().asObject();
return asHostUser(details);

private static HostUser asHostUser(JSONObject details) {
// Always present
var login = details.get("login").asString();
var id = details.get("id").asInt();
@@ -196,7 +199,11 @@ public HostUser currentUser() {
var appName = appDetails.get("name").asString() + "[bot]";
currentUser = user(appName);
} else if (pat != null) {
currentUser = user(pat.username());
// Cannot always trust username in PAT, e.g. Git Credential Manager
// on Windows always return "PersonalAccessToken" as username.
// Query GitHub for the username instead.
var details = request.get("user").execute().asObject();
currentUser = asHostUser(details);
} else {
throw new IllegalStateException("No credentials present");
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.