-
Notifications
You must be signed in to change notification settings - Fork 741
/
Copy pathGHDiscussion.java
281 lines (252 loc) · 7.45 KB
/
GHDiscussion.java
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
// TODO: Auto-generated Javadoc
/**
* A discussion in GitHub Team.
*
* @author Charles Moulliard
* @see <a href="https://developer.github.com/v3/teams/discussions">GitHub Team Discussions</a>
*/
public class GHDiscussion extends GHObject {
/**
* Create default GHDiscussion instance
*/
public GHDiscussion() {
}
private GHTeam team;
private long number;
private String body, title, htmlUrl;
@JsonProperty(value = "private")
private boolean isPrivate;
/**
* Gets the html url.
*
* @return the html url
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public URL getHtmlUrl() throws IOException {
return GitHubClient.parseURL(htmlUrl);
}
/**
* Wrap up.
*
* @param team
* the team
* @return the GH discussion
*/
GHDiscussion wrapUp(GHTeam team) {
this.team = team;
return this;
}
/**
* Get the team to which this discussion belongs.
*
* @return the team for this discussion
*/
@Nonnull
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHTeam getTeam() {
return team;
}
/**
* Get the title of the discussion.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* The description of this discussion.
*
* @return the body
*/
public String getBody() {
return body;
}
/**
* The number of this discussion.
*
* @return the number
*/
public long getNumber() {
return number;
}
/**
* The id number of this discussion. GitHub discussions have "number" instead of "id". This is provided for
* convenience.
*
* @return the id number for this discussion
* @see #getNumber()
*/
@Override
public long getId() {
return getNumber();
}
/**
* Whether the discussion is private to the team.
*
* @return {@code true} if discussion is private.
*/
public boolean isPrivate() {
return isPrivate;
}
/**
* Begins the creation of a new instance.
*
* Consumer must call {@link GHDiscussion.Creator#done()} to commit changes.
*
* @param team
* the team in which the discussion will be created.
* @return a {@link GHLabel.Creator}
* @throws IOException
* the io exception
*/
static GHDiscussion.Creator create(GHTeam team) throws IOException {
return new GHDiscussion.Creator(team);
}
/**
* Read.
*
* @param team
* the team
* @param discussionNumber
* the discussion number
* @return the GH discussion
* @throws IOException
* Signals that an I/O exception has occurred.
*/
static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException {
return team.root()
.createRequest()
.setRawUrlPath(getRawUrlPath(team, discussionNumber))
.fetch(GHDiscussion.class)
.wrapUp(team);
}
/**
* Read all.
*
* @param team
* the team
* @return the paged iterable
* @throws IOException
* Signals that an I/O exception has occurred.
*/
static PagedIterable<GHDiscussion> readAll(GHTeam team) throws IOException {
return team.root()
.createRequest()
.setRawUrlPath(getRawUrlPath(team, null))
.toIterable(GHDiscussion[].class, item -> item.wrapUp(team));
}
/**
* Begins a batch update
*
* Consumer must call {@link GHDiscussion.Updater#done()} to commit changes.
*
* @return a {@link GHDiscussion.Updater}
*/
public GHDiscussion.Updater update() {
return new GHDiscussion.Updater(this);
}
/**
* Begins a single property update.
*
* @return a {@link GHDiscussion.Setter}
*/
public GHDiscussion.Setter set() {
return new GHDiscussion.Setter(this);
}
/**
* Delete the discussion.
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
team.root().createRequest().method("DELETE").setRawUrlPath(getRawUrlPath(team, number)).send();
}
private static String getRawUrlPath(@Nonnull GHTeam team, @CheckForNull Long discussionNumber) {
return team.getUrl().toString() + "/discussions" + (discussionNumber == null ? "" : "/" + discussionNumber);
}
/**
* A {@link GHLabelBuilder} that updates a single property per request
*
* {@link GitHubRequestBuilderDone#done()} is called automatically after the property is set.
*/
public static class Setter extends GHDiscussionBuilder<GHDiscussion> {
private Setter(@Nonnull GHDiscussion base) {
super(GHDiscussion.class, base.team, base);
requester.method("PATCH").setRawUrlPath(base.getUrl().toString());
}
}
/**
* A {@link GHLabelBuilder} that allows multiple properties to be updated per request.
*
* Consumer must call {@link Updater#done()} to commit changes.
*/
public static class Updater extends GHDiscussionBuilder<Updater> {
private Updater(@Nonnull GHDiscussion base) {
super(GHDiscussion.Updater.class, base.team, base);
requester.method("PATCH").setRawUrlPath(base.getUrl().toString());
}
}
/**
* A {@link GHLabelBuilder} that creates a new {@link GHLabel}
*
* Consumer must call {@link Creator#done()} to create the new instance.
*/
public static class Creator extends GHDiscussionBuilder<Creator> {
private Creator(@Nonnull GHTeam team) {
super(GHDiscussion.Creator.class, team, null);
requester.method("POST").setRawUrlPath(getRawUrlPath(team, null));
}
/**
* Sets whether this discussion is private to this team.
*
* @param value
* privacy of this discussion
* @return either a continuing builder or an updated {@link GHDiscussion}
* @throws IOException
* if there is an I/O Exception
*/
@Nonnull
public Creator private_(boolean value) throws IOException {
return with("private", value);
}
}
/**
* Equals.
*
* @param o
* the o
* @return true, if successful
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GHDiscussion that = (GHDiscussion) o;
return number == that.number && Objects.equals(getUrl(), that.getUrl()) && Objects.equals(team, that.team)
&& Objects.equals(body, that.body) && Objects.equals(title, that.title);
}
/**
* Hash code.
*
* @return the int
*/
@Override
public int hashCode() {
return Objects.hash(team, number, body, title);
}
}