close.rs 722 B

12345678910111213141516171819202122232425
  1. //! Allows to close an issue or a PR
  2. use crate::{config::CloseConfig, github::Event, handlers::Context, interactions::ErrorComment};
  3. use parser::command::close::CloseCommand;
  4. pub(super) async fn handle_command(
  5. ctx: &Context,
  6. _config: &CloseConfig,
  7. event: &Event,
  8. _cmd: CloseCommand,
  9. ) -> anyhow::Result<()> {
  10. let issue = event.issue().unwrap();
  11. let is_team_member = event
  12. .user()
  13. .is_team_member(&ctx.github)
  14. .await
  15. .unwrap_or(false);
  16. if !is_team_member {
  17. let cmnt = ErrorComment::new(&issue, "Only team members can close issues.");
  18. cmnt.post(&ctx.github).await?;
  19. return Ok(());
  20. }
  21. issue.close(&ctx.github).await?;
  22. Ok(())
  23. }