Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b6050c9

Browse files
committed
Merge branch 'master' into refactor/usage-tracker
Conflicts: src/GitHub.App/Models/RepositoryHost.cs src/GitHub.VisualStudio/source.extension.vsixmanifest src/MsiInstaller/Version.wxi src/common/SolutionInfo.cs
2 parents 7b1a37f + ad67d7f commit b6050c9

File tree

71 files changed

+589
-798
lines changed

Some content is hidden

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

71 files changed

+589
-798
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# GitHub Extension for Visual Studio
22

3-
**The location of the submodules has changed as of 31-01-2017.** If you have an existing clone, make sure to run `git submodule sync` to update your local clone with the new locations for the submodules.
3+
## Notices
4+
5+
### VS 2017 v15.3 users, please read
6+
7+
If you need to downgrade or uninstall the extension, **do not use** ***Revert*** in Visual Studio 2017 15.3. Instead, manually uninstall the extension with the steps listed in https://github.com/github/VisualStudio/issues/1206#issuecomment-326558902
8+
9+
If you have a corrupted extension cache, steps for fixing it are in https://github.com/github/VisualStudio/issues/1206#issuecomment-326053090
10+
11+
The Visual Studio 2017 15.3 installer [has a bug](https://github.com/github/VisualStudio/issues/1206) that causes a corruption of the installed extensions data when you revert an installation of the extension (see also [this MS issue](https://developercommunity.visualstudio.com/content/problem/102178/error-installing-github-extension.html)). Until VS 2017 15.4 comes out, **do not use Revert in** ***Extensions and Updates***.
12+
13+
### The location of the submodules has changed as of 31-01-2017
14+
15+
If you have an existing clone, make sure to run `git submodule sync` to update your local clone with the new locations for the submodules.
16+
17+
## About
418

519
The GitHub Extension for Visual Studio provides GitHub integration in Visual Studio 2015.
620
Most of the extension UI lives in the Team Explorer pane, which is available from the View menu.

script

src/GitHub.Api/WindowsLoginCache.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public Task SaveLogin(string userName, string password, HostAddress hostAddress)
3939
Guard.ArgumentNotEmptyString(password, nameof(password));
4040
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
4141

42+
var keyGit = GetKeyGit(hostAddress.CredentialCacheKeyHost);
4243
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
4344

45+
using (var credential = new Credential(userName, password, keyGit))
46+
{
47+
credential.Save();
48+
}
49+
4450
using (var credential = new Credential(userName, password, keyHost))
4551
{
4652
credential.Save();
@@ -54,8 +60,16 @@ public Task EraseLogin(HostAddress hostAddress)
5460
{
5561
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
5662

63+
var keyGit = GetKeyGit(hostAddress.CredentialCacheKeyHost);
5764
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
5865

66+
using (var credential = new Credential())
67+
{
68+
credential.Target = keyGit;
69+
credential.Type = CredentialType.Generic;
70+
credential.Delete();
71+
}
72+
5973
using (var credential = new Credential())
6074
{
6175
credential.Target = keyHost;
@@ -66,6 +80,17 @@ public Task EraseLogin(HostAddress hostAddress)
6680
return Task.CompletedTask;
6781
}
6882

83+
static string GetKeyGit(string key)
84+
{
85+
key = FormatKey(key);
86+
// it appears this is how MS expects the host key
87+
if (!key.StartsWith("git:", StringComparison.Ordinal))
88+
key = "git:" + key;
89+
if (key.EndsWith("/", StringComparison.Ordinal))
90+
key = key.Substring(0, key.Length - 1);
91+
return key;
92+
}
93+
6994
static string GetKeyHost(string key)
7095
{
7196
key = FormatKey(key);

src/GitHub.App/Api/ApiClient.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public partial class ApiClient : IApiClient
2626
const string ScopesHeader = "X-OAuth-Scopes";
2727
const string ProductName = Info.ApplicationInfo.ApplicationDescription;
2828
static readonly Logger log = LogManager.GetCurrentClassLogger();
29-
static readonly Uri userEndpoint = new Uri("user", UriKind.Relative);
3029

3130
readonly IObservableGitHubClient gitHubClient;
3231
// There are two sets of authorization scopes, old and new:
@@ -96,30 +95,9 @@ public IObservable<Gist> CreateGist(NewGist newGist)
9695
return gitHubClient.Gist.Create(newGist);
9796
}
9897

99-
public IObservable<UserAndScopes> GetUser()
98+
public IObservable<User> GetUser()
10099
{
101-
return GetUserInternal().ToObservable();
102-
}
103-
104-
async Task<UserAndScopes> GetUserInternal()
105-
{
106-
var response = await gitHubClient.Connection.Get<User>(
107-
userEndpoint, null, null).ConfigureAwait(false);
108-
var scopes = default(string[]);
109-
110-
if (response.HttpResponse.Headers.ContainsKey(ScopesHeader))
111-
{
112-
scopes = response.HttpResponse.Headers[ScopesHeader]
113-
.Split(',')
114-
.Select(x => x.Trim())
115-
.ToArray();
116-
}
117-
else
118-
{
119-
log.Error($"Error reading scopes: /user succeeded but {ScopesHeader} was not present.");
120-
}
121-
122-
return new UserAndScopes(response.Body, scopes);
100+
return gitHubClient.User.Current();
123101
}
124102

125103
public IObservable<ApplicationAuthorization> GetOrCreateApplicationAuthenticationCode(

src/GitHub.App/Controllers/UIController.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ void ConfigureUIHandlingStates()
319319
ConfigureEntriesExitsForView(UIViewType.Login);
320320
ConfigureEntriesExitsForView(UIViewType.TwoFactor);
321321
ConfigureEntriesExitsForView(UIViewType.Gist);
322-
ConfigureEntriesExitsForView(UIViewType.LogoutRequired);
323322
ConfigureEntriesExitsForView(UIViewType.StartPageClone);
324323

325324
uiStateMachine.Configure(UIViewType.End)
@@ -421,7 +420,6 @@ void ConfigureLogicStates()
421420
ConfigureSingleViewLogic(UIControllerFlow.Create, UIViewType.Create);
422421
ConfigureSingleViewLogic(UIControllerFlow.Gist, UIViewType.Gist);
423422
ConfigureSingleViewLogic(UIControllerFlow.Home, UIViewType.PRList);
424-
ConfigureSingleViewLogic(UIControllerFlow.LogoutRequired, UIViewType.LogoutRequired);
425423
ConfigureSingleViewLogic(UIControllerFlow.Publish, UIViewType.Publish);
426424
ConfigureSingleViewLogic(UIControllerFlow.PullRequestList, UIViewType.PRList);
427425
ConfigureSingleViewLogic(UIControllerFlow.PullRequestDetail, UIViewType.PRDetail);
@@ -448,11 +446,7 @@ UIControllerFlow SelectActiveFlow()
448446
{
449447
var host = connection != null ? hosts.LookupHost(connection.HostAddress) : null;
450448
var loggedIn = host?.IsLoggedIn ?? false;
451-
if (!loggedIn || selectedFlow != UIControllerFlow.Gist)
452-
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
453-
454-
var supportsGist = host?.SupportsGist ?? false;
455-
return supportsGist ? selectedFlow : UIControllerFlow.LogoutRequired;
449+
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
456450
}
457451

458452
/// <summary>

src/GitHub.App/GitHub.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
<Compile Include="ViewModels\NotAGitRepositoryViewModel.cs" />
217217
<Compile Include="ViewModels\NotAGitHubRepositoryViewModel.cs" />
218218
<Compile Include="ViewModels\LoggedOutViewModel.cs" />
219-
<Compile Include="ViewModels\LogoutRequiredViewModel.cs" />
220219
<Compile Include="ViewModels\PullRequestCreationViewModel.cs" />
221220
<Compile Include="ViewModels\PullRequestDetailViewModel.cs" />
222221
<Compile Include="ViewModels\PullRequestDirectoryNode.cs" />

src/GitHub.App/Models/DisconnectedRepositoryHosts.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public DisconnectedRepositoryHost()
2525

2626
public bool IsLoggedIn { get; private set; }
2727
public bool IsLoggingIn { get; private set; }
28-
public bool SupportsGist { get; private set; }
2928
public ReactiveList<IAccount> Organizations { get; private set; }
3029
public ReactiveList<IAccount> Accounts { get; private set; }
3130
public string Title { get; private set; }

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ namespace GitHub.Models
2727
public class RepositoryHost : ReactiveObject, IRepositoryHost
2828
{
2929
static readonly Logger log = LogManager.GetCurrentClassLogger();
30-
static readonly UserAndScopes unverifiedUser = new UserAndScopes(null, null);
3130

3231
readonly ILoginManager loginManager;
3332
readonly HostAddress hostAddress;
@@ -65,8 +64,6 @@ public bool IsLoggedIn
6564
private set { this.RaiseAndSetIfChanged(ref isLoggedIn, value); }
6665
}
6766

68-
public bool SupportsGist { get; private set; }
69-
7067
public string Title { get; private set; }
7168

7269
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
@@ -82,7 +79,7 @@ public IObservable<AuthenticationResult> LogInFromCache()
8279
await usage.IncrementCounter(x => x.NumberOfLogins);
8380
await ModelService.InsertUser(accountCacheItem);
8481

85-
if (user != unverifiedUser.User)
82+
if (user != null)
8683
{
8784
IsLoggedIn = true;
8885
return AuthenticationResult.Success;
@@ -114,7 +111,7 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
114111
await usage.IncrementCounter(x => x.NumberOfLogins);
115112
await ModelService.InsertUser(accountCacheItem);
116113

117-
if (user != unverifiedUser.User)
114+
if (user != null)
118115
{
119116
IsLoggedIn = true;
120117
return Observable.Return(AuthenticationResult.Success);
@@ -151,53 +148,6 @@ public IObservable<Unit> LogOut()
151148
});
152149
}
153150

154-
static IObservable<AuthenticationResult> GetAuthenticationResultForUser(UserAndScopes account)
155-
{
156-
return Observable.Return(account == null ? AuthenticationResult.CredentialFailure
157-
: account == unverifiedUser
158-
? AuthenticationResult.VerificationFailure
159-
: AuthenticationResult.Success);
160-
}
161-
162-
IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
163-
{
164-
return GetAuthenticationResultForUser(userAndScopes)
165-
.SelectMany(result =>
166-
{
167-
if (result.IsSuccess())
168-
{
169-
var accountCacheItem = new AccountCacheItem(userAndScopes.User);
170-
usage.IncrementCounter(x => x.NumberOfLogins).Forget();
171-
return ModelService.InsertUser(accountCacheItem).Select(_ => result);
172-
}
173-
174-
if (result == AuthenticationResult.VerificationFailure)
175-
{
176-
return loginCache.EraseLogin(Address).Select(_ => result);
177-
}
178-
return Observable.Return(result);
179-
})
180-
.ObserveOn(RxApp.MainThreadScheduler)
181-
.Do(result =>
182-
{
183-
if (result.IsSuccess())
184-
{
185-
SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
186-
IsLoggedIn = true;
187-
}
188-
189-
log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
190-
userAndScopes?.User?.Login ?? "(null)",
191-
hostAddress.ApiUri,
192-
result.IsSuccess() ? "SUCCEEDED" : "FAILED");
193-
});
194-
}
195-
196-
IObservable<UserAndScopes> GetUserFromApi()
197-
{
198-
return Observable.Defer(() => ApiClient.GetUser());
199-
}
200-
201151
protected virtual void Dispose(bool disposing)
202152
{}
203153

src/GitHub.App/Resources.Designer.cs

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@
159159
<data name="LoginTitle" xml:space="preserve">
160160
<value>Connect To GitHub</value>
161161
</data>
162-
<data name="LogoutRequiredFeatureGist" xml:space="preserve">
163-
<value>create a Gist</value>
164-
</data>
165-
<data name="LogoutRequiredMessage" xml:space="preserve">
166-
<value>To {0} you need to sign out and back in.</value>
167-
</data>
168-
<data name="LogoutRequiredTitle" xml:space="preserve">
169-
<value>Sign Out Required</value>
170-
</data>
171162
<data name="PasswordValidatorEmpty" xml:space="preserve">
172163
<value>Please enter your password</value>
173164
</data>

0 commit comments

Comments
 (0)