From 4dd5802501f134bddccaf05ee342ed67f3646eba Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 31 Oct 2024 00:48:20 +0100 Subject: [PATCH] feat: remove gists from this codebase Bye bye, one piece of GitHub! Signed-off-by: Raito Bezarius --- ofborg/src/tasks/eval/mod.rs | 2 +- ofborg/src/tasks/eval/nixpkgs.rs | 27 +++++------ ofborg/src/tasks/evaluate.rs | 63 +++++--------------------- ofborg/src/tasks/mod.rs | 3 +- ofborg/src/tasks/pastebin_collector.rs | 8 ---- ofborg/src/utils/pastebin.rs | 13 +++++- 6 files changed, 38 insertions(+), 78 deletions(-) diff --git a/ofborg/src/tasks/eval/mod.rs b/ofborg/src/tasks/eval/mod.rs index 4e32ee6..172c335 100644 --- a/ofborg/src/tasks/eval/mod.rs +++ b/ofborg/src/tasks/eval/mod.rs @@ -41,7 +41,7 @@ pub struct EvaluationComplete { pub enum Error { CommitStatusWrite(CommitStatusError), Fail(String), - FailWithGist(String, String, String), + FailWithPastebin(String, String, String), } impl From for Error { diff --git a/ofborg/src/tasks/eval/nixpkgs.rs b/ofborg/src/tasks/eval/nixpkgs.rs index b126acb..7153adb 100644 --- a/ofborg/src/tasks/eval/nixpkgs.rs +++ b/ofborg/src/tasks/eval/nixpkgs.rs @@ -12,13 +12,12 @@ use crate::tagger::{MaintainerPrTagger, PkgsAddedRemovedTagger, RebuildTagger, S use crate::tasks::eval::{ stdenvs::Stdenvs, Error, EvaluationComplete, EvaluationStrategy, StepResult, }; -use crate::tasks::evaluate::{get_prefix, make_gist, update_labels}; +use crate::tasks::evaluate::{get_prefix, update_labels}; use std::path::Path; use chrono::Utc; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; -use hubcaps::gists::Gists; use hubcaps::issues::{Issue, IssueRef}; use hubcaps::repositories::Repository; use regex::Regex; @@ -53,7 +52,6 @@ pub struct NixpkgsStrategy<'a> { issue: &'a Issue, issue_ref: &'a IssueRef, repo: &'a Repository, - gists: &'a Gists, nix: Nix, stdenv_diff: Option, outpath_diff: Option, @@ -69,7 +67,6 @@ impl<'a> NixpkgsStrategy<'a> { issue: &'a Issue, issue_ref: &'a IssueRef, repo: &'a Repository, - gists: &'a Gists, nix: Nix, ) -> NixpkgsStrategy<'a> { Self { @@ -78,7 +75,6 @@ impl<'a> NixpkgsStrategy<'a> { issue, issue_ref, repo, - gists, nix, stdenv_diff: None, outpath_diff: None, @@ -137,7 +133,7 @@ impl<'a> NixpkgsStrategy<'a> { .notify(Event::TargetBranchFailsEvaluation(target_branch.clone())); */ - Err(Error::FailWithGist( + Err(Error::FailWithPastebin( String::from("The branch this PR will merge in to does not cleanly evaluate, and so this PR cannot be checked."), String::from("Output path comparison"), err.display(), @@ -151,7 +147,7 @@ impl<'a> NixpkgsStrategy<'a> { fn check_outpaths_after(&mut self) -> StepResult<()> { if let Some(ref mut rebuildsniff) = self.outpath_diff { if let Err(err) = rebuildsniff.find_after() { - Err(Error::FailWithGist( + Err(Error::FailWithPastebin( String::from("This PR does not cleanly list package outputs after merging."), String::from("Output path comparison"), err.display(), @@ -235,16 +231,15 @@ impl<'a> NixpkgsStrategy<'a> { } fn gist_changed_paths(&self, attrs: &[PackageArch]) -> Option { - make_gist( - self.gists, + crate::utils::pastebin::make_pastebin( "Changed Paths", - Some("".to_owned()), attrs .iter() .map(|attr| format!("{}\t{}", &attr.architecture, &attr.package)) .collect::>() .join("\n"), ) + .map(|pp| pp.uri) } fn record_impacted_maintainers(&self, dir: &Path, attrs: &[PackageArch]) -> Result<(), Error> { @@ -257,15 +252,14 @@ impl<'a> NixpkgsStrategy<'a> { let m = ImpactedMaintainers::calculate(&self.nix, dir, changed_paths, &changed_attributes); - let gist_url = make_gist( - self.gists, + let gist_url = crate::utils::pastebin::make_pastebin( "Potential Maintainers", - Some("".to_owned()), match m { Ok(ref maintainers) => format!("Maintainers:\n{}", maintainers), Err(ref e) => format!("Ignorable calculation error:\n{:?}", e), }, - ); + ) + .map(|pp| pp.uri); let prefix = get_prefix(self.repo.statuses(), &self.job.pr.head_sha)?; @@ -357,7 +351,10 @@ impl<'a> NixpkgsStrategy<'a> { } } Err(out) => { - status.set_url(make_gist(self.gists, "Meta Check", None, out.display())); + status.set_url( + crate::utils::pastebin::make_pastebin("Meta Check", out.display()) + .map(|pp| pp.uri), + ); status.set(hubcaps::statuses::State::Failure)?; Err(Error::Fail(String::from( "Failed to validate package metadata.", diff --git a/ofborg/src/tasks/evaluate.rs b/ofborg/src/tasks/evaluate.rs index 600f39c..3d325cb 100644 --- a/ofborg/src/tasks/evaluate.rs +++ b/ofborg/src/tasks/evaluate.rs @@ -9,23 +9,21 @@ use crate::nix; use crate::stats::{self, Event}; use crate::systems; use crate::tasks::eval; +use crate::utils::pastebin::PersistedPastebin; use crate::worker; use futures_util::TryFutureExt; -use std::collections::HashMap; use std::path::Path; use std::sync::RwLock; use std::time::Instant; use hubcaps::checks::CheckRunOptions; -use hubcaps::gists::Gists; use hubcaps::issues::Issue; use tracing::{debug, debug_span, error, info, warn}; pub struct EvaluationWorker { cloner: checkout::CachedCloner, nix: nix::Nix, - github: hubcaps::Github, github_vend: RwLock, acl: Acl, identity: String, @@ -37,7 +35,6 @@ impl EvaluationWorker { pub fn new( cloner: checkout::CachedCloner, nix: &nix::Nix, - github: hubcaps::Github, github_vend: GithubAppVendingMachine, acl: Acl, identity: String, @@ -46,7 +43,6 @@ impl EvaluationWorker { EvaluationWorker { cloner, nix: nix.without_limited_supported_systems(), - github, github_vend: RwLock::new(github_vend), acl, identity, @@ -92,7 +88,6 @@ impl worker::SimpleWorker for EvaluationWorker OneEval::new( github_client, - &self.github, &self.nix, &self.acl, &mut self.events, @@ -107,7 +102,6 @@ impl worker::SimpleWorker for EvaluationWorker struct OneEval<'a, E> { client_app: &'a hubcaps::Github, repo: hubcaps::repositories::Repository, - gists: Gists, nix: &'a nix::Nix, acl: &'a Acl, events: &'a mut E, @@ -120,7 +114,6 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { #[allow(clippy::too_many_arguments)] fn new( client_app: &'a hubcaps::Github, - client_legacy: &'a hubcaps::Github, nix: &'a nix::Nix, acl: &'a Acl, events: &'a mut E, @@ -128,13 +121,10 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { cloner: &'a checkout::CachedCloner, job: &'a evaluationjob::EvaluationJob, ) -> OneEval<'a, E> { - let gists = client_legacy.gists(); - let repo = client_app.repo(job.repo.owner.clone(), job.repo.name.clone()); OneEval { client_app, repo, - gists, nix, acl, events, @@ -190,13 +180,8 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { ) } - fn make_gist( - &self, - filename: &str, - description: Option, - content: String, - ) -> Option { - make_gist(&self.gists, filename, description, content) + fn make_pastebin(&self, title: &str, contents: String) -> Option { + crate::utils::pastebin::make_pastebin(title, contents) } fn worker_actions(&mut self) -> worker::Actions { @@ -206,10 +191,10 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { EvalWorkerError::EvalError(eval::Error::Fail(msg)) => { self.update_status(msg, None, hubcaps::statuses::State::Failure) } - EvalWorkerError::EvalError(eval::Error::FailWithGist(msg, filename, content)) => self + EvalWorkerError::EvalError(eval::Error::FailWithPastebin(msg, title, content)) => self .update_status( msg, - self.make_gist(&filename, Some("".to_owned()), content), + self.make_pastebin(&title, content).map(|pp| pp.uri), hubcaps::statuses::State::Failure, ), EvalWorkerError::EvalError(eval::Error::CommitStatusWrite(e)) => Err(e), @@ -297,7 +282,6 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { &issue, &issue_ref, &repo, - &self.gists, self.nix.clone(), )) } else { @@ -422,11 +406,12 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> { } Err(mut out) => { state = hubcaps::statuses::State::Failure; - gist_url = self.make_gist( - &format!("{}-eval-{}", prefix, check.name()), - Some(format!("{:?}", state)), - file_to_str(&mut out), - ); + gist_url = self + .make_pastebin( + &format!("[{}] Evaluation of {}", prefix, check.name()), + file_to_str(&mut out), + ) + .map(|pp| pp.uri); } } @@ -507,32 +492,6 @@ fn schedule_builds( response } -pub fn make_gist( - gists: &hubcaps::gists::Gists, - name: &str, - description: Option, - contents: String, -) -> Option { - let mut files: HashMap = HashMap::new(); - files.insert( - name.to_string(), - hubcaps::gists::Content { - filename: Some(name.to_string()), - content: contents, - }, - ); - - Some( - async_std::task::block_on(gists.create(&hubcaps::gists::GistOptions { - description, - public: Some(true), - files, - })) - .expect("Failed to create gist!") - .html_url, - ) -} - pub fn update_labels(issueref: &hubcaps::issues::IssueRef, add: &[String], remove: &[String]) { let l = issueref.labels(); let issue = async_std::task::block_on(issueref.get()).expect("Failed to get issue"); diff --git a/ofborg/src/tasks/mod.rs b/ofborg/src/tasks/mod.rs index c290c36..82f5214 100644 --- a/ofborg/src/tasks/mod.rs +++ b/ofborg/src/tasks/mod.rs @@ -4,6 +4,7 @@ pub mod evaluate; pub mod evaluationfilter; pub mod githubcommentfilter; pub mod githubcommentposter; -pub mod pastebin_collector; pub mod log_message_collector; +pub mod pastebin_collector; pub mod statscollector; +pub mod status_check_collector; diff --git a/ofborg/src/tasks/pastebin_collector.rs b/ofborg/src/tasks/pastebin_collector.rs index 18d2f4b..0d102c6 100644 --- a/ofborg/src/tasks/pastebin_collector.rs +++ b/ofborg/src/tasks/pastebin_collector.rs @@ -12,16 +12,9 @@ use crate::{ worker, }; -enum CompressionMethod { - //None, - Zstd, -} - -#[allow(dead_code)] pub struct PastebinCollector { pastebin_root: PathBuf, db_path: PathBuf, - compression_method: CompressionMethod, } impl PastebinCollector { @@ -29,7 +22,6 @@ impl PastebinCollector { Self { pastebin_root, db_path, - compression_method: CompressionMethod::Zstd, } } } diff --git a/ofborg/src/utils/pastebin.rs b/ofborg/src/utils/pastebin.rs index 14592e1..b63c8a4 100644 --- a/ofborg/src/utils/pastebin.rs +++ b/ofborg/src/utils/pastebin.rs @@ -23,7 +23,6 @@ impl From<&Pastebin> for PersistedPastebin { let uuid_str = uuid.as_bytes(); let encoded_uri = BASE64_URL_SAFE_NO_PAD.encode(uuid_str); let path = format!("pastes/{}", uuid.simple()); - // derive a uri and a path from it. PersistedPastebin { title: value.title.clone(), uri: encoded_uri, @@ -31,3 +30,15 @@ impl From<&Pastebin> for PersistedPastebin { } } } + +pub fn make_pastebin(title: &str, contents: String) -> Option { + let pastebin = Pastebin { + title: title.to_owned(), + contents, + }; + + // wait for a reply? + //async_std::task::block_on(publish_serde_action(pastebin)); + + None +}