forge
Explore
Log in

Don't you dare go Hollow

Gitea routes: pull request comments, forgejo review states

Browse files at this commit

978cff36f32fa797a797ef13c9b5770c05971310Ahmet Kaan GümüşParent: 24f9502
  • fix
    • gitea routes: pull request comments, forgejo review states
Show full message
🐛 fix: gitea routes: pull request comments, forgejo review states
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,
524524 Ok(page_response(cx, out, total as usize, &pg))
525525 }
526526
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.
528529 async fn issue_row(
529530 state: &AppState,
530531 repo: &CoreRepo,
@@ -532,7 +533,12 @@ async fn issue_row(
532533 ) -> Result<forge_core::issues::Issue, Refusal> {
533534 let number: i64 = raw.parse().map_err(|_| bad("invalid issue index"))?;
534535 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),
536542 Ok(None) => Err(not_found("issue not found")),
537543 Err(e) => Err(internal(e)),
538544 }
@@ -829,6 +835,9 @@ async fn list_pulls_route(cx: &Cx) -> topcoat::Result<Response> {
829835 Ok(result.unwrap_or_else(|res| *res))
830836 }
831837
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.
832841 fn review_state(review: &Review) -> &'static str {
833842 let effective = if review.state == ReviewState::Dismissed {
834843 review.dismissed_from.unwrap_or(ReviewState::Commented)
@@ -837,9 +846,9 @@ fn review_state(review: &Review) -> &'static str {
837846 };
838847 match effective {
839848 ReviewState::Approved => "APPROVED",
840- ReviewState::ChangesRequested => "REQUEST_CHANGES",
849+ ReviewState::ChangesRequested => "CHANGES_REQUESTED",
841850 ReviewState::Pending => "PENDING",
842- ReviewState::Commented | ReviewState::Dismissed => "COMMENT",
851+ ReviewState::Commented | ReviewState::Dismissed => "COMMENTED",
843852 }
844853 }
845854
@@ -856,7 +865,7 @@ fn review_json(ctx: &Ctx, number: i64, review: &Review, comment_count: usize) ->
856865 "body": review.body,
857866 "commit_id": review.commit_oid,
858867 "stale": false,
859- "official": matches!(review_state(review), "APPROVED" | "REQUEST_CHANGES"),
868+ "official": matches!(review_state(review), "APPROVED" | "CHANGES_REQUESTED"),
860869 "dismissed": review.state == ReviewState::Dismissed,
861870 "comments_count": comment_count,
862871 "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() {
443443 .await;
444444 assert_eq!(status, 200);
445445 let review = &reviews[0];
446- assert_eq!(review["state"], "REQUEST_CHANGES");
446+ assert_eq!(review["state"], "CHANGES_REQUESTED");
447447 assert_eq!(review["body"], "please fix");
448448 assert_eq!(review["user"]["login"], "bob");
449449 assert_eq!(review["commit_id"], f.oid);
@@ -467,6 +467,13 @@ async fn pulls_reviews_and_review_comments() {
467467 assert_eq!(c["user"]["login"], "bob");
468468 assert_eq!(c["pull_request_review_id"], review_id);
469469
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+
470477 // An issue number is not a pull request.
471478 let (status, _, _) = f.get(&repo_path_of("/pulls/1/reviews")).await;
472479 assert_eq!(status, 404);