Skip to content

Commit e9230e6

Browse files
author
Casey Hillers
authored
Add calendar versioning (#338)
Add calendar version
1 parent 11544fc commit e9230e6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/src/common/github.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GitHub {
2121
GitHub({
2222
Authentication? auth,
2323
this.endpoint = 'https://api.github.com',
24+
this.version = '2022-11-28',
2425
http.Client? client,
2526
}) : auth = auth ?? Authentication.anonymous(),
2627
client = client ?? http.Client();
@@ -29,12 +30,24 @@ class GitHub {
2930
static const _ratelimitResetHeader = 'x-ratelimit-reset';
3031
static const _ratelimitRemainingHeader = 'x-ratelimit-remaining';
3132

33+
@visibleForTesting
34+
static const versionHeader = 'X-GitHub-Api-Version';
35+
3236
/// Authentication Information
3337
Authentication? auth;
3438

3539
/// API Endpoint
3640
final String endpoint;
3741

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+
3851
/// HTTP Client
3952
final http.Client client;
4053

@@ -306,6 +319,7 @@ class GitHub {
306319
}
307320

308321
headers.putIfAbsent('Accept', () => v3ApiMimeType);
322+
headers.putIfAbsent(versionHeader, () => version);
309323

310324
final response = await request(
311325
method,

test/common/github_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)