mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-19 12:32:26 +08:00
GitSetup: Get the user's name + email from the GitHost
This way they aren't committing under the name of 'GitJournal'.
This commit is contained in:
@ -177,4 +177,33 @@ class GitHub implements GitHost {
|
||||
cloneUrl: parsedJson['ssh_url'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserInfo> getUserInfo() async {
|
||||
if (_accessCode.isEmpty) {
|
||||
throw GitHostException.MissingAccessCode;
|
||||
}
|
||||
|
||||
var url = "https://api.github.com/user?access_token=$_accessCode";
|
||||
|
||||
var response = await http.get(url);
|
||||
if (response.statusCode != 200) {
|
||||
print("Github getUserInfo: Invalid response " +
|
||||
response.statusCode.toString() +
|
||||
": " +
|
||||
response.body);
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> map = jsonDecode(response.body);
|
||||
if (map == null || map.isEmpty) {
|
||||
print("Github getUserInfo: jsonDecode Failed " +
|
||||
response.statusCode.toString() +
|
||||
": " +
|
||||
response.body);
|
||||
return null;
|
||||
}
|
||||
|
||||
return UserInfo(name: map['name'], email: map['email']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user