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

Commit 6028eab

Browse files
committed
Merge branch 'master' into 480-fix-pr-refresh-showing-create-form
2 parents 919f571 + 38a687e commit 6028eab

File tree

68 files changed

+823
-486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+823
-486
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Octokit.Internal;
1919
using System.Collections.Generic;
2020
using GitHub.Models;
21+
using GitHub.Extensions;
2122

2223
namespace GitHub.Api
2324
{

src/GitHub.App/Caches/LoginCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reactive;
55
using System.Reactive.Linq;
66
using Akavache;
7+
using GitHub.Extensions;
78
using GitHub.Primitives;
89
using NLog;
910

src/GitHub.App/Factories/SqlitePersistentBlobCacheFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.ComponentModel.Composition;
77
using System.Reactive.Linq;
88
using System.Threading.Tasks;
9+
using GitHub.Extensions;
910

1011
namespace GitHub.Factories
1112
{

src/GitHub.App/GitHub.App.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
<Compile Include="Models\DisconnectedRepositoryHosts.cs" />
174174
<Compile Include="Models\RepositoryHost.cs" />
175175
<Compile Include="Models\RepositoryHosts.cs" />
176-
<Compile Include="Models\RepositoryModel.cs" />
176+
<Compile Include="Models\RemoteRepositoryModel.cs" />
177177
<Compile Include="SampleData\SampleViewModels.cs" />
178178
<Compile Include="Api\ApiClient.cs" />
179179
<Compile Include="Factories\ApiClientFactory.cs" />
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using GitHub.Primitives;
2+
using NullGuard;
3+
using System;
4+
using System.Globalization;
5+
6+
namespace GitHub.Models
7+
{
8+
/// <summary>
9+
/// A repository read from the GitHub API.
10+
/// </summary>
11+
public class RemoteRepositoryModel : RepositoryModelBase, IRemoteRepositoryModel,
12+
IEquatable<RemoteRepositoryModel>, IComparable<RemoteRepositoryModel>
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="RemoteRepositoryModel"/> class.
16+
/// </summary>
17+
/// <param name="id">The API ID of the repository.</param>
18+
/// <param name="name">The repository name.</param>
19+
/// <param name="cloneUrl">The repository's clone URL.</param>
20+
/// <param name="isPrivate">Whether the repository is private.</param>
21+
/// <param name="isFork">Whether the repository is a fork.</param>
22+
/// <param name="ownerAccount">The repository owner account.</param>
23+
public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount)
24+
: base(name, cloneUrl)
25+
{
26+
Id = id;
27+
OwnerAccount = ownerAccount;
28+
IsFork = isFork;
29+
SetIcon(isPrivate, isFork);
30+
// this is an assumption, we'd have to load the repo information from octokit to know for sure
31+
// probably not worth it for this ctor
32+
DefaultBranch = new BranchModel("master", this);
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="RemoteRepositoryModel"/> class.
37+
/// </summary>
38+
/// <param name="repository">The source octokit repository.</param>
39+
public RemoteRepositoryModel(Octokit.Repository repository)
40+
: base(repository.Name, repository.CloneUrl)
41+
{
42+
Id = repository.Id;
43+
IsFork = repository.Fork;
44+
SetIcon(repository.Private, IsFork);
45+
OwnerAccount = new Account(repository.Owner);
46+
DefaultBranch = new BranchModel(repository.DefaultBranch, this);
47+
Parent = repository.Parent != null ? new RemoteRepositoryModel(repository.Parent) : null;
48+
if (Parent != null)
49+
Parent.DefaultBranch.DisplayName = Parent.DefaultBranch.Id;
50+
}
51+
52+
#region Equality Things
53+
public void CopyFrom(IRemoteRepositoryModel other)
54+
{
55+
if (!Equals(other))
56+
throw new ArgumentException("Instance to copy from doesn't match this instance. this:(" + this + ") other:(" + other + ")", nameof(other));
57+
Icon = other.Icon;
58+
}
59+
60+
public override int GetHashCode()
61+
{
62+
return Id.GetHashCode();
63+
}
64+
65+
public override bool Equals([AllowNull]object obj)
66+
{
67+
if (ReferenceEquals(this, obj))
68+
return true;
69+
var other = obj as RemoteRepositoryModel;
70+
return Equals(other);
71+
}
72+
73+
public bool Equals([AllowNull]IRemoteRepositoryModel other)
74+
{
75+
if (ReferenceEquals(this, other))
76+
return true;
77+
return other != null && Id == other.Id;
78+
}
79+
80+
public bool Equals([AllowNull]RemoteRepositoryModel other)
81+
{
82+
if (ReferenceEquals(this, other))
83+
return true;
84+
return other != null && Id == other.Id;
85+
}
86+
87+
public int CompareTo([AllowNull]IRemoteRepositoryModel other)
88+
{
89+
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
90+
}
91+
92+
public int CompareTo([AllowNull]RemoteRepositoryModel other)
93+
{
94+
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
95+
}
96+
97+
public static bool operator >([AllowNull]RemoteRepositoryModel lhs, [AllowNull]RemoteRepositoryModel rhs)
98+
{
99+
if (ReferenceEquals(lhs, rhs))
100+
return false;
101+
return lhs?.CompareTo(rhs) > 0;
102+
}
103+
104+
public static bool operator <([AllowNull]RemoteRepositoryModel lhs, [AllowNull]RemoteRepositoryModel rhs)
105+
{
106+
if (ReferenceEquals(lhs, rhs))
107+
return false;
108+
return (object)lhs == null || lhs.CompareTo(rhs) < 0;
109+
}
110+
111+
public static bool operator ==([AllowNull]RemoteRepositoryModel lhs, [AllowNull]RemoteRepositoryModel rhs)
112+
{
113+
return ReferenceEquals(lhs, rhs);
114+
}
115+
116+
public static bool operator !=([AllowNull]RemoteRepositoryModel lhs, [AllowNull]RemoteRepositoryModel rhs)
117+
{
118+
return !(lhs == rhs);
119+
}
120+
#endregion
121+
122+
/// <summary>
123+
/// Gets the account that is the ower of the repository.
124+
/// </summary>
125+
public IAccount OwnerAccount { get; }
126+
127+
/// <summary>
128+
/// Gets the repository's API ID.
129+
/// </summary>
130+
public long Id { get; }
131+
132+
/// <summary>
133+
/// Gets the date and time at which the repository was created.
134+
/// </summary>
135+
public DateTimeOffset CreatedAt { get; set; }
136+
137+
/// <summary>
138+
/// Gets the repository's last update date and time.
139+
/// </summary>
140+
public DateTimeOffset UpdatedAt { get; set; }
141+
142+
/// <summary>
143+
/// Gets a value indicating whether the repository is a fork.
144+
/// </summary>
145+
public bool IsFork { get; }
146+
147+
/// <summary>
148+
/// Gets the repository from which this repository was forked, if any.
149+
/// </summary>
150+
[AllowNull] public IRemoteRepositoryModel Parent { [return: AllowNull] get; }
151+
152+
/// <summary>
153+
/// Gets the default branch for the repository.
154+
/// </summary>
155+
public IBranch DefaultBranch { get; }
156+
157+
internal string DebuggerDisplay
158+
{
159+
get
160+
{
161+
return String.Format(CultureInfo.InvariantCulture,
162+
"{4}\tId: {0} Name: {1} CloneUrl: {2} Account: {3}", Id, Name, CloneUrl, Owner, GetHashCode());
163+
}
164+
}
165+
}
166+
}

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using System.Reactive.Threading.Tasks;
1919
using System.Collections.Generic;
20+
using GitHub.Extensions;
2021

2122
namespace GitHub.Models
2223
{

src/GitHub.App/Models/RepositoryModel.cs

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/GitHub.App/SampleData/PullRequestCreationViewModelDesigner.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public PullRequestCreationViewModelDesigner()
1414
{
1515
Branches = new List<IBranch>
1616
{
17-
new BranchModel("master", new SimpleRepositoryModel("http://github.com/user/repo")),
18-
new BranchModel("don/stub-ui", new SimpleRepositoryModel("http://github.com/user/repo")),
19-
new BranchModel("feature/pr/views", new SimpleRepositoryModel("http://github.com/user/repo")),
20-
new BranchModel("release-1.0.17.0", new SimpleRepositoryModel("http://github.com/user/repo")),
17+
new BranchModel("master", new LocalRepositoryModel("http://github.com/user/repo")),
18+
new BranchModel("don/stub-ui", new LocalRepositoryModel("http://github.com/user/repo")),
19+
new BranchModel("feature/pr/views", new LocalRepositoryModel("http://github.com/user/repo")),
20+
new BranchModel("release-1.0.17.0", new LocalRepositoryModel("http://github.com/user/repo")),
2121
}.AsReadOnly();
2222

23-
TargetBranch = new BranchModel("master", new SimpleRepositoryModel("http://github.com/user/repo"));
23+
TargetBranch = new BranchModel("master", new LocalRepositoryModel("http://github.com/user/repo"));
2424
SourceBranch = Branches[2];
2525

2626
SelectedAssignee = "Haacked (Phil Haack)";

0 commit comments

Comments
 (0)