@@ -46,6 +46,13 @@ public async Task<string> BuildReleaseNotes()
46
46
var previousMilestone = GetPreviousMilestone ( ) ;
47
47
var numberOfCommits = await _vcsProvider . GetNumberOfCommitsBetween ( previousMilestone , _targetMilestone , _user , _repository ) . ConfigureAwait ( false ) ;
48
48
49
+ if ( issues . Count == 0 )
50
+ {
51
+ var logMessage = string . Format ( "No closed issues have been found for milestone {0}, or all assigned issues are meant to be excluded from release notes, aborting creation of release." , _milestoneTitle ) ;
52
+ Logger . WriteError ( logMessage ) ;
53
+ throw new Exception ( logMessage ) ;
54
+ }
55
+
49
56
if ( issues . Count > 0 )
50
57
{
51
58
var issuesText = string . Format ( issues . Count == 1 ? "{0} issue" : "{0} issues" , issues . Count ) ;
@@ -109,18 +116,19 @@ private string GetLabel(string label, Func<LabelAlias, string> func)
109
116
return alias != null ? func ( alias ) : null ;
110
117
}
111
118
112
- private void CheckForValidLabels ( Issue issue )
119
+ private bool CheckForValidLabels ( Issue issue )
113
120
{
114
- var count = 0 ;
121
+ var includedIssuesCount = 0 ;
122
+ var excludedIssuesCount = 0 ;
115
123
116
124
foreach ( var issueLabel in issue . Labels )
117
125
{
118
- count += _configuration . IssueLabelsInclude . Count ( issueToInclude => issueLabel . Name . ToUpperInvariant ( ) == issueToInclude . ToUpperInvariant ( ) ) ;
126
+ includedIssuesCount += _configuration . IssueLabelsInclude . Count ( issueToInclude => issueLabel . Name . ToUpperInvariant ( ) == issueToInclude . ToUpperInvariant ( ) ) ;
119
127
120
- count += _configuration . IssueLabelsExclude . Count ( issueToExclude => issueLabel . Name . ToUpperInvariant ( ) == issueToExclude . ToUpperInvariant ( ) ) ;
128
+ excludedIssuesCount += _configuration . IssueLabelsExclude . Count ( issueToExclude => issueLabel . Name . ToUpperInvariant ( ) == issueToExclude . ToUpperInvariant ( ) ) ;
121
129
}
122
130
123
- if ( count != 1 )
131
+ if ( includedIssuesCount + excludedIssuesCount != 1 )
124
132
{
125
133
var allIssueLabels = _configuration . IssueLabelsInclude . Union ( _configuration . IssueLabelsExclude ) . ToList ( ) ;
126
134
var allIssuesExceptLast = allIssueLabels . Take ( allIssueLabels . Count - 1 ) ;
@@ -131,6 +139,13 @@ private void CheckForValidLabels(Issue issue)
131
139
var message = string . Format ( CultureInfo . InvariantCulture , "Bad Issue {0} expected to find a single label with either {1} or {2}." , issue . HtmlUrl , allIssuesExceptLastString , lastLabel ) ;
132
140
throw new InvalidOperationException ( message ) ;
133
141
}
142
+
143
+ if ( includedIssuesCount > 0 )
144
+ {
145
+ return true ;
146
+ }
147
+
148
+ return false ;
134
149
}
135
150
136
151
private void AddIssues ( StringBuilder stringBuilder , List < Issue > issues )
@@ -181,9 +196,24 @@ private async Task LoadMilestones()
181
196
private async Task < List < Issue > > GetIssues ( Milestone milestone )
182
197
{
183
198
var issues = await _vcsProvider . GetIssuesAsync ( milestone ) . ConfigureAwait ( false ) ;
199
+
200
+ var hasIncludedIssues = false ;
201
+
184
202
foreach ( var issue in issues )
185
203
{
186
- CheckForValidLabels ( issue ) ;
204
+ if ( CheckForValidLabels ( issue ) )
205
+ {
206
+ hasIncludedIssues = true ;
207
+ }
208
+ }
209
+
210
+ // If there are no issues assigned to the milestone that have a label that is part
211
+ // of the labels to include array, then that is essentially the same as having no
212
+ // closed issues assigned to the milestone. In this scenario, we want to raise an
213
+ // error, so return an emtpy issues list.
214
+ if ( ! hasIncludedIssues )
215
+ {
216
+ return new List < Issue > ( ) ;
187
217
}
188
218
189
219
return issues ;
0 commit comments