execute method
Future<bool>
execute(
- ReleasePacker releasePacker,
- Directory rootDirectory, {
- ReleaseBundle? releaseBundle,
override
Implementation
@override
Future<bool> execute(ReleasePacker releasePacker, Directory rootDirectory,
{ReleaseBundle? releaseBundle}) async {
var parameters = this.parameters != null
? Map<String, Object?>.from(this.parameters!)
: null;
Object? body;
if (this.body == '%RELEASE_BUNDLE%') {
if (releaseBundle == null) {
print(' ▒ Release bundle not provided for body: $this');
return false;
} else {
print(' » Using `ReleaseBundle` as body.');
var file = parameters?['file'] as String?;
if (file != null) {
var release = releaseBundle.release;
var fileFormatted = ReleaseBundle.formatReleaseBundleFile(
file, release.name, release.version, release.platform);
parameters!['file'] = fileFormatted;
print(' » Parameter `file`: $fileFormatted');
}
var release = parameters?['release'] as String?;
if (release != null && release.toLowerCase() == '%release%') {
release = releaseBundle.release.toString();
parameters!['release'] = release;
}
}
body = await releaseBundle.toBytes();
} else {
body = this.body;
}
var httpClient = HttpClient(url);
HttpResponse response;
if (body != null) {
print(' » Requesting URL[POS]: $url');
String bodyStr;
if (body is List<int>) {
bodyStr = '${body.length} bytes';
} else {
bodyStr = '<<$body>>';
}
print(' » Body: $bodyStr');
try {
response = await httpClient.post('',
parameters: parameters, authorization: authorization, body: body);
} catch (e) {
print(' ▒ Error requesting: $url > $e');
return false;
}
} else {
print(' » Requesting URL[GET]: $url');
try {
response = await httpClient.get(
'',
parameters: parameters,
authorization: authorization,
);
} catch (e) {
print(' ▒ Error requesting: $url > $e');
return false;
}
}
print(
' » Request response> status: ${response.status} ; body: ${response.bodyAsString}');
return response.isOK;
}