2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'dart:io' ;
6
+
5
7
import 'package:github/github.dart' ;
8
+ import 'package:google_generative_ai/google_generative_ai.dart' ;
6
9
7
10
import 'src/common.dart' ;
8
11
import 'src/gemini.dart' ;
@@ -17,66 +20,85 @@ Future<void> triage(
17
20
bool force = false ,
18
21
required GithubService githubService,
19
22
required GeminiService geminiService,
23
+ required Logger logger,
20
24
}) async {
21
- print ('Triaging $sdkSlug ...' );
22
- print ('' );
25
+ logger. log ('Triaging $sdkSlug ...' );
26
+ logger. log ('' );
23
27
24
28
// retrieve the issue
25
29
final issue = await githubService.fetchIssue (sdkSlug, issueNumber);
26
- print ('## issue ${issue .url }' );
27
- print ('' );
28
- print ('title: ${issue .title }' );
30
+ logger.log ('## issue "${issue .htmlUrl }"' );
31
+ logger.log ('' );
29
32
final labels = issue.labels.map ((l) => l.name).toList ();
30
33
if (labels.isNotEmpty) {
31
- print ('labels: ${labels .join (', ' )}' );
34
+ logger.log ('labels: ${labels .join (', ' )}' );
35
+ logger.log ('' );
32
36
}
37
+ logger.log ('"${issue .title }"' );
38
+ logger.log ('' );
33
39
final bodyLines =
34
40
issue.body.split ('\n ' ).where ((l) => l.trim ().isNotEmpty).toList ();
35
- print ('' );
36
41
for (final line in bodyLines.take (4 )) {
37
- print (' $line ' );
42
+ logger.log (line);
43
+ }
44
+ if (bodyLines.length > 4 ) {
45
+ logger.log ('...' );
38
46
}
39
- print ('' );
47
+ logger. log ('' );
40
48
41
49
// decide if we should triage
42
50
final alreadyTriaged = labels.any ((l) => l.startsWith ('area-' ));
43
51
if (alreadyTriaged && ! force) {
44
- print ('Exiting (issue is already triaged).' );
52
+ logger. log ('Exiting (issue is already triaged).' );
45
53
return ;
46
54
}
47
55
48
56
// ask for the summary
49
57
var bodyTrimmed = trimmedBody (issue.body);
50
- // TODO(devoncarew): handle safety failures
51
- final summary = await geminiService.summarize (
52
- summarizeIssuePrompt (title: issue.title, body: bodyTrimmed),
53
- );
54
- print ('## gemini summary' );
55
- print ('' );
56
- print (summary);
57
- print ('' );
58
+ String summary;
59
+ try {
60
+ // Failures here can include things like gemini safety issues, ...
61
+ summary = await geminiService.summarize (
62
+ summarizeIssuePrompt (title: issue.title, body: bodyTrimmed),
63
+ );
64
+ } on GenerativeAIException catch (e) {
65
+ stderr.writeln ('gemini: $e ' );
66
+ exit (1 );
67
+ }
68
+
69
+ logger.log ('## gemini summary' );
70
+ logger.log ('' );
71
+ logger.log (summary);
72
+ logger.log ('' );
58
73
59
74
// ask for the 'area-' classification
60
- // TODO(devoncarew): handle safety failures
61
- final classification = await geminiService.classify (
62
- assignAreaPrompt (title: issue.title, body: bodyTrimmed),
63
- );
64
- print ('## gemini classification' );
65
- print ('' );
66
- print (classification);
67
- print ('' );
75
+ List <String > classification;
76
+ try {
77
+ // Failures here can include things like gemini safety issues, ...
78
+ classification = await geminiService.classify (
79
+ assignAreaPrompt (title: issue.title, body: bodyTrimmed),
80
+ );
81
+ } on GenerativeAIException catch (e) {
82
+ stderr.writeln ('gemini: $e ' );
83
+ exit (1 );
84
+ }
85
+
86
+ logger.log ('## gemini classification' );
87
+ logger.log ('' );
88
+ logger.log (classification.toString ());
89
+ logger.log ('' );
68
90
69
91
if (dryRun) {
70
- print ('Exiting (dry run mode - not applying changes).' );
92
+ logger. log ('Exiting (dry run mode - not applying changes).' );
71
93
return ;
72
94
}
73
95
74
96
// perform changes
75
- print ('## github comment' );
76
- print ('' );
77
- print (summary);
78
- print ('' );
79
- print ('labels: $classification ' );
97
+ logger. log ('## github comment' );
98
+ logger. log ('' );
99
+ logger. log (summary);
100
+ logger. log ('' );
101
+ logger. log ('labels: $classification ' );
80
102
81
103
var comment = '' ;
82
104
if (classification.isNotEmpty) {
@@ -101,10 +123,10 @@ Future<void> triage(
101
123
await githubService.addLabelsToIssue (sdkSlug, issueNumber, newLabels);
102
124
}
103
125
104
- print ('' );
105
- print ('---' );
106
- print ('' );
107
- print ('Triaged ${issue .url }.' );
126
+ logger. log ('' );
127
+ logger. log ('---' );
128
+ logger. log ('' );
129
+ logger. log ('Triaged ${issue .htmlUrl }.' );
108
130
}
109
131
110
132
List <String > filterExistingLabels (
0 commit comments