-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathApplicationProperties.java
389 lines (306 loc) · 7.96 KB
/
ApplicationProperties.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.githubchangeloggenerator;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.util.Assert;
import io.spring.githubchangeloggenerator.github.service.Repository;
/**
* Configuration properties for the Github repo.
*
* @author Madhura Bhave
* @author Phillip Webb
* @author Mahendra Bishnoi
* @author Gary Russell
* @author Steven Sheehy
*/
@ConfigurationProperties(prefix = "changelog")
@ConstructorBinding
public class ApplicationProperties {
/**
* GitHub repository to use in the form "owner/repository".
*/
private final Repository repository;
/**
* The way that milestones are referenced. Supports "title", "id".
*/
private final MilestoneReference milestoneReference;
/**
* Section definitions in the order that they should appear.
*/
private final List<Section> sections;
/**
* Settings specific to issues.
*/
private final Issues issues;
/**
* Settings specific to contributors.
*/
private final Contributors contributors;
/**
* Settings specific to external links.
*/
private final List<ExternalLink> externalLinks;
/**
* True to add sections to default instead of replacing.
*/
private final boolean addSections;
public ApplicationProperties(Repository repository, @DefaultValue("title") MilestoneReference milestoneReference,
List<Section> sections, Issues issues, Contributors contributors, List<ExternalLink> externalLinks,
@DefaultValue("false") boolean addSections) {
Assert.notNull(repository, "Repository must not be null");
this.repository = repository;
this.milestoneReference = milestoneReference;
this.sections = (sections != null) ? sections : Collections.emptyList();
this.issues = (issues != null) ? issues : new Issues(null, null, null);
this.contributors = (contributors != null) ? contributors : new Contributors(null, null);
this.externalLinks = (externalLinks != null) ? externalLinks : Collections.emptyList();
this.addSections = addSections;
}
public Repository getRepository() {
return this.repository;
}
public MilestoneReference getMilestoneReference() {
return this.milestoneReference;
}
public List<Section> getSections() {
return this.sections;
}
public Issues getIssues() {
return this.issues;
}
public Contributors getContributors() {
return this.contributors;
}
public List<ExternalLink> getExternalLinks() {
return this.externalLinks;
}
public boolean isAddSections() {
return this.addSections;
}
/**
* Properties for a single changelog section.
*/
public static class Section {
/**
* Title of the section.
*/
private final String title;
/**
* Group used to bound the contained issues. Issues appear in the first section of
* each group.
*/
private final String group;
/**
* Sort order for issues within this section.
*/
private final IssueSort sort;
/**
* Labels used to identify if an issue is for the section.
*/
private final Set<String> labels;
/**
* Whether issues, pull requests or both should be included in this section.
*/
private final IssueType type;
public Section(String title, @DefaultValue("default") String group, IssueSort sort, Set<String> labels,
@DefaultValue("ANY") IssueType type) {
this.title = title;
this.group = (group != null) ? group : "default";
this.sort = sort;
this.labels = labels;
this.type = type;
}
public String getTitle() {
return this.title;
}
public String getGroup() {
return this.group;
}
public IssueSort getSort() {
return this.sort;
}
public Set<String> getLabels() {
return this.labels;
}
public IssueType getType() {
return this.type;
}
}
/**
* Properties relating to issues.
*/
public static class Issues {
/**
* The issue sort order.
*/
private final IssueSort sort;
/**
* Issue exclusions.
*/
private final IssuesExclude exclude;
/**
* Identification of issues that are a forward-port or back-port of another issue.
*/
private final Set<PortedIssue> ports;
public Issues(IssueSort sort, IssuesExclude exclude, Set<PortedIssue> ports) {
this.sort = sort;
this.exclude = (exclude != null) ? exclude : new IssuesExclude(null);
this.ports = (ports != null) ? ports : Collections.emptySet();
}
public IssueSort getSort() {
return this.sort;
}
public IssuesExclude getExcludes() {
return this.exclude;
}
public Set<PortedIssue> getPorts() {
return this.ports;
}
}
/**
* Issues exclude.
*/
public static class IssuesExclude {
/**
* Labels used to exclude issues.
*/
private final Set<String> labels;
public IssuesExclude(Set<String> labels) {
this.labels = (labels != null) ? labels : Collections.emptySet();
}
public Set<String> getLabels() {
return this.labels;
}
}
/**
* Properties related to identification of ported issues.
*/
public static class PortedIssue {
/**
* Label used to identify a ported issue.
*/
private final String label;
/**
* Regular expression used to extract the upstream or downstream issue ID from the
* body of a ported issue.
*/
private final Pattern bodyExpression;
public PortedIssue(String label, String bodyExpression) {
this.label = label;
this.bodyExpression = Pattern.compile(bodyExpression);
}
public String getLabel() {
return this.label;
}
public Pattern getBodyExpression() {
return this.bodyExpression;
}
}
/**
* Properties relating to constructors.
*/
public static class Contributors {
/**
* Title for the contributors section.
*/
private final String title;
/**
* Contributor exclusions.
*/
private final ContributorsExclude exclude;
public Contributors(String title, ContributorsExclude exclude) {
this.title = title;
this.exclude = (exclude != null) ? exclude : new ContributorsExclude(null);
}
public String getTitle() {
return this.title;
}
public ContributorsExclude getExclude() {
return this.exclude;
}
}
/**
* Contributors exclude.
*/
public static class ContributorsExclude {
/**
* Contributor names to exclude.
*/
private final Set<String> names;
public ContributorsExclude(Set<String> names) {
this.names = (names != null) ? names : Collections.emptySet();
}
public Set<String> getNames() {
return this.names;
}
}
/**
* Properties for a single external link.
*/
public static class ExternalLink {
/**
* Name to be shown for an external link.
*/
private final String name;
/**
* URL for an external link.
*/
private final String location;
public ExternalLink(String name, String location) {
this.name = name;
this.location = location;
}
public String getName() {
return this.name;
}
public String getLocation() {
return this.location;
}
}
public enum IssueSort {
/**
* Sort by the created date.
*/
CREATED,
/**
* Sort by the title.
*/
TITLE
}
/**
* The type of changelog entry.
*/
public enum IssueType {
/**
* Either issue or pull requests.
*/
ANY,
/**
* GitHub issue.
*/
ISSUE,
/**
* GitHub pull request.
*/
PULL_REQUEST
}
}