This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathPullRequestModel.cs
More file actions
186 lines (161 loc) · 5.68 KB
/
Copy pathPullRequestModel.cs
File metadata and controls
186 lines (161 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System;
using System.Globalization;
using GitHub.Primitives;
using GitHub.VisualStudio.Helpers;
using System.Diagnostics;
using System.Collections.Generic;
using GitHub.Extensions;
namespace GitHub.Models
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public sealed class PullRequestModel : NotificationAwareObject, IPullRequestModel,
IEquatable<PullRequestModel>,
IComparable<PullRequestModel>
{
public PullRequestModel(int number, string title, IAccount author,
DateTimeOffset createdAt, DateTimeOffset? updatedAt = null)
{
Number = number;
Title = title;
Author = author;
CreatedAt = createdAt;
UpdatedAt = updatedAt ?? CreatedAt;
}
public void CopyFrom(IPullRequestModel other)
{
if (!Equals(other))
throw new ArgumentException("Instance to copy from doesn't match this instance. this:(" + this + ") other:(" + other + ")", nameof(other));
Title = other.Title;
State = other.State;
UpdatedAt = other.UpdatedAt;
CommentCount = other.CommentCount;
HasNewComments = other.HasNewComments;
Assignee = other.Assignee;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
return true;
var other = obj as PullRequestModel;
return other != null && Number == other.Number;
}
public override int GetHashCode()
{
return Number.GetHashCode();
}
bool IEquatable<IPullRequestModel>.Equals(IPullRequestModel other)
{
if (ReferenceEquals(this, other))
return true;
return other != null && Number == other.Number;
}
bool IEquatable<PullRequestModel>.Equals(PullRequestModel other)
{
if (ReferenceEquals(this, other))
return true;
return other != null && Number == other.Number;
}
public int CompareTo(IPullRequestModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}
public int CompareTo(PullRequestModel other)
{
return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1;
}
public static bool operator >(PullRequestModel lhs, PullRequestModel rhs)
{
if (ReferenceEquals(lhs, rhs))
return false;
return lhs?.CompareTo(rhs) > 0;
}
public static bool operator <(PullRequestModel lhs, PullRequestModel rhs)
{
if (ReferenceEquals(lhs, rhs))
return false;
return (object)lhs == null || lhs.CompareTo(rhs) < 0;
}
public static bool operator ==(PullRequestModel lhs, PullRequestModel rhs)
{
return ReferenceEquals(lhs, rhs);
}
public static bool operator !=(PullRequestModel lhs, PullRequestModel rhs)
{
return !(lhs == rhs);
}
public int Number { get; }
string title;
public string Title
{
get { return title; }
set
{
Guard.ArgumentNotNull(value, nameof(value));
title = value;
this.RaisePropertyChange();
}
}
PullRequestState status;
public PullRequestState State
{
get { return status; }
set
{
status = value;
this.RaisePropertyChange();
// TODO: These notifications will be removed once maintainer workflow has been merged to master.
this.RaisePropertyChange(nameof(IsOpen));
this.RaisePropertyChange(nameof(Merged));
}
}
// TODO: Remove these property once maintainer workflow has been merged to master.
public bool IsOpen => State == PullRequestState.Open;
public bool Merged => State == PullRequestState.Merged;
int commentCount;
public int CommentCount
{
get { return commentCount; }
set { commentCount = value; this.RaisePropertyChange(); }
}
int commitCount;
public int CommitCount
{
get { return commitCount; }
set { commitCount = value; this.RaisePropertyChange(); }
}
bool hasNewComments;
public bool HasNewComments
{
get { return hasNewComments; }
set { hasNewComments = value; this.RaisePropertyChange(); }
}
string body;
public string Body
{
get { return body; }
set { body = value; this.RaisePropertyChange(); }
}
public GitReferenceModel Base { get; set; }
public GitReferenceModel Head { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public IAccount Author { get; set; }
IAccount assignee;
public IAccount Assignee
{
get { return assignee; }
set { assignee = value; this.RaisePropertyChange(); }
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "id:{0} title:{1} created:{2:u} updated:{3:u}", Number, Title, CreatedAt, UpdatedAt);
}
internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "id:{0} title:{1} created:{2:u} updated:{3:u}", Number, Title, CreatedAt, UpdatedAt);
}
}
}
}