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

Conversation

jcansdale
Copy link
Collaborator

@jcansdale jcansdale commented Nov 2, 2018

Depends on #2008
Depends on #2025

The focus of this PR has been removing the model interfaces, Octokit dependencies in model constructors and fixing NSubstitute tests that were broken when an interface changed to a class. I've tried to avoid any functional changes.

What this PR does

  • Remove the IGitService dependency from BranchModel
  • Remove Octokit.Branch dependency from BranchModel
  • Remove Octokit.Repository dependency from RemoteRepositoryModel
  • Remove IBranch interface from BranchModel
  • Remove the IRepositoryModel interface from RepositoryModel
  • Remove IRemoteRepositoryModel interface from RemoteRepositoryModel
  • Remove ILocalRepositoryModel interface from LocalRepositoryModel
  • Moved RemoteRepositoryModel from GitHub.App to GitHub.Exports.Reactive
  • Moved Account from GitHub.App to GitHub.Exports.Reactive
  • Rename IGitService.CreateCurrentBranchModel to GetBranch
  • Remove unused/buggy code for creating a BranchModel when LibGit2Sharp.Branch.IsRemote=true

Still to do

Refactor the constructor that took IGitService into
LocalRepositoryModel where it was used.
Move GenerateUrl from LocalRepositoryModel to LinkCommandBase.
Move LocalRepositoryModel construction tests to new home.
This property wasn't being used.
We Now only need the CreateLocalRepositoryModel(localPath) overload.
Previously the current branch was being read when CurrentBranch was
fetched. This changes it to be read when the LocalRepositoryModel is
created.
Remove redundant code and usings.
Previously CurrentBranch was created as the property was read. We now
need a way to refresh it.
It appears VSGitExt.ActiveRepositoriesChanged is fired before the local
repository has actually changed its branch. This means we can't read
the branch information immediately!
Remove the ILocalRepositoryModel.CurrentBranch property and explicitly
call IGitService.CreateCurrentBranchModel instead.
Fix all the broken tests.
Convert GetPullRequestForCurrentBranch to return (string owner, int
number). This allows the tuple to be compared directly.
We can now use GitService as a LocalRepositoryMode factory.
Be explicit about what it does.
Make ITeamExplorerServiceHolder responsible for holding references to
services, but not watching for and marshaling repository change events.
Delegate to ITeamExplorerContext for this.
This is no longer called by TeamExplorerServiceHolder.
Contains a call chain that results in a call to a virtual method
defined by the class.
Make log message a bit less bit yoda-y.
Tests started throwing null reference exceptions when we stopped using
an interface for BranchModel. This makes PrepareTestData default to
return no branches.
Remove Octokit.Repository dependency from RemoteRepositoryModel.
Fix warnings in LocalRepositoryModelDesigner and
RemoteRepositoryModelDesigner.
@jcansdale jcansdale changed the title [wip] Repository model refactoring (part 3) Repository model refactoring (part 3) Nov 6, 2018
@jcansdale jcansdale requested a review from grokys November 6, 2018 11:42
Copy link
Contributor

@grokys grokys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good in general, and pretty straightfoward. However I have one question (and couldn't leave it inline as the file was moved without changes):

Why was Account moved into GitHub.Exports.Reactive? It's a class with logic so should really stay in GitHub.App I think.

@@ -82,8 +82,12 @@ public class PullRequestCreationViewModel : PanePageViewModelBase, IPullRequestC
.Where(_ => TargetBranch != null)
.Subscribe(x =>
{
//// HACK: Why is `t` null?
//if (!x.Any(t => t != null && t.Equals(TargetBranch)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment mean "Why was there a check for t being null here?"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I temporarily added the t != null to allow the tests to pass. For some reason changing from using an interface to a class meant this come up null when testing.

I believe it was because NSubstitute automatically generates substitutes rather than returning null by default. I've since fixed this in the tests and removed the null check/comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove the commented-out code here then, or is that fix in a separate PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, in my mind I'd removed the comments! ;-)

@jcansdale jcansdale changed the base branch from refactor/ITeamExplorerServiceHolder to master November 7, 2018 11:19
grokys and others added 2 commits November 7, 2018 12:23
@jcansdale
Copy link
Collaborator Author

@grokys,

Why was Account moved into GitHub.Exports.Reactive? It's a class with logic so should really stay in GitHub.App I think.

After some later cleanup, the constructor of RemoteRepositoryModel no longer depends on Account. I think that was the original problem. I've moved Account back to GitHub.App.

Team Explorer was being flooded with repository StatusChanged events
which were being processes asynchronously.
This appears to be redundant and not used.
Copy link
Contributor

@grokys grokys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there! One more thing I just noticed.

Also, with this PR after cloning a new repository, the Pull Requests button appears for a moment on the TE home page and then disappears, we need to fix that.

@@ -82,8 +82,12 @@ public class PullRequestCreationViewModel : PanePageViewModelBase, IPullRequestC
.Where(_ => TargetBranch != null)
.Subscribe(x =>
{
//// HACK: Why is `t` null?
//if (!x.Any(t => t != null && t.Equals(TargetBranch)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove the commented-out code here then, or is that fix in a separate PR?

Previously visibility was only being refreshed when a new repository
change event arrived.
@jcansdale
Copy link
Collaborator Author

Also, with this PR after cloning a new repository, the Pull Requests button appears for a moment on the TE home page and then disappears, we need to fix that.

Good catch! This has been fixed in 17716ef.

Previously both TeamExplorerNavigationItemBase and TeamExplorerItemBase
were listring for repository change events. This changes it so that
only TeamExplorerItemBase needs to listen for change events.
TeamExplorerNavigationItemBase needs to subscribe before the item is
visible (the event is required to make it visible).
Copy link
Contributor

@grokys grokys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Remove redundant Guard statements.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants