-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployments_api.dart
More file actions
52 lines (47 loc) · 1.45 KB
/
deployments_api.dart
File metadata and controls
52 lines (47 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'dart:convert';
import 'package:http/http.dart' as http;
/// Creates a deployment in Raygun.
Future<bool> createDeployment({
required String token,
required String apiKey,
required String version,
String? ownerName,
String? emailAddress,
String? comment,
String? scmIdentifier,
String? scmType,
}) async {
final url =
'https://api.raygun.com/v3/applications/api-key/$apiKey/deployments';
final payload = {
'version': version,
if (ownerName != null) 'ownerName': ownerName,
if (emailAddress != null) 'emailAddress': emailAddress,
if (comment != null) 'comment': comment,
if (scmIdentifier != null) 'scmIdentifier': scmIdentifier,
if (scmType != null) 'scmType': scmType,
'deployedAt': DateTime.now().toUtc().toIso8601String(),
};
try {
final response = await http.post(
Uri.parse(url),
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);
if (response.statusCode == 200 || response.statusCode == 201) {
print('Success creating deployment: ${response.statusCode}');
print(
'Deployment identifier: ${jsonDecode(response.body)['identifier']}');
return true;
}
print('Error creating deployment: ${response.statusCode}');
print('Response: ${response.body}');
return false;
} catch (e) {
print('Exception while creating deployment: $e');
return false;
}
}