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

Commit 43d7df8

Browse files
authored
Merge branch 'master' into fixes/process-wrapper
2 parents a9af148 + 6c0791f commit 43d7df8

File tree

20 files changed

+138
-122
lines changed

20 files changed

+138
-122
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Have you read GitHub for Unity's Code of Conduct? By filing an Issue, you are ex
99
- Be sure to run with tracing enabled to capture runtime details in the log file
1010
- Include the log file in the PR.
1111
- On Windows, the extension log file is at `%LOCALAPPDATA%\GitHubUnity\github-unity.log`
12-
- On macOS, the extension log file is at `~/.local/share/GitHubUnity/github-unity.log`
12+
- On macOS, the extension log file is at `~/Library/Application Support/GitHubUnity/github-unity.log`
1313

1414
### Description
1515

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
2929
private readonly ILoginManager loginManager;
3030
private static readonly SemaphoreSlim sem = new SemaphoreSlim(1);
3131

32-
Octokit.Repository repositoryCache = new Octokit.Repository();
3332
IList<Organization> organizationsCache;
3433
Octokit.User userCache;
3534

@@ -49,13 +48,6 @@ public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClie
4948
loginManager = new LoginManager(keychain, ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
5049
}
5150

52-
public async Task GetRepository(Action<Octokit.Repository> callback)
53-
{
54-
Guard.ArgumentNotNull(callback, "callback");
55-
var repo = await GetRepositoryInternal();
56-
callback(repo);
57-
}
58-
5951
public async Task Logout(UriString host)
6052
{
6153
await LogoutInternal(host);
@@ -182,45 +174,18 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
182174
return result.Code == LoginResultCodes.Success;
183175
}
184176

185-
private async Task<Octokit.Repository> GetRepositoryInternal()
177+
private async Task CreateRepositoryInternal(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization)
186178
{
187179
try
188180
{
189-
if (owner == null)
181+
logger.Trace("Creating repository");
182+
183+
if (!await EnsureKeychainLoaded())
190184
{
191-
var ownerLogin = OriginalUrl.Owner;
192-
var repositoryName = OriginalUrl.RepositoryName;
193-
194-
if (ownerLogin != null && repositoryName != null)
195-
{
196-
var repo = await githubClient.Repository.Get(ownerLogin, repositoryName);
197-
if (repo != null)
198-
{
199-
repositoryCache = repo;
200-
}
201-
owner = ownerLogin;
202-
}
185+
callback(null, new Exception("Keychain Not Loaded"));
186+
return;
203187
}
204-
}
205-
// it'll throw if it's private or an enterprise instance requiring authentication
206-
catch (ApiException apiex)
207-
{
208-
if (!HostAddress.IsGitHubDotCom(OriginalUrl.ToRepositoryUri()))
209-
isEnterprise = apiex.IsGitHubApiException();
210-
}
211-
catch {}
212-
finally
213-
{
214-
sem.Release();
215-
}
216188

217-
return repositoryCache;
218-
}
219-
220-
private async Task CreateRepositoryInternal(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization)
221-
{
222-
try
223-
{
224189
Octokit.Repository repository;
225190
if (!string.IsNullOrEmpty(organization))
226191
{
@@ -252,6 +217,11 @@ private async Task<IList<Organization>> GetOrganizationInternal()
252217
{
253218
logger.Trace("Getting Organizations");
254219

220+
if (!await EnsureKeychainLoaded())
221+
{
222+
return null;
223+
}
224+
255225
var organizations = await githubClient.Organization.GetAllForCurrent();
256226

257227
logger.Trace("Obtained {0} Organizations", organizations?.Count.ToString() ?? "NULL");
@@ -276,6 +246,11 @@ private async Task<IList<Organization>> GetOrganizationInternal()
276246
{
277247
logger.Trace("Getting Organizations");
278248

249+
if (!await EnsureKeychainLoaded())
250+
{
251+
return null;
252+
}
253+
279254
userCache = await githubClient.User.Current();
280255
}
281256
catch(Exception ex)
@@ -287,6 +262,31 @@ private async Task<IList<Organization>> GetOrganizationInternal()
287262
return userCache;
288263
}
289264

265+
private async Task<bool> EnsureKeychainLoaded()
266+
{
267+
logger.Trace("EnsureKeychainLoaded");
268+
269+
if (keychain.HasKeys)
270+
{
271+
if (!keychain.NeedsLoad)
272+
{
273+
logger.Trace("EnsureKeychainLoaded: Has keys does not need load");
274+
return true;
275+
}
276+
277+
logger.Trace("EnsureKeychainLoaded: Loading");
278+
279+
var uriString = keychain.Connections.First().Host;
280+
var keychainAdapter = await keychain.Load(uriString);
281+
282+
return keychainAdapter.OctokitCredentials != Credentials.Anonymous;
283+
}
284+
285+
logger.Trace("EnsureKeychainLoaded: No keys to load");
286+
287+
return false;
288+
}
289+
290290
public async Task<bool> ValidateCredentials()
291291
{
292292
try

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ public virtual async Task Run(bool firstRun)
6969

7070
RestartRepository();
7171
InitializeUI();
72-
73-
new ActionTask(new Task(() => LoadKeychain().Start())).Start();
7472
}
7573

7674
public ITask InitializeRepository()
@@ -128,22 +126,6 @@ public void RestartRepository()
128126
}
129127
}
130128

131-
private async Task LoadKeychain()
132-
{
133-
Logger.Trace("Loading Keychain");
134-
135-
var firstConnection = Platform.Keychain.Hosts.FirstOrDefault();
136-
if (firstConnection == null)
137-
{
138-
Logger.Trace("No Host Found");
139-
}
140-
else
141-
{
142-
Logger.Trace("Loading Connection to Host:\"{0}\"", firstConnection);
143-
await Platform.Keychain.Load(firstConnection).SafeAwait();
144-
}
145-
}
146-
147129
private async Task<NPath> DetermineGitExecutablePath(ProgressReport progress = null)
148130
{
149131
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();

src/GitHub.Api/Application/IApiClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface IApiClient
99
{
1010
HostAddress HostAddress { get; }
1111
UriString OriginalUrl { get; }
12-
Task GetRepository(Action<Octokit.Repository> callback);
1312
Task CreateRepository(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization = null);
1413
Task GetOrganizations(Action<IList<Organization>> callback);
1514
Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result);

src/GitHub.Api/Authentication/IKeychain.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IKeychain
1515
Connection[] Connections { get; }
1616
IList<UriString> Hosts { get; }
1717
bool HasKeys { get; }
18+
bool NeedsLoad { get; }
1819
void SetToken(UriString host, string token);
1920
}
2021
}

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,7 @@ public void UpdateToken(UriString host, string token)
230230
public IList<UriString> Hosts => connectionCache.Keys.ToArray();
231231

