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

Commit 7e15eb4

Browse files
Merge branch 'master' into ui/delete-branch
2 parents 53201fe + 88adbf1 commit 7e15eb4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1550
-476
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The extension log file can be found at `~/.local/share/GitHubUnityDebug/github-u
8686

8787
##### Windows
8888

89-
The extension log file can be found at `%LOCALAPPDATA%\GitHubUnityDebug\github-unity.log`
89+
The extension log file can be found at `%LOCALAPPDATA%\GitHubUnity\github-unity.log`
9090

9191
## Building and Contributing
9292

build.cmd

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@echo off
2+
setlocal
3+
4+
set Configuration=dev
5+
if not %1.==. (
6+
set Configuration=%1
7+
)
8+
9+
set Target=Build
10+
if not %2.==. (
11+
set Target=%2
12+
)
13+
14+
if %Target%==Rebuild (
15+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.dll
16+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.mdb
17+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.pdb
18+
19+
if exist "..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub" (
20+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\*.dll
21+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\*.mdb
22+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\*.pdb
23+
)
24+
)
25+
26+
call common\nuget.exe restore GitHub.Unity.sln
27+
echo xbuild GitHub.Unity.sln /verbosity:normal /property:Configuration=%Configuration% /target:%Target%
28+
call xbuild GitHub.Unity.sln /verbosity:normal /property:Configuration=%Configuration% /target:%Target%
29+
30+
echo xcopy /C /H /R /S /Y /Q unity\PackageProject\Assets\Editor\GitHub ..\github-unity-test\GitHubExtensionProject\Assets\Editor
31+
call xcopy /C /H /R /S /Y /Q unity\PackageProject\Assets\Editor\GitHub ..\github-unity-test\GitHubExtensionProject\Assets\Editor
32+
33+
del /Q unity\PackageProject\Assets\Editor\GitHub\deleteme*
34+
del /Q unity\PackageProject\Assets\Editor\GitHub\deleteme*
35+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.xml
36+
37+
if exist ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub (
38+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\deleteme*
39+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\deleteme*
40+
del /Q ..\github-unity-test\GitHubExtensionProject\Assets\Editor\GitHub\*.xml
41+
)

package.cmd

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
1-
set GITHUB_UNITY_DISABLE=1
2-
%1\Unity.exe -batchmode -projectPath %~dp0unity\PackageProject -exportPackage Assets\Editor\GitHub github-for-unity-windows.unitypackage -force-free -quit
1+
@echo off
2+
setlocal
3+
4+
set Configuration=Release
5+
6+
if %1.==. (
7+
echo Need path to Unity
8+
exit /b 1
9+
)
10+
11+
set UnityPath=%1
12+
set UnityPath=%UnityPath:"=%
13+
14+
set ChangeConfigurationToDebug=0
15+
16+
if "%2"=="debug" (
17+
set ChangeConfigurationToDebug=1
18+
)
19+
20+
if "%2"=="Debug" (
21+
set ChangeConfigurationToDebug=1
22+
)
23+
24+
if %ChangeConfigurationToDebug%==1 (
25+
set Configuration=Debug
26+
)
27+
28+
set Unity=%UnityPath%\Editor\Unity.exe
29+
if not exist "%Unity%" (
30+
echo Cannot find Unity at %Unity%
31+
exit /b 1
32+
) else (
33+
cd unity\PackageProject\Assets
34+
call git clean -xdf
35+
cd ..\..\..
36+
37+
cd src
38+
call git clean -xdf
39+
cd ..
40+
41+
call common\nuget.exe restore GitHub.Unity.sln
42+
echo xbuild GitHub.Unity.sln /property:Configuration=%Configuration%
43+
call xbuild GitHub.Unity.sln /property:Configuration=%Configuration%
44+
45+
del /Q unity\PackageProject\Assets\Editor\GitHub\deleteme*
46+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.pdb
47+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.pdb.meta
48+
del /Q unity\PackageProject\Assets\Editor\GitHub\*.xml
49+
50+
for /f tokens^=^2^ usebackq^ delims^=^" %%G in (`find "const string Version" common\SolutionInfo.cs`) do call :Package %%G
51+
52+
goto End
53+
54+
:Package
55+
set Version=%1
56+
set GITHUB_UNITY_DISABLE=1
57+
echo "%Unity%" -batchmode -projectPath "%~dp0unity\PackageProject" -exportPackage Assets/Editor/GitHub github-for-unity-%Version%-alpha.unitypackage -force-free -quit
58+
call "%Unity%" -batchmode -projectPath "%~dp0unity\PackageProject" -exportPackage Assets/Editor/GitHub github-for-unity-%Version%-alpha.unitypackage -force-free -quit
59+
goto:eof
60+
61+
:End
62+
echo Completed
63+
)
64+
endlocal

package.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@ pushd src
2222
git clean -xdf
2323
popd
2424

25-
if [ -f "$1/Unity.app/Contents/MacOS/Unity" ]; then
26-
Unity="$1/Unity.app/Contents/MacOS/Unity"
27-
elif [ -f $1/Unity ]; then
28-
Unity="$1/Unity"
29-
else
30-
echo "Can't find Unity in $1"
31-
exit 1
32-
fi
33-
3425
OS="Mac"
35-
if [ -e "/c/" ]; then
26+
if [ -e "c:\\" ]; then
3627
OS="Windows"
3728
fi
3829

30+
if [ x"$OS" == x"Windows" ]; then
31+
if [ -f "$1/Editor/Unity.exe" ]; then
32+
Unity="$1/Editor/Unity.exe"
33+
else
34+
echo "Can't find Unity in $1"
35+
exit 1
36+
fi
37+
else
38+
if [ -f "$1/Unity.app/Contents/MacOS/Unity" ]; then
39+
Unity="$1/Unity.app/Contents/MacOS/Unity"
40+
elif [ -f "$1/Unity" ]; then
41+
Unity="$1/Unity"
42+
else
43+
echo "Can't find Unity in $1"
44+
exit 1
45+
fi
46+
fi
47+
3948
if [ x"$OS" == x"Windows" ]; then
4049
common/nuget restore GitHub.Unity.sln
4150
else

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using System.Threading;
35
using System.Threading.Tasks;
46
using Octokit;
@@ -9,6 +11,8 @@ class ApiClient : IApiClient
911
{
1012
public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
1113
{
14+
logger.Trace("Creating ApiClient: {0}", repositoryUrl);
15+
1216
var credentialStore = keychain.Connect(repositoryUrl);
1317
var hostAddress = HostAddress.Create(repositoryUrl);
1418

@@ -26,6 +30,9 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
2630
private static readonly SemaphoreSlim sem = new SemaphoreSlim(1);
2731

2832
Octokit.Repository repositoryCache = new Octokit.Repository();
33+
IList<Organization> organizationsCache;
34+
Octokit.User userCache;
35+
2936
string owner;
3037
bool? isEnterprise;
3138

@@ -42,14 +49,14 @@ public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClie
4249
loginManager = new LoginManager(keychain, ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
4350
}
4451

45-
public async void GetRepository(Action<Octokit.Repository> callback)
52+
public async Task GetRepository(Action<Octokit.Repository> callback)
4653
{
4754
Guard.ArgumentNotNull(callback, "callback");
4855
var repo = await GetRepositoryInternal();
4956
callback(repo);
5057
}
5158

52-
public async void Logout(UriString host)
59+
public async Task Logout(UriString host)
5360
{
5461
await LogoutInternal(host);
5562
}
@@ -59,6 +66,26 @@ private async Task LogoutInternal(UriString host)
5966
await loginManager.Logout(host);
6067
}
6168

69+
public async Task CreateRepository(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization = null)
70+
{
71+
Guard.ArgumentNotNull(callback, "callback");
72+
await CreateRepositoryInternal(newRepository, callback, organization);
73+
}
74+
75+
public async Task GetOrganizations(Action<IList<Organization>> callback)
76+
{
77+
Guard.ArgumentNotNull(callback, "callback");
78+
var organizations = await GetOrganizationInternal();
79+
callback(organizations);
80+
}
81+
82+
public async Task GetCurrentUser(Action<Octokit.User> callback)
83+
{
84+
Guard.ArgumentNotNull(callback, "callback");
85+
var user = await GetCurrentUserInternal();
86+
callback(user);
87+
}
88+
6289
public async Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result)
6390
{
6491
Guard.ArgumentNotNull(need2faCode, "need2faCode");
@@ -190,6 +217,74 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
190217
return repositoryCache;
191218
}
192219

220+
private async Task CreateRepositoryInternal(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization)
221+
{
222+
try
223+
{
224+
logger.Trace("Creating Repository");
225+
226+
Octokit.Repository repository;
227+
if (organization != null)
228+
{
229+
repository = await githubClient.Repository.Create(organization, newRepository);
230+
}
231+
else
232+
{
233+
repository = await githubClient.Repository.Create(newRepository);
234+
}
235+
236+
logger.Trace("Created Repository");
237+
238+
callback(repository, null);
239+
}
240+
catch (Exception ex)
241+
{
242+
logger.Error(ex, "Error Creating Repository");
243+
callback(null, ex);
244+
}
245+
}
246+
247+
private async Task<IList<Organization>> GetOrganizationInternal()
248+
{
249+
try
250+
{
251+
logger.Trace("Getting Organizations");
252+
253+
var organizations = await githubClient.Organization.GetAllForCurrent();
254+
255+
logger.Trace("Obtained {0} Organizations", organizations?.Count.ToString() ?? "NULL");
256+
257+
if (organizations != null)
258+
{
259+
organizationsCache = organizations.ToArray();
260+
}
261+
}
262+
catch(Exception ex)
263+
{
264+
logger.Error(ex, "Error Getting Organizations");
265+
throw;
266+
}
267+
268+
return organizationsCache;
269+
}
270+
271+
private async Task<Octokit.User> GetCurrentUserInternal()
272+
{
273+
try
274+
{
275+
logger.Trace("Getting Organizations");
276+
277+
userCache = await githubClient.User.Current();
278+
}
279+
catch(Exception ex)
280+
{
281+
logger.Error(ex, "Error Getting Current User");
282+
throw;
283+
}
284+
285+
return userCache;
286+
}
287+
193288
public async Task<bool> ValidateCredentials()
194289
{
195290
try

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,10 @@ public virtual async Task Run(bool firstRun)
5252
}
5353
else
5454
{
55-
var progress = new ProgressReport();
56-
57-
var gitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
58-
var gitSetup = new GitInstaller(Environment, CancellationToken);
59-
var expectedPath = gitSetup.GitInstallationPath;
60-
var setupDone = await gitSetup.SetupIfNeeded(progress.Percentage, progress.Remaining);
61-
if (setupDone)
62-
Environment.GitExecutablePath = gitSetup.GitExecutablePath;
63-
else
64-
Environment.GitExecutablePath = await LookForGitInstallationPath(gitClient, SystemSettings).SafeAwait();
65-
66-
GitClient = gitClient;
55+
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
56+
Environment.GitExecutablePath = await DetermineGitExecutablePath();
6757

68-
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());
58+
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());
6959

7060
if (Environment.IsWindows)
7161
{
@@ -152,7 +142,7 @@ private async Task LoadKeychain()
152142
{
153143
Logger.Trace("Loading Keychain");
154144

155-
var firstConnection = Platform.Keychain.Connections.FirstOrDefault();
145+
var firstConnection = Platform.Keychain.Hosts.FirstOrDefault();
156146
if (firstConnection == null)
157147
{
158148
Logger.Trace("No Host Found");
@@ -164,19 +154,25 @@ private async Task LoadKeychain()
164154
}
165155
}
166156

167-
private static async Task<NPath> LookForGitInstallationPath(IGitClient gitClient, ISettings systemSettings)
157+
private async Task<NPath> DetermineGitExecutablePath(ProgressReport progress = null)
168158
{
169-
NPath cachedGitInstallPath = null;
170-
var path = systemSettings.Get(Constants.GitInstallPathKey);
171-
if (!String.IsNullOrEmpty(path))
172-
cachedGitInstallPath = path.ToNPath();
159+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
160+
if (gitExecutablePath != null && gitExecutablePath.FileExists())
161+
{
162+
Logger.Trace("Using git install path from settings");
163+
return gitExecutablePath;
164+
}
173165

174-
// Root paths
175-
if (cachedGitInstallPath != null && cachedGitInstallPath.DirectoryExists())
166+
var gitInstaller = new GitInstaller(Environment, CancellationToken);
167+
var setupDone = await gitInstaller.SetupIfNeeded(progress?.Percentage, progress?.Remaining);
168+
if (setupDone)
176169
{
177-
return cachedGitInstallPath;
170+
Logger.Trace("Setup performed using new path");
171+
return gitInstaller.GitExecutablePath;
178172
}
179-
return await gitClient.FindGitInstallation();
173+
174+
Logger.Trace("Finding git install path");
175+
return await GitClient.FindGitInstallation().SafeAwait();
180176
}
181177

182178
protected void SetupMetrics(string unityVersion, bool firstRun)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
using System.Threading.Tasks;
22
using Octokit;
33
using System;
4+
using System.Collections.Generic;
45

56
namespace GitHub.Unity
67
{
78
interface IApiClient
89
{
910
HostAddress HostAddress { get; }
1011
UriString OriginalUrl { get; }
11-
void GetRepository(Action<Octokit.Repository> callback);
12+
Task GetRepository(Action<Octokit.Repository> callback);
13+
Task CreateRepository(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization = null);
14+
Task GetOrganizations(Action<IList<Organization>> callback);
1215
Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result);
1316
Task ContinueLogin(LoginResult loginResult, string code);
1417
Task<bool> LoginAsync(string username, string password, Func<LoginResult, string> need2faCode);
1518
Task<bool> ValidateCredentials();
16-
void Logout(UriString host);
19+
Task Logout(UriString host);
20+
Task GetCurrentUser(Action<Octokit.User> callback);
1721
}
1822
}

0 commit comments

Comments
 (0)