Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit cd75172

Browse files
authored
Merge pull request #425 from github-for-unity/fixes/git-client-should-return-user
Changing GitClient to return User instead of string array
2 parents 985c390 + 12449b8 commit cd75172

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ITask<string> GetConfig(string key, GitConfigSource configSource,
2323
ITask<string> SetConfig(string key, string value, GitConfigSource configSource,
2424
IOutputProcessor<string> processor = null);
2525

26-
ITask<string[]> GetConfigUserAndEmail();
26+
ITask<User> GetConfigUserAndEmail();
2727

2828
ITask<List<GitLock>> ListLocks(bool local,
2929
BaseOutputListProcessor<GitLock> processor = null);
@@ -255,26 +255,28 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
255255
.Configure(processManager);
256256
}
257257

258-
public ITask<string[]> GetConfigUserAndEmail()
258+
public ITask<User> GetConfigUserAndEmail()
259259
{
260260
string username = null;
261261
string email = null;
262262

263-
return GetConfig("user.name", GitConfigSource.User).Then((success, value) => {
264-
if (success)
265-
{
266-
username = value;
267-
}
268-
269-
}).Then(GetConfig("user.email", GitConfigSource.User).Then((success, value) => {
270-
if (success)
271-
{
272-
email = value;
273-
}
274-
})).Then(success => {
275-
Logger.Trace("user.name:{1} user.email:{2}", success, username, email);
276-
return new[] { username, email };
277-
});
263+
return GetConfig("user.name", GitConfigSource.User)
264+
.Then((success, value) => {
265+
if (success)
266+
{
267+
username = value;
268+
}
269+
})
270+
.Then(GetConfig("user.email", GitConfigSource.User)
271+
.Then((success, value) => {
272+
if (success)
273+
{
274+
email = value;
275+
}
276+
})).Then(success => {
277+
Logger.Trace("{0}:{1} {2}:{3}", "user.name", username, "user.email", email);
278+
return new User { Name= username, Email = email };
279+
});
278280
}
279281

280282
public ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,9 @@ public ITask UnlockFile(string file, bool force)
299299
private void LoadGitUser()
300300
{
301301
GitClient.GetConfigUserAndEmail()
302-
.Then((success, strings) => {
303-
var username = strings[0];
304-
var email = strings[1];
305-
306-
var user = new User {
307-
Name = username,
308-
Email = email
309-
};
310-
302+
.Then((success, user) => {
311303
Logger.Trace("OnGitUserLoaded: {0}", user);
312304
OnGitUserLoaded?.Invoke(user);
313-
314305
}).Start();
315306
}
316307

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ private void CheckForUser()
9696
Logger.Trace("Checking for user");
9797
isBusy = true;
9898

99-
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
100-
var username = strings[0];
101-
var email = strings[1];
102-
99+
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => {
103100
isBusy = false;
104-
isUserDataPresent = success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email);
101+
isUserDataPresent = success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email);
105102
hasCompletedInitialCheck = true;
106103

107104
Logger.Trace("User Present: {0}", isUserDataPresent);

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,10 @@ private void MaybeUpdateData()
115115
{
116116
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
117117
{
118-
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
119-
var username = strings[0];
120-
var email = strings[1];
121-
122-
if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email))
118+
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => {
119+
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
123120
{
124-
cachedUser = new User {
125-
Name = username,
126-
Email = email
127-
};
121+
cachedUser = user;
128122

129123
userDataHasChanged = true;
130124
Redraw();

0 commit comments

Comments
 (0)