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

Commit 79af9ae

Browse files
committed
Remove Octokit.Repository dependency
Remove Octokit.Repository dependency from RemoteRepositoryModel.
1 parent c360269 commit 79af9ae

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

src/GitHub.App/Services/ModelService.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,22 @@ public IObservable<IReadOnlyList<IAccount>> GetAccounts()
107107
public IObservable<RemoteRepositoryModel> GetForks(RepositoryModel repository)
108108
{
109109
return ApiClient.GetForks(repository.Owner, repository.Name)
110-
.Select(x => new RemoteRepositoryModel(x));
110+
.Select(x => CreateRemoteRepositoryModel(x));
111+
}
112+
113+
static RemoteRepositoryModel CreateRemoteRepositoryModel(Repository repository)
114+
{
115+
var ownerAccount = new Models.Account(repository.Owner);
116+
var parent = repository.Parent != null ? CreateRemoteRepositoryModel(repository.Parent) : null;
117+
var model = new RemoteRepositoryModel(repository.Id, repository.Name, repository.CloneUrl,
118+
repository.Private, repository.Fork, ownerAccount, parent, repository.DefaultBranch);
119+
120+
if (parent != null)
121+
{
122+
parent.DefaultBranch.DisplayName = parent.DefaultBranch.Id;
123+
}
124+
125+
return model;
111126
}
112127

113128
IObservable<LicenseCacheItem> GetLicensesFromApi()

src/GitHub.App/ViewModels/GitHubPane/PullRequestCreationViewModel.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public async Task InitializeAsync(LocalRepositoryModel repository, IConnection c
149149
SourceBranch = gitService.GetBranch(repository);
150150

151151
var obs = modelService.ApiClient.GetRepository(repository.Owner, repository.Name)
152-
.Select(r => new RemoteRepositoryModel(r))
152+
.Select(r => CreateRemoteRepositoryModel(r))
153153
.PublishLast();
154154
disposables.Add(obs.Connect());
155155
var githubObs = obs;
@@ -196,6 +196,21 @@ public async Task InitializeAsync(LocalRepositoryModel repository, IConnection c
196196
Initialized = true;
197197
}
198198

199+
static RemoteRepositoryModel CreateRemoteRepositoryModel(Repository repository)
200+
{
201+
var ownerAccount = new Models.Account(repository.Owner);
202+
var parent = repository.Parent != null ? CreateRemoteRepositoryModel(repository.Parent) : null;
203+
var model = new RemoteRepositoryModel(repository.Id, repository.Name, repository.CloneUrl,
204+
repository.Private, repository.Fork, ownerAccount, parent, repository.DefaultBranch);
205+
206+
if (parent != null)
207+
{
208+
parent.DefaultBranch.DisplayName = parent.DefaultBranch.Id;
209+
}
210+
211+
return model;
212+
}
213+
199214
async Task LoadInitialState(string draftKey)
200215
{
201216
if (activeLocalRepo.CloneUrl == null)

src/GitHub.Exports.Reactive/Models/RemoteRepositoryModel.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GitHub.Primitives;
2-
using System;
1+
using System;
32
using System.Globalization;
3+
using GitHub.Primitives;
44
using GitHub.Extensions;
55
using GitHub.Collections;
66

@@ -27,7 +27,9 @@ protected RemoteRepositoryModel()
2727
/// <param name="isFork">Whether the repository is a fork.</param>
2828
/// <param name="ownerAccount">The repository owner account.</param>
2929
/// <param name="parent">The parent repository if this repository is a fork.</param>
30-
public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount, RemoteRepositoryModel parent)
30+
/// <param name="defaultBranchName">The default branch name (or "master" if undefined).</param>
31+
public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount,
32+
RemoteRepositoryModel parent, string defaultBranchName = "master")
3133
: base(name, cloneUrl)
3234
{
3335
Guard.ArgumentNotEmptyString(name, nameof(name));
@@ -37,31 +39,10 @@ public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPr
3739
OwnerAccount = ownerAccount;
3840
IsFork = isFork;
3941
SetIcon(isPrivate, isFork);
40-
// this is an assumption, we'd have to load the repo information from octokit to know for sure
41-
// probably not worth it for this ctor
42-
DefaultBranch = new BranchModel("master", this);
42+
DefaultBranch = new BranchModel(defaultBranchName, this);
4343
Parent = parent;
4444
}
4545

46-
/// <summary>
47-
/// Initializes a new instance of the <see cref="RemoteRepositoryModel"/> class.
48-
/// </summary>
49-
/// <param name="repository">The source octokit repository.</param>
50-
public RemoteRepositoryModel(Octokit.Repository repository)
51-
: base(repository.Name, repository.CloneUrl)
52-
{
53-
Guard.ArgumentNotNull(repository, nameof(repository));
54-
55-
Id = repository.Id;
56-
IsFork = repository.Fork;
57-
SetIcon(repository.Private, IsFork);
58-
OwnerAccount = new Account(repository.Owner);
59-
DefaultBranch = new BranchModel(repository.DefaultBranch, this);
60-
Parent = repository.Parent != null ? new RemoteRepositoryModel(repository.Parent) : null;
61-
if (Parent != null)
62-
Parent.DefaultBranch.DisplayName = Parent.DefaultBranch.Id;
63-
}
64-
6546
#region Equality Things
6647
public void CopyFrom(RemoteRepositoryModel other)
6748
{

test/GitHub.App.UnitTests/ViewModels/GitHubPane/PullRequestCreationViewModelTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static TestData PrepareTestData(
9393
githubRepoParent = CreateRepository(targetRepoOwner, repoName, id: 1);
9494
var githubRepo = CreateRepository(sourceRepoOwner, repoName, id: 2, parent: githubRepoParent);
9595
var sourceBranch = new BranchModel(sourceBranchName, activeRepo);
96-
var sourceRepo = new RemoteRepositoryModel(githubRepo);
96+
var sourceRepo = CreateRemoteRepositoryModel(githubRepo);
9797
var targetRepo = targetRepoOwner == sourceRepoOwner ? sourceRepo : sourceRepo.Parent;
9898
var targetBranch = targetBranchName != targetRepo.DefaultBranch.Name ? new BranchModel(targetBranchName, targetRepo) : targetRepo.DefaultBranch;
9999

@@ -125,6 +125,21 @@ static TestData PrepareTestData(
125125
};
126126
}
127127

128+
static RemoteRepositoryModel CreateRemoteRepositoryModel(Repository repository)
129+
{
130+
var ownerAccount = new GitHub.Models.Account(repository.Owner);
131+
var parent = repository.Parent != null ? CreateRemoteRepositoryModel(repository.Parent) : null;
132+
var model = new RemoteRepositoryModel(repository.Id, repository.Name, repository.CloneUrl,
133+
repository.Private, repository.Fork, ownerAccount, parent, repository.DefaultBranch);
134+
135+
if (parent != null)
136+
{
137+
parent.DefaultBranch.DisplayName = parent.DefaultBranch.Id;
138+
}
139+
140+
return model;
141+
}
142+
128143
[Test]
129144
public async Task TargetBranchDisplayNameIncludesRepoOwnerWhenForkAsync()
130145
{

0 commit comments

Comments
 (0)