Skip to content

Commit

Permalink
commitstatus: use github trait
Browse files Browse the repository at this point in the history
  • Loading branch information
LnL7 committed Nov 24, 2020
1 parent 54002e3 commit f5c65fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
13 changes: 8 additions & 5 deletions ofborg/src/commitstatus.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::ghrepo;

use std::rc::Rc;
use tracing::warn;

pub struct CommitStatus<'a> {
api: hubcaps::statuses::Statuses<'a>,
repo_client: Rc<dyn ghrepo::Client + 'a>,
sha: String,
context: String,
description: String,
Expand All @@ -10,14 +13,14 @@ pub struct CommitStatus<'a> {

impl<'a> CommitStatus<'a> {
pub fn new(
api: hubcaps::statuses::Statuses<'a>,
repo_client: Rc<dyn ghrepo::Client + 'a>,
sha: String,
context: String,
description: String,
url: Option<String>,
) -> CommitStatus<'a> {
let mut stat = CommitStatus {
api,
repo_client,
sha,
context,
description,
Expand Down Expand Up @@ -57,8 +60,8 @@ impl<'a> CommitStatus<'a> {
self.description.clone()
};

self.api
.create(
self.repo_client
.create_status(
self.sha.as_ref(),
&hubcaps::statuses::StatusOptions::builder(state)
.context(self.context.clone())
Expand Down
24 changes: 0 additions & 24 deletions ofborg/src/ghrepo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::commitstatus;
use crate::message;

use hubcaps::checks::{CheckRun, CheckRunOptions};
Expand All @@ -22,13 +21,6 @@ pub trait Client {
) -> hubcaps::Result<Pull>;
fn create_status(&self, sha: &str, status: &StatusOptions) -> hubcaps::Result<Status>;
fn create_checkrun(&self, check: &CheckRunOptions) -> hubcaps::Result<CheckRun>;
fn create_commitstatus(
&self,
pr: &message::Pr,
context: String,
description: String,
gist_url: Option<String>,
) -> commitstatus::CommitStatus;
}

pub struct Hubcaps<'a> {
Expand Down Expand Up @@ -76,20 +68,4 @@ impl Client for Hubcaps<'_> {
fn create_checkrun(&self, check: &CheckRunOptions) -> hubcaps::Result<CheckRun> {
self.repo.checkruns().create(&check)
}

fn create_commitstatus(
&self,
pr: &message::Pr,
context: String,
description: String,
gist_url: Option<String>,
) -> commitstatus::CommitStatus {
commitstatus::CommitStatus::new(
self.repo.statuses(),
pr.head_sha.clone(),
context,
description,
gist_url,
)
}
}
15 changes: 9 additions & 6 deletions ofborg/src/tasks/eval/nixpkgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ impl<'a> NixpkgsStrategy<'a> {
"pull request has {} changed paths, skipping review requests",
changed_paths.len()
);
let status = self.repo_client.create_commitstatus(
&self.job.pr,
let status = CommitStatus::new(
self.repo_client.clone(),
self.job.pr.head_sha.clone(),
String::from("grahamcofborg-eval-check-maintainers"),
String::from("large change, skipping automatic review requests"),
gist_url,
Expand All @@ -288,8 +289,9 @@ impl<'a> NixpkgsStrategy<'a> {
return Ok(());
}

let status = self.repo_client.create_commitstatus(
&self.job.pr,
let status = CommitStatus::new(
self.repo_client.clone(),
self.job.pr.head_sha.clone(),
String::from("grahamcofborg-eval-check-maintainers"),
String::from("matching changed paths to changed attrs..."),
gist_url,
Expand Down Expand Up @@ -318,8 +320,9 @@ impl<'a> NixpkgsStrategy<'a> {

fn check_meta_queue_builds(&self, dir: &Path) -> StepResult<Vec<BuildJob>> {
if let Some(ref possibly_touched_packages) = self.touched_packages {
let mut status = self.repo_client.create_commitstatus(
&self.job.pr,
let mut status = CommitStatus::new(
self.repo_client.clone(),
self.job.pr.head_sha.clone(),
String::from("grahamcofborg-eval-check-meta"),
String::from("config.nix: checkMeta = true"),
None,
Expand Down
12 changes: 7 additions & 5 deletions ofborg/src/tasks/evaluate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// This is what evaluates every pull-request
use crate::acl::ACL;
use crate::checkout;
use crate::commitstatus::CommitStatusError;
use crate::commitstatus::{CommitStatus, CommitStatusError};
use crate::config::GithubAppVendingMachine;
use crate::files::file_to_str;
use crate::ghgist;
Expand Down Expand Up @@ -290,8 +290,9 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
Box::new(eval::GenericStrategy::new())
};

let mut overall_status = self.repo_client.create_commitstatus(
&job.pr,
let mut overall_status = CommitStatus::new(
self.repo_client.clone(),
job.pr.head_sha.clone(),
"grahamcofborg-eval".to_string(),
"Starting".to_string(),
None,
Expand Down Expand Up @@ -373,8 +374,9 @@ impl<'a, E: stats::SysEvents + 'static> OneEval<'a, E> {
.evaluation_checks()
.into_iter()
.map(|check| {
let mut status = self.repo_client.create_commitstatus(
&job.pr,
let mut status = CommitStatus::new(
self.repo_client.clone(),
job.pr.head_sha.clone(),
check.name(),
check.cli_cmd(),
None,
Expand Down

0 comments on commit f5c65fc

Please sign in to comment.