From bc00b523ea68d5bf8f33fd8cf604a4eb03a54af7 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 4 Feb 2021 11:16:34 -0800 Subject: [PATCH] Rename check prefixes to `ofborg` * If the sha we're operating on already has checks beginning with the old `grahamcofborg-` prefix (e.g. someone just used `@ofborg eval`, `@ofborg build`, or `@ofborg test`), continue using that prefix. * If the sha we're operating on doesn't have any checks beginning with the old `grahamcofborg-` prefix, use the new `ofborg-` prefix. This will take effect on all new PRs immediately, and after a force-push for all existing PRs. --- ofborg/src/evalchecker.rs | 4 ++-- ofborg/src/tasks/eval/nixpkgs.rs | 12 +++++++---- ofborg/src/tasks/evaluate.rs | 36 ++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/ofborg/src/evalchecker.rs b/ofborg/src/evalchecker.rs index d34b5ab..d7af769 100644 --- a/ofborg/src/evalchecker.rs +++ b/ofborg/src/evalchecker.rs @@ -20,8 +20,8 @@ impl EvalChecker { } } - pub fn name(&self) -> String { - format!("grahamcofborg-eval-{}", self.name) + pub fn name(&self) -> &str { + &self.name } pub fn execute(&self, path: &Path) -> Result { diff --git a/ofborg/src/tasks/eval/nixpkgs.rs b/ofborg/src/tasks/eval/nixpkgs.rs index 4799883..61a5972 100644 --- a/ofborg/src/tasks/eval/nixpkgs.rs +++ b/ofborg/src/tasks/eval/nixpkgs.rs @@ -14,7 +14,7 @@ use crate::tagger::{ use crate::tasks::eval::{ stdenvs::Stdenvs, Error, EvaluationComplete, EvaluationStrategy, StepResult, }; -use crate::tasks::evaluate::{make_gist, update_labels}; +use crate::tasks::evaluate::{get_prefix, make_gist, update_labels}; use std::collections::HashMap; use std::path::Path; @@ -272,6 +272,8 @@ impl<'a> NixpkgsStrategy<'a> { }, ); + let prefix = get_prefix(self.repo.statuses(), &self.job.pr.head_sha)?; + if changed_paths.len() > MAINTAINER_REVIEW_MAX_CHANGED_PATHS { info!( "pull request has {} changed paths, skipping review requests", @@ -280,7 +282,7 @@ impl<'a> NixpkgsStrategy<'a> { let status = CommitStatus::new( self.repo.statuses(), self.job.pr.head_sha.clone(), - String::from("grahamcofborg-eval-check-maintainers"), + format!("{}-eval-check-maintainers", prefix), String::from("large change, skipping automatic review requests"), gist_url, ); @@ -291,7 +293,7 @@ impl<'a> NixpkgsStrategy<'a> { let status = CommitStatus::new( self.repo.statuses(), self.job.pr.head_sha.clone(), - String::from("grahamcofborg-eval-check-maintainers"), + format!("{}-eval-check-maintainers", prefix), String::from("matching changed paths to changed attrs..."), gist_url, ); @@ -315,10 +317,12 @@ impl<'a> NixpkgsStrategy<'a> { fn check_meta_queue_builds(&self, dir: &Path) -> StepResult> { if let Some(ref possibly_touched_packages) = self.touched_packages { + let prefix = get_prefix(self.repo.statuses(), &self.job.pr.head_sha)?; + let mut status = CommitStatus::new( self.repo.statuses(), self.job.pr.head_sha.clone(), - String::from("grahamcofborg-eval-check-meta"), + format!("{}-eval-check-meta", prefix), String::from("config.nix: checkMeta = true"), None, ); diff --git a/ofborg/src/tasks/evaluate.rs b/ofborg/src/tasks/evaluate.rs index 088e319..009e9ec 100644 --- a/ofborg/src/tasks/evaluate.rs +++ b/ofborg/src/tasks/evaluate.rs @@ -186,9 +186,13 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { } else { description }; + let repo = self + .client_app + .repo(self.job.repo.owner.clone(), self.job.repo.name.clone()); + let prefix = get_prefix(repo.statuses(), &self.job.pr.head_sha)?; let mut builder = hubcaps::statuses::StatusOptions::builder(state); - builder.context("grahamcofborg-eval"); + builder.context(format!("{}-eval", prefix)); builder.description(description.clone()); if let Some(url) = url { @@ -322,10 +326,12 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { Box::new(eval::GenericStrategy::new()) }; + let prefix = get_prefix(repo.statuses(), &job.pr.head_sha)?; + let mut overall_status = CommitStatus::new( repo.statuses(), job.pr.head_sha.clone(), - "grahamcofborg-eval".to_owned(), + format!("{}-eval", &prefix), "Starting".to_owned(), None, ); @@ -422,7 +428,7 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { let mut status = CommitStatus::new( repo.statuses(), job.pr.head_sha.clone(), - check.name(), + format!("{}-eval-{}", prefix, check.name()), check.cli_cmd(), None, ); @@ -441,7 +447,7 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { Err(mut out) => { state = hubcaps::statuses::State::Failure; gist_url = self.make_gist( - &check.name(), + &format!("{}-eval-{}", prefix, check.name()), Some(format!("{:?}", state)), file_to_str(&mut out), ); @@ -618,6 +624,28 @@ fn indicates_wip(text: &str) -> bool { false } +/// Determine whether or not to use the "old" status prefix, `grahamcofborg`, or +/// the new one, `ofborg`. +/// +/// If the PR already has any `grahamcofborg`-prefixed statuses, continue to use +/// that (e.g. if someone used `@ofborg eval`, `@ofborg build`, `@ofborg test`). +/// Otherwise, if it's a new PR or was recently force-pushed (and therefore +/// doesn't have any old `grahamcofborg`-prefixed statuses), use the new prefix. +pub fn get_prefix<'a>( + statuses: hubcaps::statuses::Statuses, + sha: &'a str, +) -> Result<&'a str, CommitStatusError> { + if statuses + .list(&sha)? + .iter() + .any(|s| s.context.starts_with("grahamcofborg-")) + { + Ok("grahamcofborg") + } else { + Ok("ofborg") + } +} + enum EvalWorkerError { EvalError(eval::Error), CommitStatusWrite(CommitStatusError),