review_submitted.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. use crate::github::{Issue, IssueCommentAction, IssueCommentEvent, Label, PullRequestReviewState};
  2. use crate::{config::ReviewSubmittedConfig, github::Event, handlers::Context};
  3. pub(crate) async fn handle(
  4. ctx: &Context,
  5. event: &Event,
  6. config: &ReviewSubmittedConfig,
  7. ) -> anyhow::Result<()> {
  8. if let Event::IssueComment(
  9. event
  10. @
  11. IssueCommentEvent {
  12. action: IssueCommentAction::Created,
  13. issue: Issue {
  14. pull_request: Some(_),
  15. ..
  16. },
  17. ..
  18. },
  19. ) = event
  20. {
  21. if event.comment.pr_review_state != Some(PullRequestReviewState::ChangesRequested) {
  22. return Ok(());
  23. }
  24. if event.issue.assignees.contains(&event.comment.user) {
  25. // Remove review labels
  26. for label in &config.review_labels {
  27. event.issue.remove_label(&ctx.github, &label).await?;
  28. }
  29. // Add waiting on author
  30. event
  31. .issue
  32. .add_labels(
  33. &ctx.github,
  34. vec![Label {
  35. name: config.reviewed_label.clone(),
  36. }],
  37. )
  38. .await?;
  39. }
  40. }
  41. Ok(())
  42. }