@@ -147,13 +147,34 @@ private Dictionary<string, List<Issue>> GetIssuesDict(List<Issue> issues)
147147 var issueLabels = _configuration . IssueLabelsInclude ;
148148 var excludedIssueLabels = _configuration . IssueLabelsExclude ;
149149
150+ Func < SortIssuesBy , string > getSortPropertyName = ( sortBy ) =>
151+ {
152+ return sortBy switch
153+ {
154+ SortIssuesBy . Title => "Title" ,
155+ SortIssuesBy . Id => "PublicNumber" ,
156+ _ => throw new NotSupportedException ( $ "'{ sortBy } ' is an unknown sort property.") ,
157+ } ;
158+ } ;
159+
160+ Func < Issue , object ? > keySelector = ( i ) => typeof ( Issue ) . GetProperty ( getSortPropertyName ( _configuration . Create . SortIssuesBy ) ) . GetValue ( i , null ) ;
161+
150162 var issuesByLabel = issues
151163 . Where ( o => ! o . Labels . Any ( l => excludedIssueLabels . Any ( eil => string . Equals ( eil , l . Name , StringComparison . OrdinalIgnoreCase ) ) ) )
152164 . SelectMany ( o => o . Labels , ( issue , label ) => new { Label = label . Name , Issue = issue } )
153165 . Where ( o => issueLabels . Any ( il => string . Equals ( il , o . Label , StringComparison . OrdinalIgnoreCase ) ) )
154166 . GroupBy ( o => o . Label , o => o . Issue )
155- . OrderBy ( o => o . Key )
156- . ToDictionary ( o => GetValidLabel ( o . Key , o . Count ( ) ) , o => o . OrderBy ( issue => issue . PublicNumber ) . ToList ( ) ) ;
167+ . OrderBy ( o => o . Key ) // Sort the labels alphabetically
168+ . ToDictionary ( o => GetValidLabel ( o . Key , o . Count ( ) ) , o =>
169+ {
170+ // Sort the issues within each label group based on configuration
171+ return _configuration . Create . SortIssuesDirection switch
172+ {
173+ SortDirection . Ascending => o . OrderBy ( i => keySelector ( i ) ) . ToList ( ) ,
174+ SortDirection . Descending => o . OrderByDescending ( i => keySelector ( i ) ) . ToList ( ) ,
175+ _ => throw new NotSupportedException ( $ "'{ _configuration . Create . SortIssuesDirection } ' is an unknown sort direction.") ,
176+ } ;
177+ } ) ;
157178
158179 return issuesByLabel ;
159180 }
0 commit comments