feat: remove gists from this codebase

Bye bye, one piece of GitHub!

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
raito 2024-10-31 00:48:20 +01:00
parent cf30f9017f
commit 4dd5802501
6 changed files with 38 additions and 78 deletions

View file

@ -41,7 +41,7 @@ pub struct EvaluationComplete {
pub enum Error { pub enum Error {
CommitStatusWrite(CommitStatusError), CommitStatusWrite(CommitStatusError),
Fail(String), Fail(String),
FailWithGist(String, String, String), FailWithPastebin(String, String, String),
} }
impl From<CommitStatusError> for Error { impl From<CommitStatusError> for Error {

View file

@ -12,13 +12,12 @@ use crate::tagger::{MaintainerPrTagger, PkgsAddedRemovedTagger, RebuildTagger, S
use crate::tasks::eval::{ use crate::tasks::eval::{
stdenvs::Stdenvs, Error, EvaluationComplete, EvaluationStrategy, StepResult, 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 std::path::Path;
use chrono::Utc; use chrono::Utc;
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use hubcaps::gists::Gists;
use hubcaps::issues::{Issue, IssueRef}; use hubcaps::issues::{Issue, IssueRef};
use hubcaps::repositories::Repository; use hubcaps::repositories::Repository;
use regex::Regex; use regex::Regex;
@ -53,7 +52,6 @@ pub struct NixpkgsStrategy<'a> {
issue: &'a Issue, issue: &'a Issue,
issue_ref: &'a IssueRef, issue_ref: &'a IssueRef,
repo: &'a Repository, repo: &'a Repository,
gists: &'a Gists,
nix: Nix, nix: Nix,
stdenv_diff: Option<Stdenvs>, stdenv_diff: Option<Stdenvs>,
outpath_diff: Option<OutPathDiff>, outpath_diff: Option<OutPathDiff>,
@ -69,7 +67,6 @@ impl<'a> NixpkgsStrategy<'a> {
issue: &'a Issue, issue: &'a Issue,
issue_ref: &'a IssueRef, issue_ref: &'a IssueRef,
repo: &'a Repository, repo: &'a Repository,
gists: &'a Gists,
nix: Nix, nix: Nix,
) -> NixpkgsStrategy<'a> { ) -> NixpkgsStrategy<'a> {
Self { Self {
@ -78,7 +75,6 @@ impl<'a> NixpkgsStrategy<'a> {
issue, issue,
issue_ref, issue_ref,
repo, repo,
gists,
nix, nix,
stdenv_diff: None, stdenv_diff: None,
outpath_diff: None, outpath_diff: None,
@ -137,7 +133,7 @@ impl<'a> NixpkgsStrategy<'a> {
.notify(Event::TargetBranchFailsEvaluation(target_branch.clone())); .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("The branch this PR will merge in to does not cleanly evaluate, and so this PR cannot be checked."),
String::from("Output path comparison"), String::from("Output path comparison"),
err.display(), err.display(),
@ -151,7 +147,7 @@ impl<'a> NixpkgsStrategy<'a> {
fn check_outpaths_after(&mut self) -> StepResult<()> { fn check_outpaths_after(&mut self) -> StepResult<()> {
if let Some(ref mut rebuildsniff) = self.outpath_diff { if let Some(ref mut rebuildsniff) = self.outpath_diff {
if let Err(err) = rebuildsniff.find_after() { 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("This PR does not cleanly list package outputs after merging."),
String::from("Output path comparison"), String::from("Output path comparison"),
err.display(), err.display(),
@ -235,16 +231,15 @@ impl<'a> NixpkgsStrategy<'a> {
} }
fn gist_changed_paths(&self, attrs: &[PackageArch]) -> Option<String> { fn gist_changed_paths(&self, attrs: &[PackageArch]) -> Option<String> {
make_gist( crate::utils::pastebin::make_pastebin(
self.gists,
"Changed Paths", "Changed Paths",
Some("".to_owned()),
attrs attrs
.iter() .iter()
.map(|attr| format!("{}\t{}", &attr.architecture, &attr.package)) .map(|attr| format!("{}\t{}", &attr.architecture, &attr.package))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("\n"), .join("\n"),
) )
.map(|pp| pp.uri)
} }
fn record_impacted_maintainers(&self, dir: &Path, attrs: &[PackageArch]) -> Result<(), Error> { fn record_impacted_maintainers(&self, dir: &Path, attrs: &[PackageArch]) -> Result<(), Error> {
@ -257,15 +252,14 @@ impl<'a> NixpkgsStrategy<'a> {
let m = let m =
ImpactedMaintainers::calculate(&self.nix, dir, changed_paths, &changed_attributes); ImpactedMaintainers::calculate(&self.nix, dir, changed_paths, &changed_attributes);
let gist_url = make_gist( let gist_url = crate::utils::pastebin::make_pastebin(
self.gists,
"Potential Maintainers", "Potential Maintainers",
Some("".to_owned()),
match m { match m {
Ok(ref maintainers) => format!("Maintainers:\n{}", maintainers), Ok(ref maintainers) => format!("Maintainers:\n{}", maintainers),
Err(ref e) => format!("Ignorable calculation error:\n{:?}", e), 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)?; let prefix = get_prefix(self.repo.statuses(), &self.job.pr.head_sha)?;
@ -357,7 +351,10 @@ impl<'a> NixpkgsStrategy<'a> {
} }
} }
Err(out) => { 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)?; status.set(hubcaps::statuses::State::Failure)?;
Err(Error::Fail(String::from( Err(Error::Fail(String::from(
"Failed to validate package metadata.", "Failed to validate package metadata.",

View file

@ -9,23 +9,21 @@ use crate::nix;
use crate::stats::{self, Event}; use crate::stats::{self, Event};
use crate::systems; use crate::systems;
use crate::tasks::eval; use crate::tasks::eval;
use crate::utils::pastebin::PersistedPastebin;
use crate::worker; use crate::worker;
use futures_util::TryFutureExt; use futures_util::TryFutureExt;
use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::sync::RwLock; use std::sync::RwLock;
use std::time::Instant; use std::time::Instant;
use hubcaps::checks::CheckRunOptions; use hubcaps::checks::CheckRunOptions;
use hubcaps::gists::Gists;
use hubcaps::issues::Issue; use hubcaps::issues::Issue;
use tracing::{debug, debug_span, error, info, warn}; use tracing::{debug, debug_span, error, info, warn};
pub struct EvaluationWorker<E> { pub struct EvaluationWorker<E> {
cloner: checkout::CachedCloner, cloner: checkout::CachedCloner,
nix: nix::Nix, nix: nix::Nix,
github: hubcaps::Github,
github_vend: RwLock<GithubAppVendingMachine>, github_vend: RwLock<GithubAppVendingMachine>,
acl: Acl, acl: Acl,
identity: String, identity: String,
@ -37,7 +35,6 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
pub fn new( pub fn new(
cloner: checkout::CachedCloner, cloner: checkout::CachedCloner,
nix: &nix::Nix, nix: &nix::Nix,
github: hubcaps::Github,
github_vend: GithubAppVendingMachine, github_vend: GithubAppVendingMachine,
acl: Acl, acl: Acl,
identity: String, identity: String,
@ -46,7 +43,6 @@ impl<E: stats::SysEvents> EvaluationWorker<E> {
EvaluationWorker { EvaluationWorker {
cloner, cloner,
nix: nix.without_limited_supported_systems(), nix: nix.without_limited_supported_systems(),
github,
github_vend: RwLock::new(github_vend), github_vend: RwLock::new(github_vend),
acl, acl,
identity, identity,
@ -92,7 +88,6 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
OneEval::new( OneEval::new(
github_client, github_client,
&self.github,
&self.nix, &self.nix,
&self.acl, &self.acl,
&mut self.events, &mut self.events,
@ -107,7 +102,6 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
struct OneEval<'a, E> { struct OneEval<'a, E> {
client_app: &'a hubcaps::Github, client_app: &'a hubcaps::Github,
repo: hubcaps::repositories::Repository, repo: hubcaps::repositories::Repository,
gists: Gists,
nix: &'a nix::Nix, nix: &'a nix::Nix,
acl: &'a Acl, acl: &'a Acl,
events: &'a mut E, events: &'a mut E,
@ -120,7 +114,6 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn new( fn new(
client_app: &'a hubcaps::Github, client_app: &'a hubcaps::Github,
client_legacy: &'a hubcaps::Github,
nix: &'a nix::Nix, nix: &'a nix::Nix,
acl: &'a Acl, acl: &'a Acl,
events: &'a mut E, events: &'a mut E,
@ -128,13 +121,10 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
cloner: &'a checkout::CachedCloner, cloner: &'a checkout::CachedCloner,
job: &'a evaluationjob::EvaluationJob, job: &'a evaluationjob::EvaluationJob,
) -> OneEval<'a, E> { ) -> OneEval<'a, E> {
let gists = client_legacy.gists();
let repo = client_app.repo(job.repo.owner.clone(), job.repo.name.clone()); let repo = client_app.repo(job.repo.owner.clone(), job.repo.name.clone());
OneEval { OneEval {
client_app, client_app,
repo, repo,
gists,
nix, nix,
acl, acl,
events, events,
@ -190,13 +180,8 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
) )
} }
fn make_gist( fn make_pastebin(&self, title: &str, contents: String) -> Option<PersistedPastebin> {
&self, crate::utils::pastebin::make_pastebin(title, contents)
filename: &str,
description: Option<String>,
content: String,
) -> Option<String> {
make_gist(&self.gists, filename, description, content)
} }
fn worker_actions(&mut self) -> worker::Actions { 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)) => { EvalWorkerError::EvalError(eval::Error::Fail(msg)) => {
self.update_status(msg, None, hubcaps::statuses::State::Failure) 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( .update_status(
msg, msg,
self.make_gist(&filename, Some("".to_owned()), content), self.make_pastebin(&title, content).map(|pp| pp.uri),
hubcaps::statuses::State::Failure, hubcaps::statuses::State::Failure,
), ),
EvalWorkerError::EvalError(eval::Error::CommitStatusWrite(e)) => Err(e), EvalWorkerError::EvalError(eval::Error::CommitStatusWrite(e)) => Err(e),
@ -297,7 +282,6 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
&issue, &issue,
&issue_ref, &issue_ref,
&repo, &repo,
&self.gists,
self.nix.clone(), self.nix.clone(),
)) ))
} else { } else {
@ -422,11 +406,12 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
} }
Err(mut out) => { Err(mut out) => {
state = hubcaps::statuses::State::Failure; state = hubcaps::statuses::State::Failure;
gist_url = self.make_gist( gist_url = self
&format!("{}-eval-{}", prefix, check.name()), .make_pastebin(
Some(format!("{:?}", state)), &format!("[{}] Evaluation of {}", prefix, check.name()),
file_to_str(&mut out), file_to_str(&mut out),
); )
.map(|pp| pp.uri);
} }
} }
@ -507,32 +492,6 @@ fn schedule_builds(
response response
} }
pub fn make_gist(
gists: &hubcaps::gists::Gists,
name: &str,
description: Option<String>,
contents: String,
) -> Option<String> {
let mut files: HashMap<String, hubcaps::gists::Content> = 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]) { pub fn update_labels(issueref: &hubcaps::issues::IssueRef, add: &[String], remove: &[String]) {
let l = issueref.labels(); let l = issueref.labels();
let issue = async_std::task::block_on(issueref.get()).expect("Failed to get issue"); let issue = async_std::task::block_on(issueref.get()).expect("Failed to get issue");

View file

@ -4,6 +4,7 @@ pub mod evaluate;
pub mod evaluationfilter; pub mod evaluationfilter;
pub mod githubcommentfilter; pub mod githubcommentfilter;
pub mod githubcommentposter; pub mod githubcommentposter;
pub mod pastebin_collector;
pub mod log_message_collector; pub mod log_message_collector;
pub mod pastebin_collector;
pub mod statscollector; pub mod statscollector;
pub mod status_check_collector;

View file

@ -12,16 +12,9 @@ use crate::{
worker, worker,
}; };
enum CompressionMethod {
//None,
Zstd,
}
#[allow(dead_code)]
pub struct PastebinCollector { pub struct PastebinCollector {
pastebin_root: PathBuf, pastebin_root: PathBuf,
db_path: PathBuf, db_path: PathBuf,
compression_method: CompressionMethod,
} }
impl PastebinCollector { impl PastebinCollector {
@ -29,7 +22,6 @@ impl PastebinCollector {
Self { Self {
pastebin_root, pastebin_root,
db_path, db_path,
compression_method: CompressionMethod::Zstd,
} }
} }
} }

View file

@ -23,7 +23,6 @@ impl From<&Pastebin> for PersistedPastebin {
let uuid_str = uuid.as_bytes(); let uuid_str = uuid.as_bytes();
let encoded_uri = BASE64_URL_SAFE_NO_PAD.encode(uuid_str); let encoded_uri = BASE64_URL_SAFE_NO_PAD.encode(uuid_str);
let path = format!("pastes/{}", uuid.simple()); let path = format!("pastes/{}", uuid.simple());
// derive a uri and a path from it.
PersistedPastebin { PersistedPastebin {
title: value.title.clone(), title: value.title.clone(),
uri: encoded_uri, uri: encoded_uri,
@ -31,3 +30,15 @@ impl From<&Pastebin> for PersistedPastebin {
} }
} }
} }
pub fn make_pastebin(title: &str, contents: String) -> Option<PersistedPastebin> {
let pastebin = Pastebin {
title: title.to_owned(),
contents,
};
// wait for a reply?
//async_std::task::block_on(publish_serde_action(pastebin));
None
}