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

Commit d52302a

Browse files
committed
ReadParentOwnerLogin -> FindParent.
Make the method to find the parent repository return the repository name and owner. We don't actually use the `name` yet, and assume that forks have the same name as the parent repository. This is usually the case but not always. `UriString` doesn't support getting a new URL with a different name as well as owner so want to do that in a separate PR.
1 parent db00183 commit d52302a

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

src/GitHub.App/GitHub.App.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<HintPath>..\..\packages\Rx-XAML.2.2.5-custom\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
195195
<Private>True</Private>
196196
</Reference>
197+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
198+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
199+
</Reference>
197200
<Reference Include="System.Web" />
198201
<Reference Include="System.Xaml" />
199202
<Reference Include="System.Xml.Linq" />

src/GitHub.App/Services/RepositoryService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace GitHub.Services
1414
[PartCreationPolicy(CreationPolicy.Shared)]
1515
public class RepositoryService : IRepositoryService
1616
{
17-
static ICompiledQuery<string> readParentOwnerLogin;
17+
static ICompiledQuery<Tuple<string, string>> readParentOwnerLogin;
1818
readonly IGraphQLClientFactory graphqlFactory;
1919

2020
[ImportingConstructor]
@@ -25,7 +25,7 @@ public RepositoryService(IGraphQLClientFactory graphqlFactory)
2525
this.graphqlFactory = graphqlFactory;
2626
}
2727

28-
public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner, string name)
28+
public async Task<(string owner, string name)?> FindParent(HostAddress address, string owner, string name)
2929
{
3030
Guard.ArgumentNotNull(address, nameof(address));
3131
Guard.ArgumentNotEmptyString(owner, nameof(owner));
@@ -35,7 +35,7 @@ public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner
3535
{
3636
readParentOwnerLogin = new Query()
3737
.Repository(Var(nameof(owner)), Var(nameof(name)))
38-
.Select(r => r.Parent != null ? r.Parent.Owner.Login : null)
38+
.Select(r => r.Parent != null ? Tuple.Create(r.Parent.Owner.Login, r.Parent.Name) : null)
3939
.Compile();
4040
}
4141

@@ -46,7 +46,8 @@ public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner
4646
};
4747

4848
var graphql = await graphqlFactory.CreateConnection(address);
49-
return await graphql.Run(readParentOwnerLogin, vars);
49+
var result = await graphql.Run(readParentOwnerLogin, vars);
50+
return result != null ? (result.Item1, result.Item2) : ((string, string)?)null;
5051
}
5152
}
5253
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,21 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
127127
SelectedState = States.FirstOrDefault();
128128
AuthorFilter = new UserFilterViewModel(LoadAuthors);
129129

130-
var parentOwner = await repositoryService.ReadParentOwnerLogin(
130+
var parent = await repositoryService.FindParent(
131131
HostAddress.Create(repository.CloneUrl),
132132
repository.Owner,
133133
repository.Name);
134134

135-
if (parentOwner == null)
135+
if (parent == null)
136136
{
137137
RemoteRepository = repository;
138138
}
139139
else
140140
{
141+
// TODO: Handle forks with different names.
141142
RemoteRepository = new RepositoryModel(
142143
repository.Name,
143-
UriString.ToUriString(repository.CloneUrl.ToRepositoryUrl(parentOwner)));
144+
UriString.ToUriString(repository.CloneUrl.ToRepositoryUrl(parent.Value.owner)));
144145

145146
Forks = new IRepositoryModel[]
146147
{

src/GitHub.App/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
<package id="SerilogAnalyzer" version="0.12.0.0" targetFramework="net461" />
3434
<package id="SQLitePCL.raw_basic" version="0.7.3.0-vs2012" targetFramework="net45" />
3535
<package id="Stateless" version="2.5.56.0" targetFramework="net45" />
36+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
3637
</packages>

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
<Reference Include="System.Management" />
136136
<Reference Include="System.Management.Instrumentation" />
137137
<Reference Include="System.Net.Http" />
138+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
139+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
140+
</Reference>
138141
<Reference Include="System.Xaml" />
139142
<Reference Include="System.Xml.Linq" />
140143
<Reference Include="System.Data.DataSetExtensions" />

src/GitHub.Exports/Services/IRepositoryService.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ namespace GitHub.Services
66
{
77
public interface IRepositoryService
88
{
9-
Task<string> ReadParentOwnerLogin(
10-
HostAddress address,
11-
string owner,
12-
string name);
9+
/// <summary>
10+
/// Finds the parent repository of a fork, if any.
11+
/// </summary>
12+
/// <param name="address">The host address.</param>
13+
/// <param name="owner">The repository owner.</param>
14+
/// <param name="name">The repository name.</param>
15+
/// <returns>
16+
/// A tuple of the parent repository's owner and name if the repository is a fork,
17+
/// otherwise null.
18+
/// </returns>
19+
Task<(string owner, string name)?> FindParent(HostAddress address, string owner, string name);
1320
}
1421
}

src/GitHub.Exports/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
<package id="Serilog" version="2.5.0" targetFramework="net461" />
2121
<package id="SerilogAnalyzer" version="0.12.0.0" targetFramework="net461" />
2222
<package id="SimpleJson" version="0.38.0" targetFramework="net461" />
23+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
2324
<package id="VSSDK.IDE.12" version="12.0.4" targetFramework="net461" />
2425
</packages>

0 commit comments

Comments
 (0)