Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GitHub.App/Api/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,9 @@ public IObservable<PullRequest> GetPullRequestsForRepository(string owner, strin
SortDirection = SortDirection.Descending
});
}
public IObservable<Repository> GetRepositories()
{
return gitHubClient.Repository.GetAllForCurrent();
}
}
}
5 changes: 5 additions & 0 deletions src/GitHub.App/Caches/CacheIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace GitHub.Caches
{
public class CacheIndex
{
public const string PRPrefix = "index:pr";
public const string RepoPrefix = "index:repos";
public const string GitIgnoresPrefix = "index:ignores";
public const string LicensesPrefix = "index:licenses";

public static CacheIndex Create(string key)
{
return new CacheIndex { IndexKey = key };
Expand Down
20 changes: 17 additions & 3 deletions src/GitHub.App/Models/PullRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
namespace GitHub.Models
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public sealed class PullRequestModel : NotificationAwareObject, IPullRequestModel
public sealed class PullRequestModel : NotificationAwareObject, IPullRequestModel,
IEquatable<PullRequestModel>,
IComparable<PullRequestModel>
{
public PullRequestModel(int number, string title,
IAccount author, [AllowNull]IAccount assignee,
Expand Down Expand Up @@ -45,7 +47,7 @@ public override bool Equals([AllowNull]object obj)

public override int GetHashCode()
{
return Number;
return Number.GetHashCode();
}

bool IEquatable<IPullRequestModel>.Equals([AllowNull]IPullRequestModel other)
Expand All @@ -55,11 +57,23 @@ bool IEquatable<IPullRequestModel>.Equals([AllowNull]IPullRequestModel other)
return other != null && Number == other.Number;
}

bool IEquatable<PullRequestModel>.Equals([AllowNull]PullRequestModel other)
{
if (ReferenceEquals(this, other))
return true;
return other != null && Number == other.Number;
}

public int CompareTo([AllowNull]IPullRequestModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}

public int CompareTo([AllowNull]PullRequestModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}

public static bool operator >([AllowNull]PullRequestModel lhs, [AllowNull]PullRequestModel rhs)
{
if (ReferenceEquals(lhs, rhs))
Expand All @@ -76,7 +90,7 @@ public int CompareTo([AllowNull]IPullRequestModel other)

public static bool operator ==([AllowNull]PullRequestModel lhs, [AllowNull]PullRequestModel rhs)
{
return Equals(lhs, rhs) && ((object)lhs == null || lhs.CompareTo(rhs) == 0);
return ReferenceEquals(lhs, rhs);
}

public static bool operator !=([AllowNull]PullRequestModel lhs, [AllowNull]PullRequestModel rhs)
Expand Down
68 changes: 61 additions & 7 deletions src/GitHub.App/Models/RepositoryModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,96 @@

namespace GitHub.Models
{
public class RepositoryModel : SimpleRepositoryModel, IRepositoryModel, IEquatable<RepositoryModel>
public class RepositoryModel : SimpleRepositoryModel, IRepositoryModel,
IEquatable<RepositoryModel>, IComparable<RepositoryModel>
{
public RepositoryModel(string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount)
public RepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount)
: base(name, cloneUrl)
{
Id = id;
Owner = ownerAccount;
SetIcon(isPrivate, isFork);
}

public IAccount Owner { get; private set; }
public void CopyFrom(IRepositoryModel other)
{
if (!Equals(other))
throw new ArgumentException("Instance to copy from doesn't match this instance. this:(" + this + ") other:(" + other + ")", nameof(other));
Icon = other.Icon;
}

public override int GetHashCode()
{
return (Owner?.GetHashCode() ?? 0) ^ base.GetHashCode();
return Id.GetHashCode();
}

public override bool Equals([AllowNull]object obj)
{
if (ReferenceEquals(this, obj))
return true;
var other = obj as RepositoryModel;
return other != null && Equals(Owner, other.Owner) && base.Equals(obj);
return other != null && Id == other.Id;
}

bool IEquatable<IRepositoryModel>.Equals([AllowNull]IRepositoryModel other)
{
if (ReferenceEquals(this, other))
return true;
return other != null && Id == other.Id;
}

bool IEquatable<RepositoryModel>.Equals([AllowNull]RepositoryModel other)
{
if (ReferenceEquals(this, other))
return true;
return other != null && Equals(Owner, other.Owner) && base.Equals(other as SimpleRepositoryModel);
return other != null && Id == other.Id;
}

public int CompareTo([AllowNull]IRepositoryModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}

public int CompareTo([AllowNull]RepositoryModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}

public static bool operator >([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs)
{
if (ReferenceEquals(lhs, rhs))
return false;
return lhs?.CompareTo(rhs) > 0;
}

public static bool operator <([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs)
{
if (ReferenceEquals(lhs, rhs))
return false;
return (object)lhs == null || lhs.CompareTo(rhs) < 0;
}

public static bool operator ==([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs)
{
return ReferenceEquals(lhs, rhs);
}

public static bool operator !=([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs)
{
return !(lhs == rhs);
}

public IAccount Owner { get; }
public long Id { get; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }

internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture,
"{4}\tName: {0} CloneUrl: {1} LocalPath: {2} Account: {3}", Name, CloneUrl, LocalPath, Owner, GetHashCode());
"{5}\tId: {0} Name: {1} CloneUrl: {2} LocalPath: {3} Account: {4}", Id, Name, CloneUrl, LocalPath, Owner, GetHashCode());
}
}
}
Expand Down
61 changes: 15 additions & 46 deletions src/GitHub.App/SampleData/SampleViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,65 +318,34 @@ public IObservable<Unit> LogOut()
}

[ExcludeFromCodeCoverage]
public class RepositoryModelDesigner : NotificationAwareObject, IRepositoryModel
public static class RepositoryModelDesigner
{
public RepositoryModelDesigner() : this("repo")
public static IRepositoryModel Create(string name = null, string owner = null)
{
name = name ?? "octocat";
owner = owner ?? "github";
return new RepositoryModel(0, name, new UriString("http://github.com/" + name + "/" + owner), false, false, new AccountDesigner() { Login = owner });
}

public RepositoryModelDesigner(string name) : this("repo", "github")
{
Name = name;
}

public RepositoryModelDesigner(string name, string owner)
{
Name = name;
Owner = new AccountDesigner { Login = owner };
}

public void SetIcon(bool isPrivate, bool isFork)
{
}

public UriString GenerateUrl(string path = null, int startLine = -1, int endLine = -1)
{
return null;
}

public string Name { get; set; }
public UriString CloneUrl { get; set; }
public string LocalPath { get; set; }

public Octicon Icon { get; set; }

public IAccount Owner { get; set; }

public void Refresh() { }
}

public class RepositoryCloneViewModelDesigner : BaseViewModel, IRepositoryCloneViewModel
{
public RepositoryCloneViewModelDesigner()
{
var repositories = new ReactiveList<IRepositoryModel>
Repositories = new ObservableCollection<IRepositoryModel>
{
new RepositoryModelDesigner("encourage", "haacked"),
new RepositoryModelDesigner("haacked.com", "haacked"),
new RepositoryModelDesigner("octokit.net", "octokit"),
new RepositoryModelDesigner("octokit.rb", "octokit"),
new RepositoryModelDesigner("octokit.objc", "octokit"),
new RepositoryModelDesigner("windows", "github"),
new RepositoryModelDesigner("mac", "github"),
new RepositoryModelDesigner("github", "github")
RepositoryModelDesigner.Create("encourage", "haacked"),
RepositoryModelDesigner.Create("haacked.com", "haacked"),
RepositoryModelDesigner.Create("octokit.net", "octokit"),
RepositoryModelDesigner.Create("octokit.rb", "octokit"),
RepositoryModelDesigner.Create("octokit.objc", "octokit"),
RepositoryModelDesigner.Create("windows", "github"),
RepositoryModelDesigner.Create("mac", "github"),
RepositoryModelDesigner.Create("github", "github")
};

BrowseForDirectory = ReactiveCommand.Create();

FilteredRepositories = repositories.CreateDerivedCollection(
x => x
);

BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
.IfNullOrEmpty("Please enter a repository path")
.IfTrue(x => x.Length > 200, "Path too long")
Expand All @@ -392,7 +361,7 @@ public IReactiveCommand<Unit> CloneCommand

public IRepositoryModel SelectedRepository { get; set; }

public IReactiveDerivedList<IRepositoryModel> FilteredRepositories
public ObservableCollection<IRepositoryModel> Repositories
{
get;
private set;
Expand Down
Loading