-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional filter params on Repositories.listCommits (#368)
* Add optional filter params on Repositories.listCommits * dart format --------- Co-authored-by: Rob Becker <[email protected]>
- Loading branch information
1 parent
87babe4
commit 4986ac1
Showing
3 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const String listCommits = ''' | ||
[ | ||
{ | ||
"sha": "3771b3c9ab1912d32a0d0baffaf489d561caf558", | ||
"node_id": "C_kwDOAVT0d9oAKDM3NzFiM2M5YWIxOTEyZDMyYTBkMGJhZmZhZjQ4OWQ1NjFjYWY1NTg", | ||
"commit": { | ||
"author": { | ||
"name": "Rob Becker", | ||
"email": "[email protected]", | ||
"date": "2023-04-17T14:55:14Z" | ||
}, | ||
"committer": { | ||
"name": "Rob Becker", | ||
"email": "[email protected]", | ||
"date": "2023-04-17T14:55:14Z" | ||
}, | ||
"message": "prep 9.12.0", | ||
"tree": { | ||
"sha": "282532b41e8fead81ec6d68e7e603139e7dd7581", | ||
"url": "https://api.github.com/repos/SpinlockLabs/github.dart/git/trees/282532b41e8fead81ec6d68e7e603139e7dd7581" | ||
}, | ||
"url": "https://api.github.com/repos/SpinlockLabs/github.dart/git/commits/3771b3c9ab1912d32a0d0baffaf489d561caf558", | ||
"comment_count": 0, | ||
"verification": { | ||
"verified": true, | ||
"reason": "valid" | ||
} | ||
}, | ||
"url": "https://api.github.com/repos/SpinlockLabs/github.dart/commits/3771b3c9ab1912d32a0d0baffaf489d561caf558", | ||
"html_url": "https://github.com/SpinlockLabs/github.dart/commit/3771b3c9ab1912d32a0d0baffaf489d561caf558", | ||
"comments_url": "https://api.github.com/repos/SpinlockLabs/github.dart/commits/3771b3c9ab1912d32a0d0baffaf489d561caf558/comments", | ||
"author": { | ||
"login": "robbecker-wf", | ||
"id": 6053699, | ||
"node_id": "MDQ6VXNlcjYwNTM2OTk=", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/6053699?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/robbecker-wf", | ||
"html_url": "https://github.com/robbecker-wf", | ||
"followers_url": "https://api.github.com/users/robbecker-wf/followers", | ||
"following_url": "https://api.github.com/users/robbecker-wf/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/robbecker-wf/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/robbecker-wf/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/robbecker-wf/subscriptions", | ||
"organizations_url": "https://api.github.com/users/robbecker-wf/orgs", | ||
"repos_url": "https://api.github.com/users/robbecker-wf/repos", | ||
"events_url": "https://api.github.com/users/robbecker-wf/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/robbecker-wf/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"committer": { | ||
"login": "robbecker-wf", | ||
"id": 6053699, | ||
"node_id": "MDQ6VXNlcjYwNTM2OTk=", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/6053699?v=4", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/robbecker-wf", | ||
"html_url": "https://github.com/robbecker-wf", | ||
"followers_url": "https://api.github.com/users/robbecker-wf/followers", | ||
"following_url": "https://api.github.com/users/robbecker-wf/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/robbecker-wf/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/robbecker-wf/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/robbecker-wf/subscriptions", | ||
"organizations_url": "https://api.github.com/users/robbecker-wf/orgs", | ||
"repos_url": "https://api.github.com/users/robbecker-wf/repos", | ||
"events_url": "https://api.github.com/users/robbecker-wf/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/robbecker-wf/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"parents": [ | ||
{ | ||
"sha": "a3081681da68383d9a5f18ef3502f47f7144e7d8", | ||
"url": "https://api.github.com/repos/SpinlockLabs/github.dart/commits/a3081681da68383d9a5f18ef3502f47f7144e7d8", | ||
"html_url": "https://github.com/SpinlockLabs/github.dart/commit/a3081681da68383d9a5f18ef3502f47f7144e7d8" | ||
} | ||
] | ||
} | ||
] | ||
'''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:github/src/common.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:http/testing.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'data/repos_json.dart'; | ||
|
||
void main() { | ||
final slug = RepositorySlug('SpinlockLabs', 'github.dart'); | ||
RepositoriesService create(Future<Response> Function(Request) f) { | ||
final client = MockClient(f); | ||
final github = GitHub(client: client); | ||
return RepositoriesService(github); | ||
} | ||
|
||
test('listCommits', () async { | ||
final repositories = create((request) async { | ||
expect(request.url.path, '/repos/${slug.fullName}/commits'); | ||
expect(request.url.query, 'page=1'); | ||
|
||
return Response(listCommits, StatusCodes.OK); | ||
}); | ||
final commits = await repositories.listCommits(slug).toList(); | ||
expect(commits, hasLength(1)); | ||
}); | ||
|
||
test('listCommits with query params', () async { | ||
final repositories = create((request) async { | ||
expect(request.url.path, '/repos/${slug.fullName}/commits'); | ||
expect( | ||
request.url.query, | ||
'author=octocat&committer=octodog&sha=abc&path=%2Fpath&since=2022-02-22T00%3A00%3A00.000&until=2023-02-22T00%3A00%3A00.000&page=1', | ||
); | ||
return Response(listCommits, StatusCodes.OK); | ||
}); | ||
final commits = await repositories | ||
.listCommits( | ||
slug, | ||
sha: 'abc', | ||
path: '/path', | ||
author: 'octocat', | ||
committer: 'octodog', | ||
since: DateTime(2022, 2, 22), | ||
until: DateTime(2023, 2, 22), | ||
) | ||
.toList(); | ||
expect(commits, hasLength(1)); | ||
}); | ||
} |