Create automatic command from event, if applicable.
(gh: DynGH, event: &Event)
| 98 | |
| 99 | /// Create automatic command from event, if applicable. |
| 100 | async fn from_event_automatic(gh: DynGH, event: &Event) -> Result<Option<Self>> { |
| 101 | match event { |
| 102 | // Pull request opened |
| 103 | Event::PullRequest(event) if event.action == PullRequestEventAction::Opened => { |
| 104 | // Get configuration |
| 105 | let inst_id = event.installation.id as u64; |
| 106 | let (owner, repo) = split_full_name(&event.repository.full_name); |
| 107 | let cfg = match Cfg::get(gh.clone(), inst_id, owner, repo).await { |
| 108 | Err(CfgError::ConfigNotFound) => return Ok(None), |
| 109 | Err(err) => return Err(err.into()), |
| 110 | Ok(cfg) => cfg, |
| 111 | }; |
| 112 | |
| 113 | // Process automation if enabled |
| 114 | if let Some(automation) = cfg.automation { |
| 115 | if !automation.enabled || automation.rules.is_empty() { |
| 116 | return Ok(None); |
| 117 | } |
| 118 | |
| 119 | // Check if any of the PR files matches the automation rules |
| 120 | let pr_number = event.pull_request.number; |
| 121 | let pr_files = gh.get_pr_files(inst_id, owner, repo, pr_number).await?; |
| 122 | for rule in automation.rules { |
| 123 | if rule.matches(pr_files.as_slice())? { |
| 124 | let cmd = Command::CreateVote(CreateVoteInput::new( |
| 125 | Some(&rule.profile), |
| 126 | &Event::PullRequest(event.clone()), |
| 127 | )); |
| 128 | return Ok(Some(cmd)); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | Ok(None) |
| 134 | } |
| 135 | _ => Ok(None), |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /// Information required to create a new vote. |
nothing calls this directly
no test coverage detected