55import 'package:json_annotation/json_annotation.dart' ;
66import 'package:path/path.dart' as p;
77
8+ import 'basic_config.dart' ;
9+ import 'coverage_processor.dart' ;
810import 'github_config.dart' ;
911import 'yaml.dart' ;
1012
@@ -18,6 +20,7 @@ const _allowedMonoConfigKeys = {
1820 'pretty_ansi' ,
1921 'pub_action' ,
2022 'self_validate' ,
23+ 'coverage_service' ,
2124};
2225
2326const _defaultPubAction = 'upgrade' ;
@@ -27,41 +30,25 @@ const _allowedPubActions = {
2730 _defaultPubAction,
2831};
2932
30- class MonoConfig {
33+ class MonoConfig implements BasicConfiguration {
3134 final Map <String , ConditionalStage > githubConditionalStages;
3235 final Set <String > mergeStages;
3336 final bool prettyAnsi;
3437 final String pubAction;
3538 final String ? selfValidateStage;
3639 final GitHubConfig github;
37-
38- factory MonoConfig ({
39- required Set <String > mergeStages,
40- required bool prettyAnsi,
41- required String pubAction,
42- required String ? selfValidateStage,
43- required Map github,
44- }) {
45- final githubConditionalStages = _readConditionalStages (github);
46-
47- return MonoConfig ._(
48- githubConditionalStages: githubConditionalStages,
49- mergeStages: mergeStages,
50- prettyAnsi: prettyAnsi,
51- pubAction: pubAction,
52- selfValidateStage: selfValidateStage,
53- github: GitHubConfig .fromJson (github),
54- );
55- }
40+ @override
41+ final Set <CoverageProcessor > coverageProcessors;
5642
5743 MonoConfig ._({
58- required this .githubConditionalStages,
5944 required this .mergeStages,
6045 required this .prettyAnsi,
6146 required this .pubAction,
6247 required this .selfValidateStage,
63- required this .github,
64- });
48+ required Map github,
49+ required this .coverageProcessors,
50+ }) : githubConditionalStages = _readConditionalStages (github),
51+ github = GitHubConfig .fromJson (github);
6552
6653 factory MonoConfig .fromJson (Map json) {
6754 final unsupportedKeys =
@@ -135,53 +122,63 @@ class MonoConfig {
135122 );
136123 }
137124
138- final mergeStages = json[ 'merge_stages' ] ?? [] ;
125+ final mergeStages = _asList ( json, 'merge_stages' ) ;
139126
140- if (mergeStages is List ) {
141- if (mergeStages.any ((v) => v is ! String )) {
142- throw CheckedFromJsonException (
143- json,
144- 'merge_stages' ,
145- 'MonoConfig' ,
146- 'All values must be strings.' ,
147- );
148- }
127+ final coverageServices = _asList (json, 'coverage_service' );
149128
150- return MonoConfig (
151- mergeStages: Set .from (mergeStages),
152- prettyAnsi: prettyAnsi,
153- pubAction: pubAction,
154- selfValidateStage: _selfValidateFromValue (selfValidate),
155- github: github,
156- );
157- } else {
158- throw CheckedFromJsonException (
159- json,
160- 'merge_stages' ,
161- 'MonoConfig' ,
162- '`merge_stages` must be an array.' ,
163- );
164- }
129+ return MonoConfig ._(
130+ mergeStages: Set .from (mergeStages),
131+ prettyAnsi: prettyAnsi,
132+ pubAction: pubAction,
133+ selfValidateStage: _selfValidateFromValue (selfValidate),
134+ github: github,
135+ coverageProcessors: coverageServices
136+ .map ((e) => CoverageProcessor .values.byName (e))
137+ .toSet (),
138+ );
165139 }
166140
167141 factory MonoConfig .fromRepo ({String ? rootDirectory}) {
168142 rootDirectory ?? = p.current;
169143
170144 final yaml = yamlMapOrNull (rootDirectory, _monoConfigFileName);
171145 if (yaml == null || yaml.isEmpty) {
172- return MonoConfig (
146+ return MonoConfig ._ (
173147 mergeStages: < String > {},
174148 pubAction: _defaultPubAction,
175149 prettyAnsi: true ,
176150 selfValidateStage: null ,
177151 github: {},
152+ coverageProcessors: {CoverageProcessor .coveralls},
178153 );
179154 }
180155
181156 return createWithCheck (() => MonoConfig .fromJson (yaml));
182157 }
183158}
184159
160+ List <String > _asList (Map json, String key) {
161+ final value = json[key] ?? < String > [];
162+
163+ if (value is List ) {
164+ if (value.any ((v) => v is ! String )) {
165+ throw CheckedFromJsonException (
166+ json,
167+ key,
168+ 'MonoConfig' ,
169+ 'All values must be strings.' ,
170+ );
171+ }
172+ return List .from (value);
173+ }
174+ throw CheckedFromJsonException (
175+ json,
176+ key,
177+ 'MonoConfig' ,
178+ '`$key ` must be an array.' ,
179+ );
180+ }
181+
185182/// Parses the `stages` key from a CI config map, into a Map from stage name
186183/// to [ConditionalStage] instance.
187184Map <String , ConditionalStage > _readConditionalStages (
0 commit comments