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 by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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");