send method
Future<NotificationResult>
send(
- NotificationPayload payload, {
- required Map<
String, String> environment, - bool dryRun = false,
override
Dispatches payload to the destination. Network calls MUST be skipped if dryRun is true.
Implementation
@override
Future<NotificationResult> send(
NotificationPayload payload, {
required Map<String, String> environment,
bool dryRun = false,
}) async {
final stopwatch = Stopwatch()..start();
final summaryFile = environment['GITHUB_STEP_SUMMARY'];
if (summaryFile != null && summaryFile.isNotEmpty) {
final markdown =
'### 🚀 ${payload.title}\n\n```text\n${payload.message}\n```\n';
if (!dryRun) {
try {
final file = File(summaryFile);
await file.writeAsString(markdown, mode: FileMode.append);
} catch (_) {}
}
}
final token = environment['GITHUB_TOKEN'];
final repo = environment['GITHUB_REPOSITORY'];
final sha = payload.event.commit;
if (token != null &&
token.isNotEmpty &&
repo != null &&
repo.isNotEmpty &&
sha != null &&
sha.isNotEmpty) {
final state = payload.severity == NotificationSeverity.success
? 'success'
: (payload.severity == NotificationSeverity.error
? 'failure'
: 'pending');
final url = 'https://api.github.com/repos/$repo/statuses/$sha';
final headers = {
'Authorization': 'Bearer $token',
'Accept': 'application/vnd.github+json',
'User-Agent': 'flutter_setup-cli',
};
final response = await _client.postJson(
url,
jsonPayload: {
'state': state,
'description': payload.title,
'context': 'flutter_setup/release',
},
headers: headers,
dryRun: dryRun,
);
stopwatch.stop();
return NotificationResult.success(
name,
statusCode: response.statusCode,
durationMs: stopwatch.elapsedMilliseconds,
);
}
stopwatch.stop();
return NotificationResult.success(
name,
statusCode: 200,
durationMs: stopwatch.elapsedMilliseconds,
);
}