review_submitted.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 @ IssueCommentEvent {
  10. action: IssueCommentAction::Created,
  11. issue: Issue {
  12. pull_request: Some(_),
  13. ..
  14. },
  15. ..
  16. },
  17. ) = event
  18. {
  19. if event.comment.pr_review_state != Some(PullRequestReviewState::ChangesRequested) {
  20. return Ok(());
  21. }
  22. if event.issue.assignees.contains(&event.comment.user) {
  23. // Remove review labels
  24. for label in &config.review_labels {
  25. event.issue.remove_label(&ctx.github, &label).await?;
  26. }
  27. // Add waiting on author
  28. event
  29. .issue
  30. .add_labels(
  31. &ctx.github,
  32. vec![Label {
  33. name: config.reviewed_label.clone(),
  34. }],
  35. )
  36. .await?;
  37. }
  38. }
  39. Ok(())
  40. }