Skip to content

Commit

Permalink
Merge pull request #155 from netglade/fix/dcm-ci
Browse files Browse the repository at this point in the history
Use oss for DCM in CI
  • Loading branch information
tenhobi authored Nov 14, 2023
2 parents 53c5006 + 3428ace commit 0807f4b
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
uses: CQLabs/dcm-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
ci_key: ${{ secrets.DCM_KEY }}
email: ${{ secrets.DCM_EMAIL }}
ci_key: oss
email: oss
folders: .
fatal_style: true
fatal_performance: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ abstract class AssignmentBuilderBase {
final TypeMapping mapping;
final void Function(TypeMapping? mapping)? usedNullableMethodCallback;

static const Reference modelReference = Reference('model');

const AssignmentBuilderBase({
required this.assignment,
required this.mapperConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IterableAssignmentBuilder extends AssignmentBuilderBase with NestedObjectM
(!targetIterableType.isSame(sourceIterableType));

// When [sourceIterableType] is nullable and [targetIterableType] is not, remove null values.
final sourceIterableExpression = refer('model').property(assignment.sourceField!.name).maybeWhereIterableNotNull(
final sourceIterableExpression = AssignmentBuilderBase.modelReference.property(assignment.sourceField!.name).maybeWhereIterableNotNull(
condition: shouldFilterNullInSource,
isOnNullable: sourceNullable,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MapAssignmentBuilder extends AssignmentBuilderBase with NestedObjectMixin
final shouldRemoveNullsValue =
sourceNullableValue && !targetNullableValue && (!(valueMapping?.hasWhenNullDefault() ?? false));

final sourceMapExpression = refer('model').property(assignment.sourceField!.name);
final sourceMapExpression = AssignmentBuilderBase.modelReference.property(assignment.sourceField!.name);

final defaultMapValueExpression = literalMap(
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mixin NestedObjectMixin on AssignmentBuilderBase {
Expression? convertMethodArgument,
bool includeGenericTypes = false,
}) {
final sourceOnModel = refer('model').property(assignment.sourceField!.displayName);
final sourceOnModel = AssignmentBuilderBase.modelReference.property(assignment.sourceField!.displayName);

// Source and target is the same.
if (source.isSame(target)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
);
}

final targetClassGetters = (mapping.target).getAllGetters();
final targetClassGetters = mapping.target.getAllGetters();

// Map constructor parameters
for (var i = 0; i < targetConstructor.parameters.length; i++) {
Expand Down Expand Up @@ -151,8 +151,7 @@ class ClassBodyBuilder extends MapBodyBuilderBase {
// If not mapped constructor param is optional - skip it
if (param.isOptional) continue;

final targetField =
(mapping.target).getAllGetters().firstWhereOrNull((field) => field.displayName == param.displayName);
final targetField = targetClassGetters.firstWhereOrNull((field) => field.displayName == param.displayName);

if (targetField == null && fieldMapping == null) {
throw InvalidGenerationSourceError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class ConvertIterableMethodBuilder extends MethodBuilderBase {
// for List/Set:
// convertIterable<SOURCE, TARGET>(model).toList()
final convertIterableCall = iterableTransformer == null
? refer('model')
? MethodBuilderBase.modelReference
.property('map')
.call([refer('(item) => _convert(item)').nullChecked], {}, [MethodBuilderBase.targetTypeReference])
: refer('convertIterable')
.call([refer('model')], {}, [MethodBuilderBase.sourceTypeReference, MethodBuilderBase.targetTypeReference])
.call([MethodBuilderBase.modelReference], {}, [MethodBuilderBase.sourceTypeReference, MethodBuilderBase.targetTypeReference])
.property(iterableTransformer!)
.call([]);

Expand All @@ -80,13 +80,14 @@ class ConvertIterableMethodBuilder extends MethodBuilderBase {
// return mappr.convertIterable(model)!;
// }
// }
final mapprReference = refer('mappr');
block.statements.add(
ExpressionExtension.forStatement(
item: refer('mappr'),
item: mapprReference,
iterable: refer(MethodBuilderBase.delegatesField),
body: ExpressionExtension.ifStatement(
condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')),
ifBody: refer('mappr').property('convert$wrapper').call([refer('model')], {}, []).returned.statement,
condition: CanConvertMethodBuilder(config).propertyCall(on: mapprReference),
ifBody: mapprReference.property('convert$wrapper').call([MethodBuilderBase.modelReference], {}, []).returned.statement,
),
).code,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConvertMethodBuilder extends MethodBuilderBase {
block.statements.add(
ExpressionExtension.ifStatement(
condition: CanConvertMethodBuilder(config).methodCall(namedArguments: {'recursive': literalFalse}),
ifBody: refer('_convert').call([refer('model')], {}, []).nullChecked.returned.statement,
ifBody: refer('_convert').call([MethodBuilderBase.modelReference], {}, []).nullChecked.returned.statement,
).code,
);

Expand All @@ -53,13 +53,14 @@ class ConvertMethodBuilder extends MethodBuilderBase {
// return mappr.convert(model)!;
// }
// }
final mapprReference = refer('mappr');
block.statements.add(
ExpressionExtension.forStatement(
item: refer('mappr'),
item: mapprReference,
iterable: refer(MethodBuilderBase.delegatesField),
body: ExpressionExtension.ifStatement(
condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')),
ifBody: refer('mappr').property('convert').call([refer('model')], {}, []).nullChecked.returned.statement,
condition: CanConvertMethodBuilder(config).propertyCall(on: mapprReference),
ifBody: mapprReference.property('convert').call([MethodBuilderBase.modelReference], {}, []).nullChecked.returned.statement,
),
).code,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class MethodBuilderBase {
static const nullableTargetTypeReference = Reference('$targetKey?');
static const targetTypeOf = Reference('_typeOf<$targetKey>()');

static const modelReference = Reference('model');

static final ListBuilder<Reference> overrideAnnotation = ListBuilder([const Reference('override')]);

final AutoMapprConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PrivateConvertMethodBuilder extends MethodBuilderBase {
block.addExpression(targetTypeOfVariable);

for (final mapping in config.mappers) {
final ifCheckForNull = refer('canReturnNull').and(refer('model').equalToNull()).ifStatement2(
final ifCheckForNull = refer('canReturnNull').and(MethodBuilderBase.modelReference.equalToNull()).ifStatement2(
ifBody: mapping.hasWhenNullDefault()
? mapping.whenSourceIsNullExpression!.asA(MethodBuilderBase.targetTypeReference).returned.statement
: literalNull.returned.statement,
Expand Down Expand Up @@ -74,7 +74,7 @@ class PrivateConvertMethodBuilder extends MethodBuilderBase {
refer(mapping.mappingMethodName(config: config))
.call(
[
refer('model').asA(EmitterHelper.current.typeRefer(type: mapping.source).nullabled()),
MethodBuilderBase.modelReference.asA(EmitterHelper.current.typeRefer(type: mapping.source).nullabled()),
],
)
.asA(MethodBuilderBase.targetTypeReference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class TryConvertIterableMethodBuilder extends MethodBuilderBase {
// for List/Set:
// tryConvertIterable<SOURCE, TARGET>(model).toList()
final convertIterableCall = iterableTransformer == null
? refer('model').property('map').call(
? MethodBuilderBase.modelReference.property('map').call(
[refer('(item) => _convert(item, canReturnNull: true)')],
{},
[MethodBuilderBase.nullableTargetTypeReference],
)
: refer('tryConvertIterable')
.call(
[refer('model')],
[MethodBuilderBase.modelReference],
{},
[MethodBuilderBase.sourceTypeReference, MethodBuilderBase.targetTypeReference],
)
Expand All @@ -90,13 +90,14 @@ class TryConvertIterableMethodBuilder extends MethodBuilderBase {
// return mappr.tryConvertIterable(model)!;
// }
// }
final mapprReference = refer('mappr');
block.statements.add(
ExpressionExtension.forStatement(
item: refer('mappr'),
item: mapprReference,
iterable: refer(MethodBuilderBase.delegatesField),
body: ExpressionExtension.ifStatement(
condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')),
ifBody: refer('mappr').property('tryConvert$wrapper').call([refer('model')], {}, []).returned.statement,
condition: CanConvertMethodBuilder(config).propertyCall(on: mapprReference),
ifBody: mapprReference.property('tryConvert$wrapper').call([MethodBuilderBase.modelReference], {}, []).returned.statement,
),
).code,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ class TryConvertMethodBuilder extends MethodBuilderBase {
// return mappr.convert(model)!;
// }
// }
final mapprReference = refer('mappr');
block.statements.add(
ExpressionExtension.forStatement(
item: refer('mappr'),
item: mapprReference,
iterable: refer(MethodBuilderBase.delegatesField),
body: ExpressionExtension.ifStatement(
condition: CanConvertMethodBuilder(config).propertyCall(on: refer('mappr')),
ifBody: refer('mappr').property('tryConvert').call([refer('model')], {}, []).returned.statement,
condition: CanConvertMethodBuilder(config).propertyCall(on: mapprReference),
ifBody: mapprReference.property('tryConvert').call([MethodBuilderBase.modelReference], {}, []).returned.statement,
),
).code,
);
Expand Down

0 comments on commit 0807f4b

Please sign in to comment.