feat: add gitea API client and DTO bundle fetch
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
use gitea_pr_review::gitea::client::GiteaClient;
|
||||
use mockito::Server;
|
||||
|
||||
#[test]
|
||||
fn fetch_bundle_hits_required_endpoints_and_aggregates_review_comments() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _pull = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body(
|
||||
r#"{
|
||||
"number": 42,
|
||||
"title": "Fix parser",
|
||||
"state": "open",
|
||||
"body": "desc",
|
||||
"user": {"login": "alice"},
|
||||
"base": {"ref": "main"},
|
||||
"head": {"ref": "feature/x"},
|
||||
"created_at": "2026-04-08T10:00:00Z",
|
||||
"updated_at": "2026-04-08T11:00:00Z",
|
||||
"merged_at": null,
|
||||
"additions": 12,
|
||||
"deletions": 3,
|
||||
"changed_files": 2
|
||||
}"#,
|
||||
)
|
||||
.create();
|
||||
|
||||
let _reviews = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42/reviews")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body(
|
||||
r#"[
|
||||
{
|
||||
"id": 7,
|
||||
"state": "COMMENT",
|
||||
"user": {"login": "bob"},
|
||||
"submitted_at": "2026-04-08T12:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"state": "APPROVED",
|
||||
"user": {"login": "carol"},
|
||||
"submitted_at": "2026-04-08T13:00:00Z"
|
||||
}
|
||||
]"#,
|
||||
)
|
||||
.create();
|
||||
|
||||
let _review_7_comments = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42/reviews/7/comments")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body(
|
||||
r#"[
|
||||
{
|
||||
"id": 71,
|
||||
"body": "first comment",
|
||||
"created_at": "2026-04-08T12:01:00Z",
|
||||
"updated_at": "2026-04-08T12:02:00Z",
|
||||
"user": {"login": "bob"},
|
||||
"path": "src/main.rs",
|
||||
"line": 10,
|
||||
"pull_request_review_id": 7,
|
||||
"original_position": 10,
|
||||
"position": 10,
|
||||
"commit_id": "abc123",
|
||||
"original_commit_id": "abc123",
|
||||
"diff_hunk": "@@ -1 +1 @@"
|
||||
}
|
||||
]"#,
|
||||
)
|
||||
.create();
|
||||
|
||||
let _review_8_comments = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42/reviews/8/comments")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body("[]")
|
||||
.create();
|
||||
|
||||
let _commits = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42/commits")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body(
|
||||
r#"[
|
||||
{
|
||||
"sha": "abcdef1234567890",
|
||||
"commit": {
|
||||
"message": "feat: parser\n\nbody",
|
||||
"author": {
|
||||
"name": "Alice",
|
||||
"date": "2026-04-08T10:10:00Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
]"#,
|
||||
)
|
||||
.create();
|
||||
|
||||
let _files = server
|
||||
.mock("GET", "/api/v1/repos/org/repo/pulls/42/files")
|
||||
.match_header("authorization", "token secret")
|
||||
.with_status(200)
|
||||
.with_body(
|
||||
r#"[
|
||||
{
|
||||
"filename": "src/main.rs",
|
||||
"additions": 12,
|
||||
"deletions": 3,
|
||||
"changes": 15,
|
||||
"status": "modified",
|
||||
"previous_filename": null
|
||||
}
|
||||
]"#,
|
||||
)
|
||||
.create();
|
||||
|
||||
let client = GiteaClient::new(server.url(), "secret".to_string());
|
||||
let bundle = client.fetch_pr_bundle("org/repo", 42).unwrap();
|
||||
|
||||
assert_eq!(bundle.pull.number, 42);
|
||||
assert_eq!(bundle.pull.title, "Fix parser");
|
||||
assert_eq!(bundle.reviews.len(), 2);
|
||||
assert_eq!(bundle.comments.len(), 1);
|
||||
assert_eq!(bundle.comments[0].pull_request_review_id, Some(7));
|
||||
assert_eq!(bundle.commits.len(), 1);
|
||||
assert_eq!(bundle.files.len(), 1);
|
||||
|
||||
_pull.assert();
|
||||
_reviews.assert();
|
||||
_review_7_comments.assert();
|
||||
_review_8_comments.assert();
|
||||
_commits.assert();
|
||||
_files.assert();
|
||||
}
|
||||
Reference in New Issue
Block a user