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

Commit f513c3e

Browse files
Merge branch 'master' into enhancement/application-cache
2 parents 516dbe6 + fa937a0 commit f513c3e

Some content is hidden

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

43 files changed

+898
-310
lines changed

CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [http://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: http://contributor-covenant.org
74+
[version]: http://contributor-covenant.org/version/1/4/

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ fi
3434

3535
xbuild GitHub.Unity.sln /property:Configuration=$Configuration /target:$Target
3636

37+
cp -r unity/PackageProject/Assets/Editor/GitHub ../github-unity-test/GitHubExtensionProject/Assets/Editor || true
38+
3739
rm -f unity/PackageProject/Assets/Editor/GitHub/deleteme*
3840
rm -f unity/PackageProject/Assets/Editor/GitHub/deleteme*
3941
rm -f unity/PackageProject/Assets/Editor/GitHub/*.xml

common/SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
namespace System
2929
{
3030
internal static class AssemblyVersionInformation {
31-
internal const string Version = "0.10.0.0";
31+
internal const string Version = "0.11.0.0";
3232
}
3333
}

src/GitHub.Api/Api/ApiClient.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,39 @@ namespace GitHub.Unity
77
{
88
class ApiClient : IApiClient
99
{
10+
public static IApiClient Create(UriString repositoryUrl, IKeychain keychain, IAppConfiguration appConfiguration)
11+
{
12+
var credentialStore = keychain.Connect(repositoryUrl);
13+
var hostAddress = HostAddress.Create(repositoryUrl);
14+
15+
return new ApiClient(repositoryUrl, keychain,
16+
new GitHubClient(appConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
17+
}
18+
1019
private static readonly Unity.ILogging logger = Unity.Logging.GetLogger<ApiClient>();
1120
public HostAddress HostAddress { get; }
1221
public UriString OriginalUrl { get; }
1322

23+
private readonly IKeychain keychain;
1424
private readonly IGitHubClient githubClient;
15-
private readonly IGitHubClient githubAppClient;
16-
private readonly ICredentialManager credentialManager;
1725
private readonly ILoginManager loginManager;
1826
private static readonly SemaphoreSlim sem = new SemaphoreSlim(1);
1927

2028
Octokit.Repository repositoryCache = new Octokit.Repository();
2129
string owner;
2230
bool? isEnterprise;
2331

24-
public ApiClient(UriString hostUrl, ICredentialManager credentialManager, IGitHubClient githubClient, IGitHubClient githubAppClient)
32+
public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClient)
2533
{
2634
Guard.ArgumentNotNull(hostUrl, nameof(hostUrl));
27-
Guard.ArgumentNotNull(credentialManager, nameof(credentialManager));
35+
Guard.ArgumentNotNull(keychain, nameof(keychain));
2836
Guard.ArgumentNotNull(githubClient, nameof(githubClient));
2937

3038
HostAddress = HostAddress.Create(hostUrl);
3139
OriginalUrl = hostUrl;
40+
this.keychain = keychain;
3241
this.githubClient = githubClient;
33-
this.githubAppClient = githubAppClient;
34-
this.credentialManager = credentialManager;
35-
loginManager = new LoginManager(credentialManager, ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
42+
loginManager = new LoginManager(keychain, ApplicationInfo.ClientId, ApplicationInfo.ClientSecret);
3643
}
3744

3845
public async void GetRepository(Action<Octokit.Repository> callback)
@@ -54,6 +61,7 @@ public async Task Login(string username, string password, Action<LoginResult> ne
5461
}
5562
catch (Exception ex)
5663
{
64+
logger.Warning(ex);
5765
result(false, ex.Message);
5866
return;
5967
}
@@ -176,10 +184,12 @@ public async Task<bool> ValidateCredentials()
176184
{
177185
try
178186
{
179-
var credential = await credentialManager.Load(OriginalUrl);
180-
if (credential != null)
187+
var store = keychain.Connect(OriginalUrl);
188+
189+
if (store.OctokitCredentials != Credentials.Anonymous)
181190
{
182-
await githubAppClient.Authorization.CheckApplicationAuthentication(ApplicationInfo.ClientId, credential.Token);
191+
var credential = store.Credential;
192+
await githubClient.Authorization.CheckApplicationAuthentication(ApplicationInfo.ClientId, credential.Token);
183193
}
184194
}
185195
catch

src/GitHub.Api/Api/ApiClientFactory.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/GitHub.Api/Api/IApiClientFactory.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/GitHub.Api/AppConfiguration.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,11 @@ class AppConfiguration : IAppConfiguration
88
{
99
public AppConfiguration()
1010
{
11-
applicationName = ApplicationInfo.ApplicationName;
12-
applicationDescription = ApplicationInfo.ApplicationDescription;
13-
1411
var executingAssembly = typeof(AppConfiguration).Assembly;
1512
AssemblyName = executingAssembly.GetName();
1613
ProductHeader = new ProductHeaderValue(ApplicationInfo.ApplicationSafeName, AssemblyName.Version.ToString());
1714
}
1815

19-
readonly string applicationName;
20-
readonly string applicationDescription;
21-
22-
/// <summary>
23-
/// Name of this application
24-
/// </summary>
25-
public string ApplicationName { get { return applicationName; } }
26-
27-
/// <summary>
28-
/// Name of this application
29-
/// </summary>
30-
public string ApplicationDescription { get { return applicationDescription; } }
31-
3216
/// <summary>
3317
/// The currently executing assembly.
3418
/// </summary>

src/GitHub.Api/ApplicationManagerBase.cs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ApplicationManagerBase : IApplicationManager
88
{
99
protected static readonly ILogging logger = Logging.GetLogger<IApplicationManager>();
1010

11+
private AppConfiguration appConfiguration;
1112
private RepositoryLocator repositoryLocator;
1213
private RepositoryManager repositoryManager;
1314

@@ -24,14 +25,21 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
2425
protected void Initialize(IUIDispatcher uiDispatcher)
2526
{
2627
// accessing Environment triggers environment initialization if it hasn't happened yet
28+
Platform = new Platform(Environment, FileSystem, uiDispatcher);
29+
30+
UserSettings = new UserSettings(Environment);
31+
UserSettings.Initialize();
32+
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
33+
2734
LocalSettings = new LocalSettings(Environment);
28-
UserSettings = new UserSettings(Environment, ApplicationInfo.ApplicationName);
29-
SystemSettings = new SystemSettings(Environment, ApplicationInfo.ApplicationName);
35+
LocalSettings.Initialize();
36+
37+
SystemSettings = new SystemSettings(Environment);
38+
SystemSettings.Initialize();
39+
3040

31-
Platform = new Platform(Environment, FileSystem, uiDispatcher);
3241
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
33-
Platform.Initialize(ProcessManager);
34-
ApiClientFactory.Instance = new ApiClientFactory(new AppConfiguration(), Platform.CredentialManager);
42+
Platform.Initialize(Environment, ProcessManager);
3543
}
3644

3745
public virtual Task Run()
@@ -119,9 +127,28 @@ private async Task RunInternal()
119127
logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());
120128

121129
await RestartRepository();
122-
}
123130

131+
if (Environment.IsWindows)
132+
{
133+
string credentialHelper = null;
134+
var gitConfigGetTask = new GitConfigGetTask(Environment, ProcessManager,
135+
new TaskResultDispatcher<string>(s => {
136+
credentialHelper = s;
137+
}), "credential.helper", GitConfigSource.Global);
138+
139+
140+
await gitConfigGetTask.RunAsync(CancellationToken.None);
124141

142+
if (string.IsNullOrEmpty(credentialHelper))
143+
{
144+
var gitConfigSetTask = new GitConfigSetTask(Environment, ProcessManager,
145+
new TaskResultDispatcher<string>(s => { }), "credential.helper", "wincred",
146+
GitConfigSource.Global);
147+
148+
await gitConfigSetTask.RunAsync(CancellationToken.None);
149+
}
150+
}
151+
}
125152

126153
private async Task<string> LookForGitInstallationPath()
127154
{
@@ -149,8 +176,8 @@ protected virtual void Dispose(bool disposing)
149176
{
150177
if (disposed) return;
151178
disposed = true;
152-
CancellationTokenSource.Cancel();
153-
repositoryManager.Dispose();
179+
if (CancellationTokenSource != null) CancellationTokenSource.Cancel();
180+
if (repositoryManager != null) repositoryManager.Dispose();
154181
}
155182
}
156183

@@ -159,6 +186,14 @@ public void Dispose()
159186
Dispose(true);
160187
}
161188

189+
public AppConfiguration AppConfiguration
190+
{
191+
get
192+
{
193+
return appConfiguration ?? (appConfiguration = new AppConfiguration());
194+
}
195+
}
196+
162197
public virtual IEnvironment Environment { get; set; }
163198
public IFileSystem FileSystem { get; protected set; }
164199
public IPlatform Platform { get; protected set; }

src/GitHub.Api/Authentication/AppCredentialStore.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/GitHub.Api/Authentication/CredentialStore.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)