MCPcopy Create free account
hub / github.com/cncf/gitvote / check_vote

Method check_vote

src/processor.rs:300–338  ·  view source on GitHub ↗
(&self, i: &CheckVoteInput)

Source from the content-addressed store, hash-verified

298 /// checked in `MAX_VOTE_CHECK_FREQUENCY`.
299 #[instrument(fields(vote_id), skip_all, err(Debug))]
300 async fn check_vote(&self, i: &CheckVoteInput) -> Result<()> {
301 // Get open vote (if any) from database
302 let Some(vote) = self
303 .db
304 .get_open_vote(&i.repository_full_name, i.issue_number)
305 .await
306 .context("error getting open vote")?
307 else {
308 return Ok(());
309 };
310
311 // Record vote_id as part of the current span
312 tracing::Span::current().record("vote_id", vote.vote_id.to_string());
313
314 // Check if the vote has already been checked recently
315 let inst_id = vote.installation_id as u64;
316 let (owner, repo) = split_full_name(&vote.repository_full_name);
317 if let Some(checked_at) = vote.checked_at
318 && OffsetDateTime::now_utc() - checked_at < MAX_VOTE_CHECK_FREQUENCY
319 {
320 // Post comment on the issue/pr and return
321 let body = tmpl::VoteCheckedRecently {}.render()?;
322 self.gh.post_comment(inst_id, owner, repo, vote.issue_number, &body).await?;
323 return Ok(());
324 }
325
326 // Calculate results
327 let (owner, repo) = split_full_name(&vote.repository_full_name);
328 let results = results::calculate(self.gh.clone(), owner, repo, &vote).await?;
329
330 // Post vote status comment on the issue/pr
331 let body = tmpl::VoteStatus::new(&results).render()?;
332 self.gh.post_comment(inst_id, owner, repo, vote.issue_number, &body).await?;
333
334 // Update vote's last check ts
335 self.db.update_vote_last_check(vote.vote_id).await?;
336
337 Ok(())
338 }
339}
340
341/// Worker that periodically checks the database for votes that should be

Callers 4

check_vote_not_foundFunction · 0.80
check_vote_successFunction · 0.80

Calls 5

split_full_nameFunction · 0.85
calculateFunction · 0.85
get_open_voteMethod · 0.80
post_commentMethod · 0.80

Tested by

no test coverage detected