Gitea routes: pull request comments, forgejo review states
Browse files at this commit978cff36f32fa797a797ef13c9b5770c05971310Parent: 24f9502- fix
- gitea routes: pull request comments, forgejo review states
2 changed files +22 -6
crates/forge-web/src/api/gitea.rsmodified+14 -5
| @@ -524,7 +524,8 @@ async fn issues_inner(cx: &Cx, state: &AppState, ctx: &Ctx) -> Result<Response, | ||
| 524 | 524 | Ok(page_response(cx, out, total as usize, &pg)) |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | -/// The issue or pull request row with this number. | |
| 527 | +/// The issue row with this number. A pull request is an issue row too, so its comments and | |
| 528 | +/// reactions are found through here as well. | |
| 528 | 529 | async fn issue_row( |
| 529 | 530 | state: &AppState, |
| 530 | 531 | repo: &CoreRepo, |
| @@ -532,7 +533,12 @@ async fn issue_row( | ||
| 532 | 533 | ) -> Result<forge_core::issues::Issue, Refusal> { |
| 533 | 534 | let number: i64 = raw.parse().map_err(|_| bad("invalid issue index"))?; |
| 534 | 535 | match state.store.issue_by_number(&repo.id, number).await { |
| 535 | - Ok(Some(issue)) => Ok(issue), | |
| 536 | + Ok(Some(issue)) => return Ok(issue), | |
| 537 | + Ok(None) => {} | |
| 538 | + Err(e) => return Err(internal(e)), | |
| 539 | + } | |
| 540 | + match state.store.pull_by_number(&repo.id, number).await { | |
| 541 | + Ok(Some(pull)) => Ok(pull.issue), | |
| 536 | 542 | Ok(None) => Err(not_found("issue not found")), |
| 537 | 543 | Err(e) => Err(internal(e)), |
| 538 | 544 | } |
| @@ -829,6 +835,9 @@ async fn list_pulls_route(cx: &Cx) -> topcoat::Result<Response> { | ||
| 829 | 835 | Ok(result.unwrap_or_else(|res| *res)) |
| 830 | 836 | } |
| 831 | 837 | |
| 838 | +/// The review state as Forgejo's uploader reads it (`CHANGES_REQUESTED`, `COMMENTED`). The Go SDK | |
| 839 | +/// names are `REQUEST_CHANGES` and `COMMENT`, which the uploader maps to a pending review, found | |
| 840 | +/// by migrating for real. | |
| 832 | 841 | fn review_state(review: &Review) -> &'static str { |
| 833 | 842 | let effective = if review.state == ReviewState::Dismissed { |
| 834 | 843 | review.dismissed_from.unwrap_or(ReviewState::Commented) |
| @@ -837,9 +846,9 @@ fn review_state(review: &Review) -> &'static str { | ||
| 837 | 846 | }; |
| 838 | 847 | match effective { |
| 839 | 848 | ReviewState::Approved => "APPROVED", |
| 840 | - ReviewState::ChangesRequested => "REQUEST_CHANGES", | |
| 849 | + ReviewState::ChangesRequested => "CHANGES_REQUESTED", | |
| 841 | 850 | ReviewState::Pending => "PENDING", |
| 842 | - ReviewState::Commented | ReviewState::Dismissed => "COMMENT", | |
| 851 | + ReviewState::Commented | ReviewState::Dismissed => "COMMENTED", | |
| 843 | 852 | } |
| 844 | 853 | } |
| 845 | 854 | |
| @@ -856,7 +865,7 @@ fn review_json(ctx: &Ctx, number: i64, review: &Review, comment_count: usize) -> | ||
| 856 | 865 | "body": review.body, |
| 857 | 866 | "commit_id": review.commit_oid, |
| 858 | 867 | "stale": false, |
| 859 | - "official": matches!(review_state(review), "APPROVED" | "REQUEST_CHANGES"), | |
| 868 | + "official": matches!(review_state(review), "APPROVED" | "CHANGES_REQUESTED"), | |
| 860 | 869 | "dismissed": review.state == ReviewState::Dismissed, |
| 861 | 870 | "comments_count": comment_count, |
| 862 | 871 | "submitted_at": review.submitted_at.clone().unwrap_or_else(|| review.created_at.clone()), |
crates/forge-web/src/api/gitea_tests.rsmodified+8 -1
| @@ -443,7 +443,7 @@ async fn pulls_reviews_and_review_comments() { | ||
| 443 | 443 | .await; |
| 444 | 444 | assert_eq!(status, 200); |
| 445 | 445 | let review = &reviews[0]; |
| 446 | - assert_eq!(review["state"], "REQUEST_CHANGES"); | |
| 446 | + assert_eq!(review["state"], "CHANGES_REQUESTED"); | |
| 447 | 447 | assert_eq!(review["body"], "please fix"); |
| 448 | 448 | assert_eq!(review["user"]["login"], "bob"); |
| 449 | 449 | assert_eq!(review["commit_id"], f.oid); |
| @@ -467,6 +467,13 @@ async fn pulls_reviews_and_review_comments() { | ||
| 467 | 467 | assert_eq!(c["user"]["login"], "bob"); |
| 468 | 468 | assert_eq!(c["pull_request_review_id"], review_id); |
| 469 | 469 | |
| 470 | + // A pull request has comments and reactions through the issue routes, as in Gitea. | |
| 471 | + let (status, _, comments) = f.get(&repo_path_of("/issues/2/comments")).await; | |
| 472 | + assert_eq!(status, 200); | |
| 473 | + assert_eq!(comments.as_array().unwrap().len(), 0); | |
| 474 | + let (status, _, _) = f.get(&repo_path_of("/issues/2/reactions")).await; | |
| 475 | + assert_eq!(status, 200); | |
| 476 | + | |
| 470 | 477 | // An issue number is not a pull request. |
| 471 | 478 | let (status, _, _) = f.get(&repo_path_of("/pulls/1/reviews")).await; |
| 472 | 479 | assert_eq!(status, 404); |