File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class GitHub {
21
21
GitHub ({
22
22
Authentication ? auth,
23
23
this .endpoint = 'https://api.github.com' ,
24
+ this .version = '2022-11-28' ,
24
25
http.Client ? client,
25
26
}) : auth = auth ?? Authentication .anonymous (),
26
27
client = client ?? http.Client ();
@@ -29,12 +30,24 @@ class GitHub {
29
30
static const _ratelimitResetHeader = 'x-ratelimit-reset' ;
30
31
static const _ratelimitRemainingHeader = 'x-ratelimit-remaining' ;
31
32
33
+ @visibleForTesting
34
+ static const versionHeader = 'X-GitHub-Api-Version' ;
35
+
32
36
/// Authentication Information
33
37
Authentication ? auth;
34
38
35
39
/// API Endpoint
36
40
final String endpoint;
37
41
42
+ /// Calendar version of the GitHub API to use.
43
+ ///
44
+ /// Changing this value is unsupported. However, it may unblock you if there's
45
+ /// hotfix versions.
46
+ ///
47
+ /// See also:
48
+ /// * https://docs.github.com/en/rest/overview/api-versions?apiVersion=2022-11-28
49
+ final String version;
50
+
38
51
/// HTTP Client
39
52
final http.Client client;
40
53
@@ -306,6 +319,7 @@ class GitHub {
306
319
}
307
320
308
321
headers.putIfAbsent ('Accept' , () => v3ApiMimeType);
322
+ headers.putIfAbsent (versionHeader, () => version);
309
323
310
324
final response = await request (
311
325
method,
Original file line number Diff line number Diff line change
1
+ import 'dart:io' ;
2
+
3
+ import 'package:github/src/common/github.dart' ;
4
+ import 'package:http/http.dart' ;
5
+ import 'package:http/testing.dart' ;
6
+ import 'package:test/test.dart' ;
7
+
8
+ void main () {
9
+ group (GitHub , () {
10
+ test ('passes calendar version header' , () async {
11
+ Request ? request;
12
+ final client = MockClient ((r) async {
13
+ request = r;
14
+ return Response ('{}' , HttpStatus .ok);
15
+ });
16
+
17
+ final github = GitHub (client: client);
18
+ await github.getJSON ('' ); // Make HTTP request
19
+
20
+ expect (request, isNotNull);
21
+ expect (request! .headers.containsKey (GitHub .versionHeader), isTrue);
22
+ final version = request! .headers[GitHub .versionHeader];
23
+ expect (version, github.version);
24
+ });
25
+ });
26
+ }
You can’t perform that action at this time.
0 commit comments