@@ -17,20 +17,23 @@ import 'dart:io';
17
17
import 'package:args/args.dart' ;
18
18
import 'package:http/http.dart' as http;
19
19
20
- void usage (ArgParser parser) {
20
+ void usage (ArgParser parser, {exitCode = 0 } ) {
21
21
print ('''
22
22
Usage: post_results_to_pubsub.dart [OPTIONS]
23
23
Posts Dart CI results as messages to Google Cloud Pub/Sub
24
24
25
25
The options are as follows:
26
26
27
27
${parser .usage }''' );
28
- exit (1 );
28
+ exit (exitCode );
29
29
}
30
30
31
31
const resultsPerMessage = 100 ;
32
- const postUrl =
33
- 'https://pubsub.googleapis.com/v1/projects/dart-ci/topics/results:publish' ;
32
+
33
+ String getPostUrl (String project) {
34
+ return 'https://pubsub.googleapis.com/v1/projects/$project '
35
+ '/topics/results:publish' ;
36
+ }
34
37
35
38
main (List <String > args) async {
36
39
final parser = new ArgParser ();
@@ -42,12 +45,26 @@ main(List<String> args) async {
42
45
abbr: 'f' , help: 'File containing the results to send' );
43
46
parser.addOption ('id' , abbr: 'i' , help: 'Buildbucket ID of this build' );
44
47
parser.addOption ('base_revision' , help: 'A try build\' s patch base' );
48
+ parser.addFlag ('staging' ,
49
+ abbr: 's' , help: 'Publish to the staging system' , defaultsTo: false );
45
50
46
51
final options = parser.parse (args);
47
52
if (options['help' ]) {
48
53
usage (parser);
49
54
}
50
55
56
+ if (options['result_file' ] == null ) {
57
+ print ('Error: option "result_file" is required.\n ' );
58
+ usage (parser, exitCode: 1 );
59
+ }
60
+
61
+ if (options['auth_token' ] == null ) {
62
+ print ('Error: option "auth_token" is required.\n ' );
63
+ usage (parser, exitCode: 1 );
64
+ }
65
+
66
+ final project = options['staging' ] ? "dart-ci-staging" : "dart-ci" ;
67
+
51
68
final client = http.Client ();
52
69
53
70
final lines = await File (options['result_file' ]).readAsLines ();
@@ -59,6 +76,8 @@ main(List<String> args) async {
59
76
return ;
60
77
}
61
78
79
+ // TODO(karlklose): parse and validate data before sending it.
80
+
62
81
final changedPattern = '"changed":true' ;
63
82
List <String > changedResults =
64
83
lines.where ((change) => change.contains (changedPattern)).toList ();
@@ -95,6 +114,7 @@ main(List<String> args) async {
95
114
]
96
115
});
97
116
final headers = {'Authorization' : 'Bearer $token ' };
117
+ final postUrl = getPostUrl (project);
98
118
final response =
99
119
await client.post (postUrl, headers: headers, body: jsonMessage);
100
120
0 commit comments