(&self, i: &CreateVoteInput)
| 163 | /// Create a new vote. |
| 164 | #[instrument(fields(repo = i.repository_full_name, issue_number = i.issue_number), skip_all, err(Debug))] |
| 165 | async fn create_vote(&self, i: &CreateVoteInput) -> Result<()> { |
| 166 | // Get vote configuration profile |
| 167 | let inst_id = i.installation_id as u64; |
| 168 | let (owner, repo) = split_full_name(&i.repository_full_name); |
| 169 | let cfg = match CfgProfile::get( |
| 170 | self.gh.clone(), |
| 171 | inst_id, |
| 172 | owner, |
| 173 | i.organization.is_some(), |
| 174 | repo, |
| 175 | i.profile_name.clone(), |
| 176 | ) |
| 177 | .await |
| 178 | { |
| 179 | Ok(cfg) => cfg, |
| 180 | Err(err) => { |
| 181 | let body = match err { |
| 182 | CfgError::ConfigNotFound => tmpl::ConfigNotFound {}.render()?, |
| 183 | CfgError::ProfileNotFound => tmpl::ConfigProfileNotFound {}.render()?, |
| 184 | CfgError::InvalidConfig(reason) => tmpl::InvalidConfig::new(&reason).render()?, |
| 185 | }; |
| 186 | self.gh.post_comment(inst_id, owner, repo, i.issue_number, &body).await?; |
| 187 | return Ok(()); |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | // Only repository collaborators can create votes |
| 192 | if !self.gh.user_is_collaborator(inst_id, owner, repo, &i.created_by).await? { |
| 193 | let body = tmpl::VoteRestricted::new(&i.created_by).render()?; |
| 194 | self.gh.post_comment(inst_id, owner, repo, i.issue_number, &body).await?; |
| 195 | return Ok(()); |
| 196 | } |
| 197 | |
| 198 | // Only allow one vote open at the same time per issue/pr |
| 199 | if self.db.has_vote_open(&i.repository_full_name, i.issue_number).await? { |
| 200 | let body = tmpl::VoteInProgress::new(&i.created_by, i.is_pull_request).render()?; |
| 201 | self.gh.post_comment(inst_id, owner, repo, i.issue_number, &body).await?; |
| 202 | return Ok(()); |
| 203 | } |
| 204 | |
| 205 | // Post vote created comment on the issue/pr |
| 206 | let body = tmpl::VoteCreated::new(i, &cfg).render()?; |
| 207 | let vote_comment_id = self.gh.post_comment(inst_id, owner, repo, i.issue_number, &body).await?; |
| 208 | |
| 209 | // Store vote information in database |
| 210 | let vote_id = self.db.store_vote(vote_comment_id, i, &cfg).await?; |
| 211 | |
| 212 | // Create check run if the vote is on a pull request |
| 213 | if i.is_pull_request { |
| 214 | let check_details = CheckDetails { |
| 215 | status: "in_progress".to_string(), |
| 216 | conclusion: None, |
| 217 | summary: "Vote open".to_string(), |
| 218 | }; |
| 219 | self.gh.create_check_run(inst_id, owner, repo, i.issue_number, &check_details).await?; |
| 220 | } |
| 221 | |
| 222 | // Update issue/pr labels |
no test coverage detected