This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refresh PullRequestSessionManager.CurrentSession when PR branch changes #1422
Merged
Merged
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
b834336
Add TeamExplorerContext MEF service
jcansdale 4e9d1ec
Harden reflection code and add logging
jcansdale e374c36
Only fire StatusChanged on BranchName/HeadSha change
jcansdale 416ec35
Ignore when ActiveRepositories is empty
jcansdale 768eca1
Don't throw if CloneUrl is null
jcansdale 00051bb
Change PullRequestSessionManager to use ITeamExplorerContext
jcansdale f06ff66
Change PR session if Number or Owner changes
jcansdale 8079f17
GetSession doesn't accept a null pullRequest
jcansdale d31d9a4
Set ActiveRepository to null when solution isn't in Git
jcansdale 6fbfb0a
Remove IVSGitExt hack from PullRequestDetailViewModel
jcansdale 7c43171
Add tests for TeamExplorerContext
jcansdale 4b67153
Add tests for TeamExplorerContext.PropertyChanged event
jcansdale cb8c1b6
Add tests for TeamExplorerContext.StatusChanged event
jcansdale 034d09b
Change GitHubPaneViewModel to use ITeamExplorerContext
jcansdale 03a41e7
Remove PullRequestDetailViewModel's dependency on IVSGitExt
jcansdale 360ba9a
Fix CA error
jcansdale c8dd2f6
Add some docs for ITeamExplorerContext
jcansdale b119585
Don't log when unit testing
jcansdale 834f39d
Log exceptions in Refresh event
jcansdale 18eba88
Use IGitHubServiceProvider instead of IServiceProvider
jcansdale be1b5b4
Use Splat.ModeDetector.InUnitTestRunner to detect runner
jcansdale 65d0be6
Use Rx for property change subscriptions
jcansdale 04452ef
Format xmldoc comments
jcansdale a35dca7
Use Rx to marshal onto main thread
jcansdale c809b66
Add remarks about non-UI thread
jcansdale fd5b45f
Merge branch 'master' into fixes/1408-change-branch-event-squashed
jcansdale 05a6e5b
Change xUnit test to NUnit test
jcansdale d8328e0
Merge branch 'master' into fixes/1408-change-branch-event-squashed
jcansdale 06daff1
Move TeamExplorerContext tests into UnitTests project
jcansdale 9706afd
Fire StatusChanged even when BranchName/HeadSha hasn't changed
jcansdale 384519a
Use TeamExplorerContext.StatusChanged to refresh PR detail view
jcansdale 23af5ec
Fire StatusChanged when tracked branch changes
jcansdale ed4bf01
Code cleanup and comments
jcansdale a2c3fe1
Simplify testing by using a nested interface
jcansdale 850f089
Add test for when only TrackedSha changes
jcansdale bfba186
Use class instead of out params
jcansdale 067e320
Add xmldoc comments for TeamExplorerContext
jcansdale 218ba5a
Rename RefreshLater to RefreshIfActive
jcansdale fd3077e
Consistently use CreateTeamExplorerContext
jcansdale 67a7c16
Fire property changed event from ActiveRepository setter
jcansdale 687db88
Encapsulate reflection code in GitExt and RepositoryInfo
jcansdale f2678a1
Make teamExplorerContext default to ValidGitHubRepo
jcansdale 5499f25
Use IVSGitExt rather than access IGitExt directly
jcansdale 1bb4be9
Don't manually disable logging when unit testing
jcansdale 3f53469
Clean up and comment
jcansdale 375bdd6
Change VSGitExt to lazy-initialize using UIContextChanged
jcansdale 572760b
Remove unused logger
jcansdale 24d45b7
Add unit tests for VSGitExt
jcansdale 34109f2
Remove UIContext watching responsibilities from TeamExplorerServiceHo…
jcansdale d69d358
Export single IVSUIContextFactory implementation in GH.TF.14
jcansdale 470991d
Keep CA happy
jcansdale a801953
Remove IVSUIContextChangedEventArgs interface
jcansdale 79ea850
Make IVSUIContextFactory filename consistent with service
jcansdale 2ccabb1
Add logging for VSGitExt
jcansdale 7e9405a
Update and add xmldoc comments
jcansdale 77bd3b2
Ensure ActiveRepositories is read using ThreadPoolThread
jcansdale dd39202
Update comments on how we're using UIContext
jcansdale e2c51e8
Cleanup usings
jcansdale edf9ff8
Don't read ActiveRepositories on UIContext thread
jcansdale a65027c
Add repo model factory and tests for repository creation
jcansdale 7ea9d81
Ensure repo changed event fires even when exception
jcansdale a41dbc1
Use IReadOnlyList and keep IVSGitExt consistent with IGitExt
jcansdale b420d4b
Merge branch 'master' into fixes/1408-change-branch-event-squashed
jcansdale 6a494e3
Fix merge error
jcansdale a466295
Only fire property change event if property has changed
jcansdale 01c81b2
Clean up redundant usings
jcansdale 7f8011e
Update test to reflect no duplicate change events
jcansdale 4995603
Merge branch 'master' into fixes/1408-change-branch-event-squashed
grokys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.ComponentModel; | ||
| using System.ComponentModel.Composition; | ||
| using GitHub.Models; | ||
| using GitHub.Logging; | ||
| using Serilog; | ||
| using EnvDTE; | ||
|
|
||
| namespace GitHub.Services | ||
| { | ||
| /// <summary> | ||
| /// This implementation listenes to IGitExt for ActiveRepositories property change events and fires | ||
| /// <see cref="PropertyChanged"/> and <see cref="StatusChanged"/> events when appropriate. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// A <see cref="PropertyChanged"/> is fired when a solution is opened in a new repository (or not in a repository). | ||
| /// A <see cref="StatusChanged"/> event is only fired when the current branch, head SHA or tracked SHA changes (not | ||
| /// on every IGitExt property change event). <see cref="ActiveRepository"/> contains the active repository or null | ||
| /// if a solution is opened that isn't in a repository. No events are fired when the same solution is unloaded then | ||
| /// reloaded (e.g. when a .sln file is touched). | ||
| /// </remarks> | ||
| [Export(typeof(ITeamExplorerContext))] | ||
| [PartCreationPolicy(CreationPolicy.Shared)] | ||
| public class TeamExplorerContext : ITeamExplorerContext | ||
| { | ||
| static ILogger log = LogManager.ForContext<TeamExplorerContext>(); | ||
|
|
||
| readonly DTE dte; | ||
| readonly IVSGitExt gitExt; | ||
|
|
||
| string solutionPath; | ||
| string repositoryPath; | ||
| string branchName; | ||
| string headSha; | ||
| string trackedSha; | ||
|
|
||
| ILocalRepositoryModel repositoryModel; | ||
|
|
||
| [ImportingConstructor] | ||
| public TeamExplorerContext(IGitHubServiceProvider serviceProvider, IVSGitExt gitExt) | ||
| : this(gitExt, serviceProvider) | ||
| { | ||
| } | ||
|
|
||
| public TeamExplorerContext(IVSGitExt gitExt, IGitHubServiceProvider serviceProvider) | ||
| { | ||
| this.gitExt = gitExt; | ||
|
|
||
| // This is a standard service which should always be available. | ||
| dte = serviceProvider.GetService<DTE>(); | ||
|
|
||
| Refresh(); | ||
| gitExt.ActiveRepositoriesChanged += Refresh; | ||
| } | ||
|
|
||
| void Refresh() | ||
| { | ||
| try | ||
| { | ||
| var repo = gitExt.ActiveRepositories?.FirstOrDefault(); | ||
| var newSolutionPath = dte.Solution?.FullName; | ||
|
|
||
| if (repo == null && newSolutionPath == solutionPath) | ||
| { | ||
| // Ignore when ActiveRepositories is empty and solution hasn't changed. | ||
| // https://github.com/github/VisualStudio/issues/1421 | ||
| log.Information("Ignoring no ActiveRepository when solution hasn't changed"); | ||
| } | ||
| else | ||
| { | ||
| var newRepositoryPath = repo?.LocalPath; | ||
| var newBranchName = repo?.CurrentBranch?.Name; | ||
| var newHeadSha = repo?.CurrentBranch?.Sha; | ||
| var newTrackedSha = repo?.CurrentBranch?.TrackedSha; | ||
|
|
||
| if (newRepositoryPath != repositoryPath) | ||
| { | ||
| log.Information("Fire PropertyChanged event for ActiveRepository"); | ||
| ActiveRepository = repo; | ||
| } | ||
| else if (newBranchName != branchName) | ||
| { | ||
| log.Information("Fire StatusChanged event when BranchName changes for ActiveRepository"); | ||
| StatusChanged?.Invoke(this, EventArgs.Empty); | ||
| } | ||
| else if (newHeadSha != headSha) | ||
| { | ||
| log.Information("Fire StatusChanged event when HeadSha changes for ActiveRepository"); | ||
| StatusChanged?.Invoke(this, EventArgs.Empty); | ||
| } | ||
| else if (newTrackedSha != trackedSha) | ||
| { | ||
| log.Information("Fire StatusChanged event when TrackedSha changes for ActiveRepository"); | ||
| StatusChanged?.Invoke(this, EventArgs.Empty); | ||
| } | ||
|
|
||
| repositoryPath = newRepositoryPath; | ||
| branchName = newBranchName; | ||
| headSha = newHeadSha; | ||
| solutionPath = newSolutionPath; | ||
| trackedSha = newTrackedSha; | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| log.Error(e, "Refreshing active repository"); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The active repository or null if not in a repository. | ||
| /// </summary> | ||
| public ILocalRepositoryModel ActiveRepository | ||
| { | ||
| get | ||
| { | ||
| return repositoryModel; | ||
| } | ||
|
|
||
| private set | ||
| { | ||
| if (value != repositoryModel) | ||
| { | ||
| repositoryModel = value; | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ActiveRepository))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Fired when a solution is opened in a new repository (or that isn't in a repository). | ||
| /// </summary> | ||
| public event PropertyChangedEventHandler PropertyChanged; | ||
|
|
||
| /// <summary> | ||
| /// Fired when the current branch, head SHA or tracked SHA changes. | ||
| /// </summary> | ||
| public event EventHandler StatusChanged; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be done on a background thread, see
TeamExplorerServiceHolderfor how it does this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it so that
ActiveRepositoriesis initialized byVSGitExton a thread pool thread.