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

Commit 258decf

Browse files
First attempt at removing locations where a repo already exists
1 parent 8881c18 commit 258decf

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/GitHub.App/ViewModels/Dialog/ForkRepositorySelectViewModel.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,22 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
6969
Observable.CombineLatest(
7070
modelService.GetAccounts(),
7171
modelService.GetRepository(repository.Owner, repository.Name),
72-
(a, r) => new { Accounts = a, Respoitory = r})
72+
modelService.GetForks(repository).ToList(),
73+
(a, r, f) => new { Accounts = a, Respoitory = r, Forks = f })
7374
.Finally(() => IsLoading = false)
7475
.Subscribe(x =>
7576
{
76-
Accounts = BuildAccounts(x.Accounts, repository.Owner);
77+
var forks = x.Forks;
78+
79+
var parents = new List<IRemoteRepositoryModel>();
80+
var current = x.Respoitory;
81+
while (current.Parent != null)
82+
{
83+
parents.Add(current.Parent);
84+
current = current.Parent;
85+
}
86+
87+
Accounts = BuildAccounts(x.Accounts, repository, forks, parents);
7788
});
7889

7990
}
@@ -84,10 +95,16 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
8495
}
8596
}
8697

87-
IReadOnlyList<IAccount> BuildAccounts(IEnumerable<IAccount> accessibleAccounts, string currentRepositoryOwner)
98+
IReadOnlyList<IAccount> BuildAccounts(IReadOnlyList<IAccount> accessibleAccounts, ILocalRepositoryModel currentRepository, IList<IRemoteRepositoryModel> forks, List<IRemoteRepositoryModel> parents)
8899
{
100+
log.Verbose("BuildAccounts: {AccessibleAccounts} accessibleAccounts, {Forks} forks, {Parents} parents", accessibleAccounts.Count, forks.Count, parents.Count);
101+
102+
var existingForksAndParents = forks.Union(parents).ToDictionary(model => model.Owner);
103+
89104
return accessibleAccounts
90-
.Where(x => x.Login != currentRepositoryOwner).ToList();
105+
.Where(x => x.Login != currentRepository.Owner)
106+
.Where(x => !existingForksAndParents.ContainsKey(x.Login))
107+
.ToList();
91108
}
92109
}
93110
}

0 commit comments

Comments
 (0)