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

Commit 85bee19

Browse files
authored
Merge branch 'master' into bump-libgit2sharp-octokit
2 parents bdda514 + 98ff88f commit 85bee19

File tree

173 files changed

+7728
-1320
lines changed

Some content is hidden

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

173 files changed

+7728
-1320
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,4 @@ WiX.Toolset.DummyFile.txt
238238
nunit-UnitTests.xml
239239
nunit-TrackingCollectionTests.xml
240240
GitHubVS.sln.DotSettings
241-
**/generated/*.cs
241+
**/generated/*.cs

CONTRIBUTING.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,33 @@ There are certain areas of the extension that are restricted in what they can do
3131
- Team Explorer content outside the Home page is slightly less restricted, but not by much
3232
- Dialogs and views that don't inherit from TeamExplorer classes are free to use what they need.
3333

34+
## Submitting an Issue
35+
36+
### Bug Reporting
37+
38+
Here are a few helpful tips when reporting a bug:
39+
- Verify the bug resides in the GitHub for Visual Studio extension
40+
- A lot of functionality provided by this extension resides in the Team Explorer pane, alongside other non-GitHub tools to manage and collaborate on source code, including Visual Studio's Git support, which is owned by Microsoft.
41+
- If this bug not is related to the GitHub extension, visit the [Visual Studio support page](https://www.visualstudio.com/support/support-overview-vs) for help
42+
- Screenshots are very helpful in diagnosing bugs and understanding the state of the extension when it's experiencing problems. Please include them whenever possible.
43+
- A log file is helpful in diagnosing bug issues. To include log files in your issue:
44+
45+
1. Close Visual Studio if it's open
46+
2. Open a Developer Command Prompt for VS2015
47+
3. Run devenv /log
48+
4. Reproduce your issue
49+
5. Close VS
50+
6. Locate the following files on your system and email them to [email protected] or create a gist and link it in the issue report:
51+
- `%appdata%\Microsoft\VisualStudio\14.0\ActivityLog.xml`
52+
- `%localappdata%\temp\extension.log`
53+
- `%localappdata%\GitHubVisualStudio\extension.log`
54+
55+
### Feature Requests
56+
If you have a feature that you think would be a great addition to the extension, we might already have thought about it too, so be sure to check if your suggestion matches our [roadmap](#roadmap-and-future-feature-ideas) before making a request. Also take a peek at our [pull requests](https://github.com/github/VisualStudio/pulls) to see what we're currently working on. Additionally, someone might have already thought of your idea, so check out Issues labeled as [features](https://github.com/github/VisualStudio/issues?q=is%3Aopen+is%3Aissue+label%3Afeature) to see if it already exists.
57+
3458
## Things to improve in the current version
3559

36-
- Localization
60+
- [Localization](https://github.com/github/VisualStudio/issues/18)
3761

3862
## Roadmap and future feature ideas
3963

GitHubVS.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ Global
524524
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.Release|Any CPU.Build.0 = Release|Any CPU
525525
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.Release|x86.ActiveCfg = Release|Any CPU
526526
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.Release|x86.Build.0 = Release|Any CPU
527-
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|Any CPU.ActiveCfg = Release|Any CPU
528-
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
527+
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|Any CPU.ActiveCfg = Debug|Any CPU
528+
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|Any CPU.Build.0 = Debug|Any CPU
529529
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|x86.ActiveCfg = Release|Any CPU
530530
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.XamlDesign|x86.Build.0 = Release|Any CPU
531531
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -540,8 +540,8 @@ Global
540540
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.Release|Any CPU.Build.0 = Release|Any CPU
541541
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.Release|x86.ActiveCfg = Release|Any CPU
542542
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.Release|x86.Build.0 = Release|Any CPU
543-
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|Any CPU.ActiveCfg = Release|Any CPU
544-
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
543+
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|Any CPU.ActiveCfg = Debug|Any CPU
544+
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|Any CPU.Build.0 = Debug|Any CPU
545545
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|x86.ActiveCfg = Release|Any CPU
546546
{161DBF01-1DBF-4B00-8551-C5C00F26720E}.XamlDesign|x86.Build.0 = Release|Any CPU
547547
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -556,8 +556,8 @@ Global
556556
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.Release|Any CPU.Build.0 = Release|Any CPU
557557
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.Release|x86.ActiveCfg = Release|Any CPU
558558
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.Release|x86.Build.0 = Release|Any CPU
559-
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|Any CPU.ActiveCfg = Release|Any CPU
560-
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
559+
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|Any CPU.ActiveCfg = Debug|Any CPU
560+
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|Any CPU.Build.0 = Debug|Any CPU
561561
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|x86.ActiveCfg = Release|Any CPU
562562
{D1DFBB0C-B570-4302-8F1E-2E3A19C41961}.XamlDesign|x86.Build.0 = Release|Any CPU
563563
EndGlobalSection

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ Visit the [Contributor Guidelines](CONTRIBUTING.md) for details on how to contri
4444

4545
## Copyright
4646

47-
Copyright 2015 GitHub, Inc.
47+
Copyright 2015 - 2016 GitHub, Inc.
4848

4949
Licensed under the [MIT License](LICENSE.md)

documentation/UIController.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
The `UIController` class creates views and associated viewmodels for each UI we have,
2+
and controls the UI logic graph. It uses various state machines to define
3+
the UI logic graph.
4+
5+
**State machines**
6+
7+
The UI logic graph is controlled by various state machines defined in
8+
`ConfigureLogicStates` and `ConfigureUIHandlingStates`
9+
10+
**ConfigureLogicStates**
11+
12+
`ConfigureLogicStates` defines the one state machine per UI group:
13+
- Authentication
14+
- Repository Clone
15+
- Repository Creation
16+
- Repository Publish,
17+
- Pull Requests (List, Detail, Creation)
18+
19+
All state machines have a common state of `None` (nothing happened yet),
20+
`End` (we're done, cleanup) and `Finish` (final state once cleanup is done), and
21+
UI-specific states that relate to what views the UI needs to show (Login, TwoFactor,
22+
PullRequestList, etc). States are defined in the enum `UIViewType`
23+
24+
All state machines support a variety of triggers for going from one state to another.
25+
These triggers are defined in the enum `Trigger`. `Cancel` and `Finish` are
26+
supported by all states (any state machine regardless of its current state supports
27+
exiting via `Cancel` (ends with success flag set to false) and `Finish` (ends with success flag set to true).
28+
Since most UI flows we support are linear (login followed by 2fa followed by clone
29+
followed by ending the flow), most states support the `Next` trigger to continue,
30+
and when at the end of a ui flow, `Next` ends it with success.
31+
32+
The Pull Requests UI flow is non-linear (there are more than one transition from the
33+
list view - it can go to the detail view, or the pr creation view, or other views),
34+
it does not support the `Next` trigger and instead has its own triggers.
35+
36+
**ConfigureUIHandlingStates**
37+
38+
`ConfigureUIHandlingStates` defines a state machine `uiStateMachine` connected
39+
to the `transition` observable, and executes whatever logic is needed to load the
40+
requested state, usually by creating the view and viewmodel that the UI state requires.
41+
Whenever a state transition happens in `uiStateMachine`, if the state requires
42+
loading a view, this view is sent back to the rendering code via the `transition`
43+
observable. When the state machine reaches the `End` state, the `completion` observable
44+
is completed with a flag indicating whether the ui flow ended successfully or was
45+
cancelled (via the `Next`/`Finish` triggers or the `Cancel` trigger) .
46+
47+
The transitions between states are dynamically evaluated at runtime based on the logic
48+
defined in `ConfigureLogicStates`. When `uiStateMachine` receives a trigger request,
49+
it passes that trigger to the state machine corresponding to the ui flow that's currently
50+
running (Authentication, Clone, etc), and that state machine determines which state
51+
to go to next.
52+
53+
In theory, `uiStateMachine` has no knowledge of the logic graph, and
54+
the only thing it's responsible for is loading UI whenever a state is entered, and cleaning
55+
up objects when things are done - making it essentially a big switch with nice entry and exit
56+
conditions. In practice, we need to configure the valid triggers from one state to the other
57+
just so we can call the corresponding state machine that handles the logic (defined in `ConfigureLogicStates`).
58+
There is a bit of code duplication because of this, and there's some room for improvement
59+
here, but because we have a small number of triggers, it's not a huge deal.

script

src/DesignTimeStyleHelper/WindowController.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using GitHub.UI;
2+
using System;
23
using System.Windows;
34
using System.Windows.Controls;
45

@@ -11,11 +12,11 @@ public partial class WindowController : Window
1112
{
1213
IDisposable disposable;
1314

14-
public WindowController(IObservable<UserControl> controls)
15+
public WindowController(IObservable<LoadData> controls)
1516
{
1617
InitializeComponent();
1718

18-
disposable = controls.Subscribe(c => Load(c),
19+
disposable = controls.Subscribe(c => Load(c.View),
1920
Close
2021
);
2122
}
@@ -26,8 +27,9 @@ protected override void OnClosed(EventArgs e)
2627
base.OnClosed(e);
2728
}
2829

29-
public void Load(UserControl control)
30+
public void Load(IView view)
3031
{
32+
var control = view as UserControl;
3133
Container.Children.Clear();
3234
Container.Children.Add(control);
3335
}

src/GitHub.App/Api/ApiClient.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@
1313
using Octokit;
1414
using Octokit.Reactive;
1515
using ReactiveUI;
16+
using System.Threading.Tasks;
17+
using System.Reactive.Threading.Tasks;
18+
using Octokit.Internal;
19+
using System.Collections.Generic;
20+
using GitHub.Models;
1621

1722
namespace GitHub.Api
1823
{
1924
public partial class ApiClient : IApiClient
2025
{
21-
static readonly Logger log = LogManager.GetCurrentClassLogger();
22-
26+
const string ScopesHeader = "X-OAuth-Scopes";
2327
const string ProductName = Info.ApplicationInfo.ApplicationDescription;
28+
static readonly Logger log = LogManager.GetCurrentClassLogger();
29+
static readonly Uri userEndpoint = new Uri("user", UriKind.Relative);
2430

2531
readonly IObservableGitHubClient gitHubClient;
2632
// There are two sets of authorization scopes, old and new:
2733
// The old scopes must be used by older versions of Enterprise that don't support the new scopes:
28-
readonly string[] oldAuthorizationScopes = { "user", "repo" };
34+
readonly string[] oldAuthorizationScopes = { "user", "repo", "gist" };
2935
// These new scopes include write:public_key, which allows us to add public SSH keys to an account:
30-
readonly string[] newAuthorizationScopes = { "user", "repo", "write:public_key" };
36+
readonly string[] newAuthorizationScopes = { "user", "repo", "gist", "write:public_key" };
3137
readonly static Lazy<string> lazyNote = new Lazy<string>(() => ProductName + " on " + GetMachineNameSafe());
3238
readonly static Lazy<string> lazyFingerprint = new Lazy<string>(GetFingerprint);
3339

@@ -52,9 +58,35 @@ public IObservable<Repository> CreateRepository(NewRepository repository, string
5258
return (isUser ? client.Create(repository) : client.Create(login, repository));
5359
}
5460

55-
public IObservable<User> GetUser()
61+
public IObservable<Gist> CreateGist(NewGist newGist)
62+
{
63+
return gitHubClient.Gist.Create(newGist);
64+
}
65+
66+
public IObservable<UserAndScopes> GetUser()
5667
{
57-
return gitHubClient.User.Current();
68+
return GetUserInternal().ToObservable();
69+
}
70+
71+
async Task<UserAndScopes> GetUserInternal()
72+
{
73+
var response = await gitHubClient.Connection.Get<User>(
74+
userEndpoint, null, null).ConfigureAwait(false);
75+
var scopes = default(string[]);
76+
77+
if (response.HttpResponse.Headers.ContainsKey(ScopesHeader))
78+
{
79+
scopes = response.HttpResponse.Headers[ScopesHeader]
80+
.Split(',')
81+
.Select(x => x.Trim())
82+
.ToArray();
83+
}
84+
else
85+
{
86+
log.Error($"Error reading scopes: /user succeeded but {ScopesHeader} was not present.");
87+
}
88+
89+
return new UserAndScopes(response.Body, scopes);
5890
}
5991

6092
public IObservable<ApplicationAuthorization> GetOrCreateApplicationAuthenticationCode(

0 commit comments

Comments
 (0)