232232
public bool HasKeys => connectionCache.Any();
233+
234+
public bool NeedsLoad => HasKeys && FindOrCreateAdapter(connectionCache.First().Value.Host).OctokitCredentials == Credentials.Anonymous;
233235
}
234236
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ private Task<NPath> LookForPortableGit()
134134

135135
private async Task<NPath> LookForSystemGit()
136136
{
137-
if (environment.IsMac)
137+
NPath path = null;
138+
if (!environment.IsWindows)
138139
{
139-
var path = "/usr/local/bin/git".ToNPath();
140-
if (path.FileExists())
141-
return path;
140+
var p = new NPath("/usr/local/bin/git");
141+
if (p.FileExists())
142+
path = p;
142143
}
143-
return await new FindExecTask("git", taskManager.Token).StartAwait();
144+
145+
if (path == null)
146+
path = await new FindExecTask("git", taskManager.Token).StartAwait();
147+
148+
return path;
144149
}
145150

146151
public bool ValidateGitInstall(NPath path)

src/GitHub.Api/Git/Tasks/GitCommitTask.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ public GitCommitTask(string message, string body,
1616

1717
Name = TaskName;
1818
arguments = "commit ";
19-
arguments += String.Format(" -m \"{0}", message);
19+
arguments += String.Format(" -m \"{0}\"", message);
2020
if (!String.IsNullOrEmpty(body))
21-
arguments += String.Format("{0}{1}", Environment.NewLine, body);
22-
arguments += "\"";
21+
arguments += String.Format(" -m \"{0}\"", body);
2322
}
2423

2524
public override string ProcessArguments { get { return arguments; } }

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<Reference Include="Mono.Security">
7070
<HintPath>$(SolutionDir)lib\Mono.Security.dll</HintPath>
7171
</Reference>
72+
<Reference Include="Mono.Posix">
73+
<HintPath>$(SolutionDir)lib\Mono.Posix.dll</HintPath>
74+
</Reference>
7275
<Reference Include="Rackspace.Threading, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bb62785d398726f0, processorArchitecture=MSIL">
7376
<HintPath>$(SolutionDir)\packages\TunnelVisionLabs.Threading.2.0.0-unity\lib\net35-client\Rackspace.Threading.dll</HintPath>
7477
<Private>True</Private>

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ public bool DirectoryExists(string append = "")
283283

284284
public bool DirectoryExists(NPath append)
285285
{
286+
if (append == null)
287+
return FileSystem.DirectoryExists(ToString());
286288
return FileSystem.DirectoryExists(Combine(append).ToString());
287289
}
288290

@@ -295,6 +297,8 @@ public bool FileExists(string append = "")
295297

296298
public bool FileExists(NPath append)
297299
{
300+
if (append == null)
301+
return FileSystem.FileExists(ToString());
298302
return FileSystem.FileExists(Combine(append).ToString());
299303
}
300304

@@ -749,11 +753,14 @@ public static NPath HomeDirectory
749753
}
750754
}
751755

756+
private static NPath systemTemp;
752757
public static NPath SystemTemp
753758
{
754759
get
755760
{
756-
return new NPath(FileSystem.GetTempPath());
761+
if (systemTemp == null)
762+
systemTemp = new NPath(FileSystem.GetTempPath());
763+
return systemTemp;
757764
}
758765
}
759766

@@ -1018,6 +1025,14 @@ public static NPath ToNPath(this string path)
10181025
return null;
10191026
return new NPath(path);
10201027
}
1028+
1029+
public static NPath Resolve(this NPath path)
1030+
{
1031+
if (path == null || DefaultEnvironment.OnWindows || path.IsRelative || !path.FileExists())
1032+
return path;
1033+
1034+
return new NPath(Mono.Unix.UnixPath.GetCompleteRealPath(path.ToString()));
1035+
}
10211036
}
10221037

10231038
public enum SlashMode

0 commit comments

Comments
 (0)