5
5
using System . Text . RegularExpressions ;
6
6
using System . Threading . Tasks ;
7
7
using Microsoft . Extensions . Configuration ;
8
- using Open_Rails_Triage . Git ;
9
8
using Open_Rails_Triage . Launchpad ;
10
9
11
10
namespace Open_Rails_Triage
@@ -46,6 +45,7 @@ static void Main(string[] args)
46
45
47
46
static async Task AsyncMain ( IConfigurationRoot config , bool verbose )
48
47
{
48
+ var references = new References ( ) ;
49
49
var gitConfig = config . GetSection ( "git" ) ;
50
50
var gitHubConfig = config . GetSection ( "github" ) ;
51
51
var launchpadConfig = config . GetSection ( "launchpad" ) ;
@@ -54,21 +54,20 @@ static async Task AsyncMain(IConfigurationRoot config, bool verbose)
54
54
var git = new Git . Project ( GetGitPath ( ) , verbose ) ;
55
55
git . Init ( gitConfig [ "projectUrl" ] ) ;
56
56
git . Fetch ( ) ;
57
- var commits = git . GetLog ( gitConfig [ "branch" ] , DateTimeOffset . Parse ( gitConfig [ "startDate" ] ) ) ;
58
57
59
58
var gitHub = new GitHub . Project ( gitHubConfig ) ;
60
59
61
60
var launchpad = new Launchpad . Cache ( ) ;
62
61
var launchpadProject = await launchpad . GetProject ( launchpadConfig [ "projectUrl" ] ) ;
63
62
64
- await CommitTriage ( commits , gitConfig , gitHub ) ;
65
- await BugTriage ( launchpadProject , launchpadConfig , commits ) ;
66
- await SpecificationTriage ( launchpadProject , launchpadConfig , commits ) ;
63
+ await CommitTriage ( git , gitConfig , gitHub , references ) ;
64
+ await BugTriage ( launchpadProject , launchpadConfig , references ) ;
65
+ await SpecificationTriage ( launchpadProject , launchpadConfig , references ) ;
67
66
await SpecificationApprovals ( launchpadProject ) ;
68
67
69
68
var trello = new Trello . Cache ( trelloConfig [ "key" ] , trelloConfig [ "token" ] ) ;
70
69
var board = await trello . GetBoard ( trelloConfig [ "board" ] ) ;
71
- await TrelloTriage ( board , trelloConfig , commits ) ;
70
+ await TrelloTriage ( board , trelloConfig , references ) ;
72
71
}
73
72
74
73
static string GetGitPath ( )
@@ -77,47 +76,43 @@ static string GetGitPath()
77
76
return Path . Combine ( Path . GetDirectoryName ( appFilePath ) , "git" ) ;
78
77
}
79
78
80
- static async Task CommitTriage ( List < Commit > commits , IConfigurationSection gitConfig , GitHub . Project gitHub )
79
+ static async Task CommitTriage ( Git . Project git , IConfigurationSection gitConfig , GitHub . Project gitHub , References references )
81
80
{
82
81
Console . WriteLine ( "Commit triage" ) ;
83
82
Console . WriteLine ( "=============" ) ;
84
83
Console . WriteLine ( ) ;
85
84
86
85
var webUrlConfig = gitConfig . GetSection ( "webUrl" ) ;
87
86
var exceptionalLabels = gitConfig . GetSection ( "references:exceptionalLabels" ) . GetChildren ( ) . Select ( item => item . Value ) ;
88
- int . TryParse ( gitConfig [ "references:minimumLines" ] , out var minimumLines ) ;
87
+ if ( ! int . TryParse ( gitConfig [ "references:minimumLines" ] , out var minimumLines ) ) minimumLines = 0 ;
89
88
var requiredLabels = gitConfig . GetSection ( "references:requiredLabels" ) . GetChildren ( ) . Select ( node => node . Value ) ;
90
- var referencePattern = new Regex ( gitConfig [ "references:references" ] ) ;
91
- foreach ( var commit in commits )
89
+
90
+ foreach ( var commit in git . GetLog ( gitConfig [ "branch" ] , DateTimeOffset . Parse ( gitConfig [ "startDate" ] ) ) )
92
91
{
93
- var data = await GetCommitDetails ( gitHub , referencePattern , commit ) ;
94
- commit . References . AddRange ( data . References ) ;
95
- foreach ( var subCommit in commit . Commits )
96
- {
97
- var subData = await GetCommitDetails ( gitHub , referencePattern , subCommit ) ;
98
- commit . References . AddRange ( subData . References ) ;
99
- }
92
+ references . Add ( commit , out var referenceTypes ) ;
100
93
101
- if ( data . PR != null )
94
+ var pr = await gitHub . GetPullRequest ( commit ) ;
95
+ var labels = pr ? . Labels . Nodes . Select ( n => n . Name ) ?? Array . Empty < string > ( ) ;
96
+ if ( pr != null )
102
97
{
103
- if ( data . PR . Labels . Nodes . Any ( label => exceptionalLabels . Contains ( label . Name ) ) ) continue ;
104
- if ( data . PR . Additions <= minimumLines && data . PR . Deletions <= minimumLines ) continue ;
98
+ if ( pr . Labels . Nodes . Any ( label => exceptionalLabels . Contains ( label . Name ) ) ) continue ;
99
+ if ( pr . Additions <= minimumLines && pr . Deletions <= minimumLines ) continue ;
105
100
}
106
101
107
102
var issues = new List < string > ( ) ;
108
103
109
- if ( ! requiredLabels . Any ( label => data . Labels . Contains ( label ) ) )
104
+ if ( requiredLabels . Any ( ) && ! requiredLabels . Any ( label => labels . Contains ( label ) ) )
110
105
{
111
106
issues . Add ( "Missing required labels" ) ;
112
107
}
113
- if ( data . References . Count ( ) == 0 )
108
+ if ( ! IsValuePresentMissing ( gitConfig . GetSection ( "references:types" ) , referenceTypes . ToArray ( ) ) )
114
109
{
115
110
issues . Add ( "Missing required references" ) ;
116
111
}
117
112
118
113
if ( issues . Count > 0 )
119
114
{
120
- Console . WriteLine ( $ "- [{ commit . Summary } ]({ webUrlConfig [ "commit" ] . Replace ( "%KEY%" , commit . Key ) } ) { string . Join ( ", " , data . Labels ) } **at** { commit . AuthorDate } **by** { commit . AuthorName } ") ;
115
+ Console . WriteLine ( $ "- [{ commit . Summary } ]({ webUrlConfig [ "commit" ] . Replace ( "%KEY%" , commit . Key ) } ) { string . Join ( ", " , labels ) } **at** { commit . AuthorDate } **by** { commit . AuthorName } ") ;
121
116
foreach ( var issue in issues )
122
117
{
123
118
Console . WriteLine ( $ " - **Issue:** { issue } ") ;
@@ -127,18 +122,7 @@ static async Task CommitTriage(List<Commit> commits, IConfigurationSection gitCo
127
122
}
128
123
}
129
124
130
- static async Task < ( GitHub . GraphPullRequest PR , IEnumerable < string > Labels , IEnumerable < string > References ) > GetCommitDetails ( GitHub . Project gitHub , Regex referencePattern , Commit commit )
131
- {
132
- var pr = await gitHub . GetPullRequest ( commit ) ;
133
- var message = pr != null ? pr . Title + "\n " + pr . Body : commit . Message ;
134
- return (
135
- PR : pr ,
136
- Labels : pr ? . Labels . Nodes . Select ( n => n . Name ) ?? new string [ 0 ] ,
137
- References : referencePattern . Matches ( message ) . Select ( match => match . Value )
138
- ) ;
139
- }
140
-
141
- static async Task BugTriage ( Launchpad . Project project , IConfigurationSection config , List < Commit > commits )
125
+ static async Task BugTriage ( Launchpad . Project project , IConfigurationSection config , References references )
142
126
{
143
127
Console . WriteLine ( "Bug triage" ) ;
144
128
Console . WriteLine ( "==========" ) ;
@@ -167,6 +151,8 @@ static async Task BugTriage(Launchpad.Project project, IConfigurationSection con
167
151
continue ;
168
152
}
169
153
154
+ references . Add ( bug , out var _ ) ;
155
+
170
156
var issues = new List < string > ( ) ;
171
157
172
158
var idealTitles = new List < string > ( ) ;
@@ -263,14 +249,13 @@ static async Task BugTriage(Launchpad.Project project, IConfigurationSection con
263
249
}
264
250
}
265
251
266
- var commitMentions = commits . Where ( commit => commit . References . Contains ( bugTask . Json . web_link ) ) ;
267
- if ( commitMentions . Any ( ) )
252
+ if ( references . TryGetValue ( bugTask . Json . web_link , out var reference ) && reference . GitCommits . Any ( ) )
268
253
{
269
254
if ( bugTask . Status < Status . InProgress )
270
255
{
271
256
issues . Add ( "Code was committed but bug is not in progress or fixed" ) ;
272
257
}
273
- var latestCommit = commitMentions . OrderBy ( commit => commit . AuthorDate ) . Last ( ) ;
258
+ var latestCommit = reference . GitCommits . OrderBy ( commit => commit . AuthorDate ) . Last ( ) ;
274
259
if ( ( DateTimeOffset . Now - latestCommit . AuthorDate ) . TotalDays > 28
275
260
&& bugTask . Status < Status . FixCommitted )
276
261
{
@@ -469,7 +454,7 @@ static SortedSet<string> GetBugIdealTags(IConfigurationSection config, string ti
469
454
return tags ;
470
455
}
471
456
472
- static async Task SpecificationTriage ( Launchpad . Project project , IConfigurationSection config , List < Commit > commits )
457
+ static async Task SpecificationTriage ( Launchpad . Project project , IConfigurationSection config , References references )
473
458
{
474
459
Console . WriteLine ( "Specification triage" ) ;
475
460
Console . WriteLine ( "====================" ) ;
@@ -539,8 +524,7 @@ static async Task SpecificationTriage(Launchpad.Project project, IConfigurationS
539
524
{
540
525
issues . Add ( "Implementation is completed but milestone is missing" ) ;
541
526
}
542
- var commitMentions = commits . Where ( commit => commit . References . Contains ( specification . Json . web_link ) ) ;
543
- if ( commitMentions . Any ( ) )
527
+ if ( references . TryGetValue ( specification . Json . web_link , out var reference ) && reference . GitCommits . Any ( ) )
544
528
{
545
529
if ( milestone != null
546
530
&& milestone . Id != config [ "currentMilestone" ] )
@@ -552,7 +536,7 @@ static async Task SpecificationTriage(Launchpad.Project project, IConfigurationS
552
536
{
553
537
issues . Add ( "Code was committed but definition is not approved" ) ;
554
538
}
555
- var latestCommit = commitMentions . OrderBy ( commit => commit . AuthorDate ) . Last ( ) ;
539
+ var latestCommit = reference . GitCommits . OrderBy ( commit => commit . AuthorDate ) . Last ( ) ;
556
540
if ( ( DateTimeOffset . Now - latestCommit . AuthorDate ) . TotalDays > 28
557
541
&& specification . Implementation != Implementation . Implemented )
558
542
{
@@ -602,10 +586,10 @@ static async Task SpecificationApprovals(Launchpad.Project project)
602
586
}
603
587
}
604
588
605
- static async Task TrelloTriage ( Trello . Board board , IConfigurationSection config , List < Commit > commits )
589
+ static async Task TrelloTriage ( Trello . Board board , IConfigurationSection config , References references )
606
590
{
607
- Console . WriteLine ( "Roadmap triage" ) ;
608
- Console . WriteLine ( "============== " ) ;
591
+ Console . WriteLine ( "Trello triage" ) ;
592
+ Console . WriteLine ( "=============" ) ;
609
593
Console . WriteLine ( ) ;
610
594
611
595
var lists = Filter ( await board . GetLists ( ) , list => list . Name , config [ "includeLists" ] , config [ "excludeLists" ] ) ;
@@ -696,7 +680,7 @@ static async Task TrelloTriage(Trello.Board board, IConfigurationSection config,
696
680
var complete = checklist . Items . Find ( item => item . Name == orderName ) ? . Complete ;
697
681
// "https://trello.com/c/JGosmRnZ/159-consist-editor" --> "https://trello.com/c/JGosmRnZ"
698
682
var url = string . Join ( "/" , card . Uri . ToString ( ) . Split ( '/' ) . Take ( 5 ) ) ;
699
- var expectedComplete = commits . Any ( commit => commit . References . Contains ( url ) ) ;
683
+ var expectedComplete = references . TryGetValue ( url , out var reference ) && reference . GitCommits . Any ( ) ;
700
684
if ( complete != expectedComplete )
701
685
{
702
686
Console . WriteLine ( $ " - [{ card . Name } ]({ card . Uri } ): { checklistConfig . Key } checklist item { orderName } is { complete } ; expected { expectedComplete } ") ;
0 commit comments