4
4
using System . Linq ;
5
5
using System . Threading . Tasks ;
6
6
using GitReleaseManager . Core . Configuration ;
7
+ using GitReleaseManager . Core . Exceptions ;
7
8
using GitReleaseManager . Core . Helpers ;
8
9
using GitReleaseManager . Core . Model ;
9
10
using GitReleaseManager . Core . Provider ;
@@ -124,36 +125,43 @@ private string GetValidLabel(string label, int issuesCount)
124
125
return newLabel ;
125
126
}
126
127
127
- private bool CheckForValidLabels ( Issue issue )
128
+ private ( List < Issue > IssuesWithValidLabel , List < string > Errors ) CheckIssuesForValidLabels ( IEnumerable < Issue > issues )
128
129
{
129
- var includedIssuesCount = 0 ;
130
- var excludedIssuesCount = 0 ;
130
+ var validIssues = new List < Issue > ( ) ;
131
+ var errors = new List < string > ( ) ;
131
132
132
- foreach ( var issueLabel in issue . Labels )
133
+ foreach ( var issue in issues )
133
134
{
134
- includedIssuesCount += _configuration . IssueLabelsInclude . Count ( issueToInclude => issueLabel . Name . ToUpperInvariant ( ) == issueToInclude . ToUpperInvariant ( ) ) ;
135
+ var includedIssuesCount = 0 ;
136
+ var excludedIssuesCount = 0 ;
135
137
136
- excludedIssuesCount += _configuration . IssueLabelsExclude . Count ( issueToExclude => issueLabel . Name . ToUpperInvariant ( ) == issueToExclude . ToUpperInvariant ( ) ) ;
137
- }
138
+ foreach ( var issueLabel in issue . Labels )
139
+ {
140
+ includedIssuesCount += _configuration . IssueLabelsInclude . Count ( issueToInclude => issueLabel . Name . ToUpperInvariant ( ) == issueToInclude . ToUpperInvariant ( ) ) ;
138
141
139
- if ( includedIssuesCount + excludedIssuesCount != 1 )
140
- {
141
- var allIssueLabels = _configuration . IssueLabelsInclude . Union ( _configuration . IssueLabelsExclude ) . ToList ( ) ;
142
- var allIssuesExceptLast = allIssueLabels . Take ( allIssueLabels . Count - 1 ) ;
143
- var lastLabel = allIssueLabels . Last ( ) ;
142
+ excludedIssuesCount += _configuration . IssueLabelsExclude . Count ( issueToExclude => issueLabel . Name . ToUpperInvariant ( ) == issueToExclude . ToUpperInvariant ( ) ) ;
143
+ }
144
144
145
- var allIssuesExceptLastString = string . Join ( ", " , allIssuesExceptLast ) ;
145
+ if ( includedIssuesCount + excludedIssuesCount != 1 )
146
+ {
147
+ var allIssueLabels = _configuration . IssueLabelsInclude . Union ( _configuration . IssueLabelsExclude ) . ToList ( ) ;
148
+ var allIssuesExceptLast = allIssueLabels . Take ( allIssueLabels . Count - 1 ) ;
149
+ var lastLabel = allIssueLabels . Last ( ) ;
146
150
147
- var message = string . Format ( CultureInfo . InvariantCulture , "Bad Issue {0} expected to find a single label with either {1} or {2}." , issue . HtmlUrl , allIssuesExceptLastString , lastLabel ) ;
148
- throw new InvalidOperationException ( message ) ;
149
- }
151
+ var allIssuesExceptLastString = string . Join ( ", " , allIssuesExceptLast ) ;
150
152
151
- if ( includedIssuesCount > 0 )
152
- {
153
- return true ;
153
+ var message = string . Format ( CultureInfo . InvariantCulture , "Bad Issue {0} expected to find a single label with either {1} or {2}." , issue . HtmlUrl , allIssuesExceptLastString , lastLabel ) ;
154
+ errors . Add ( message ) ;
155
+ continue ;
156
+ }
157
+
158
+ if ( includedIssuesCount > 0 )
159
+ {
160
+ validIssues . Add ( issue ) ;
161
+ }
154
162
}
155
163
156
- return false ;
164
+ return ( validIssues , errors ) ;
157
165
}
158
166
159
167
private Milestone GetPreviousMilestone ( )
@@ -173,28 +181,25 @@ private async Task LoadMilestonesAsync()
173
181
174
182
private async Task < List < Issue > > GetIssuesAsync ( Milestone milestone )
175
183
{
176
- var issues = await _vcsProvider . GetIssuesAsync ( _user , _repository , milestone . Number , ItemStateFilter . Closed ) . ConfigureAwait ( false ) ;
184
+ var allIssues = await _vcsProvider . GetIssuesAsync ( _user , _repository , milestone . Number , ItemStateFilter . Closed ) . ConfigureAwait ( false ) ;
177
185
178
- var hasIncludedIssues = false ;
186
+ var result = CheckIssuesForValidLabels ( allIssues ) ;
179
187
180
- foreach ( var issue in issues )
188
+ if ( result . Errors . Count > 0 )
181
189
{
182
- if ( CheckForValidLabels ( issue ) )
183
- {
184
- hasIncludedIssues = true ;
185
- }
190
+ throw new InvalidIssuesException ( result . Errors ) ;
186
191
}
187
192
188
193
// If there are no issues assigned to the milestone that have a label that is part
189
194
// of the labels to include array, then that is essentially the same as having no
190
195
// closed issues assigned to the milestone. In this scenario, we want to raise an
191
196
// error, so return an emtpy issues list.
192
- if ( ! hasIncludedIssues )
197
+ if ( ! result . IssuesWithValidLabel . Any ( ) )
193
198
{
194
199
return new List < Issue > ( ) ;
195
200
}
196
201
197
- return issues . ToList ( ) ;
202
+ return allIssues . ToList ( ) ;
198
203
}
199
204
200
205
private void GetTargetMilestone ( )
0 commit comments