forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGHLabel.java
More file actions
285 lines (254 loc) · 6.71 KB
/
Copy pathGHLabel.java
File metadata and controls
285 lines (254 loc) · 6.71 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
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
282
283
284
285
package org.kohsuke.github;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
// TODO: Auto-generated Javadoc
/**
* The type GHLabel.
*
* @author Kohsuke Kawaguchi
* @see <a href="https://developer.github.com/v3/issues/labels/">Labels</a>
* @see GHIssue#getLabels() GHIssue#getLabels()
* @see GHRepository#listLabels() GHRepository#listLabels()
*/
public class GHLabel extends GitHubInteractiveObject {
/**
* A {@link GHLabelBuilder} that creates a new {@link GHLabel}
*
* Consumer must call {@link Creator#done()} to create the new instance.
*/
@BetaApi
public static class Creator extends GHLabelBuilder<Creator> {
private Creator(@Nonnull GHRepository repository) {
super(Creator.class, repository.root(), null);
requester.method("POST").withUrlPath(repository.getApiTailUrl("labels"));
}
}
/**
* A {@link GHLabelBuilder} that updates a single property per request
*
* {@link Setter#done()} is called automatically after the property is set.
*/
@BetaApi
public static class Setter extends GHLabelBuilder<GHLabel> {
private Setter(@Nonnull GHLabel base) {
super(GHLabel.class, base.getApiRoot(), base);
requester.method("PATCH").setRawUrlPath(base.getUrl());
}
}
/**
* A {@link GHLabelBuilder} that allows multiple properties to be updated per request.
*
* Consumer must call {@link Updater#done()} to commit changes.
*/
@BetaApi
public static class Updater extends GHLabelBuilder<Updater> {
private Updater(@Nonnull GHLabel base) {
super(Updater.class, base.getApiRoot(), base);
requester.method("PATCH").setRawUrlPath(base.getUrl());
}
}
/**
* Begins the creation of a new instance.
*
* Consumer must call {@link Creator#done()} to commit changes.
*
* @param repository
* the repository in which the label will be created.
* @return a {@link Creator}
*/
@BetaApi
static Creator create(GHRepository repository) {
return new Creator(repository);
}
/**
* Reads a label from a repository.
*
* @param repository
* the repository to read from
* @param name
* the name of the label
* @return a label
* @throws IOException
* the io exception
*/
static GHLabel read(@Nonnull GHRepository repository, @Nonnull String name) throws IOException {
return repository.root()
.createRequest()
.withUrlPath(repository.getApiTailUrl("labels"), name)
.fetch(GHLabel.class);
}
/**
* Reads all labels from a repository.
*
* @param repository
* the repository to read from
* @return iterable of all labels
*/
static PagedIterable<GHLabel> readAll(@Nonnull final GHRepository repository) {
return repository.root()
.createRequest()
.withUrlPath(repository.getApiTailUrl("labels"))
.toIterable(GHLabel[].class, null);
}
/**
* To names.
*
* @param labels
* the labels
* @return the collection
*/
static Collection<String> toNames(Collection<GHLabel> labels) {
List<String> r = new ArrayList<>();
for (GHLabel l : labels) {
r.add(l.getName());
}
return r;
}
@CheckForNull
private String description;
private long id;
@JsonProperty("default")
private boolean isDefault;
private String nodeId;
@Nonnull
private String url, name, color;
@JsonCreator
private GHLabel(@JacksonInject @Nonnull GitHub root) {
url = "";
name = "";
color = "";
description = null;
}
/**
* Delete this label from the repository.
*
* @throws IOException
* the io exception
*/
public void delete() throws IOException {
root().createRequest().method("DELETE").setRawUrlPath(getUrl()).send();
}
/**
* Equals.
*
* @param o
* the o
* @return true, if successful
*/
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
final GHLabel ghLabel = (GHLabel) o;
return Objects.equals(url, ghLabel.url) && Objects.equals(name, ghLabel.name)
&& Objects.equals(color, ghLabel.color) && Objects.equals(description, ghLabel.description);
}
/**
* Color code without leading '#', such as 'f29513'.
*
* @return the color
*/
@Nonnull
public String getColor() {
return color;
}
/**
* Purpose of Label.
*
* @return the description
*/
@CheckForNull
public String getDescription() {
return description;
}
/**
* Gets id.
*
* @return the id
*/
public long getId() {
return id;
}
/**
* Gets name.
*
* @return the name
*/
@Nonnull
public String getName() {
return name;
}
/**
* Gets node id.
*
* @return the node id.
*/
public String getNodeId() {
return nodeId;
}
/**
* Gets url.
*
* @return the url
*/
@Nonnull
public String getUrl() {
return url;
}
/**
* Hash code.
*
* @return the int
*/
@Override
public int hashCode() {
return Objects.hash(url, name, color, description);
}
/**
* If the label is one of the default labels created by GitHub automatically.
*
* @return true if the label is a default one
*/
public boolean isDefault() {
return isDefault;
}
/**
* Begins a single property update.
*
* @return a {@link Setter}
*/
@BetaApi
public Setter set() {
return new Setter(this);
}
/**
* Begins a batch update
*
* Consumer must call {@link Updater#done()} to commit changes.
*
* @return a {@link Updater}
*/
@BetaApi
public Updater update() {
return new Updater(this);
}
/**
* Gets the api root.
*
* @return the api root
*/
@Nonnull
GitHub getApiRoot() {
return Objects.requireNonNull(root());
}
}