Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/ofborg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6cce1a6e62d2
Choose a base ref
...
head repository: NixOS/ofborg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 37484b7763cd
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Apr 12, 2019

  1. fixups

    grahamc committed Apr 12, 2019
    Copy the full SHA
    37484b7 View commit details
Showing with 45 additions and 34 deletions.
  1. +38 −31 ofborg/src/config.rs
  2. +4 −1 ofborg/src/tasks/evaluate.rs
  3. +3 −2 ofborg/src/tasks/githubcommentposter.rs
69 changes: 38 additions & 31 deletions ofborg/src/config.rs
Original file line number Diff line number Diff line change
@@ -3,12 +3,12 @@ use hyper::net::HttpsConnector;
use hyper::Client;
use hyper_native_tls::NativeTlsClient;
use nix::Nix;
use ofborg::acl;
use serde_json;
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use ofborg::acl;

#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
@@ -114,8 +114,7 @@ impl Config {
)
}

pub fn github_app_vendingmachine(&self) -> GithubAppVendingMachine
{
pub fn github_app_vendingmachine(&self) -> GithubAppVendingMachine {
GithubAppVendingMachine {
conf: self.github_app.clone().unwrap(),
id_cache: HashMap::new(),
@@ -167,50 +166,58 @@ pub fn load(filename: &Path) -> Config {

pub struct GithubAppVendingMachine {
conf: GithubAppConfig,
id_cache: HashMap<(String, String), i32>,
id_cache: HashMap<(String, String), Option<i32>>,
client_cache: HashMap<i32, Github>,
}

impl GithubAppVendingMachine {
pub fn for_repo<'a>(&'a mut self, owner: &str, repo: &str) -> Result<&'a Github, hubcaps::Error> {
let useragent = "github.com/grahamc/ofborg (app)";
let jwt = JWTCredentials::new(self.conf.app_id,
self.conf.private_key.clone());
fn useragent(&self) -> &'static str {
"github.com/grahamc/ofborg (app)"
}

let install_id: i32;
fn jwt(&self) -> JWTCredentials {
JWTCredentials::new(self.conf.app_id, self.conf.private_key.clone())
}

fn install_id_for_repo(&mut self, owner: &str, repo: &str) -> Option<i32> {
let useragent = self.useragent();
let jwt = self.jwt();

let key = (owner.to_owned(), repo.to_owned());
if self.id_cache.contains_key(&key) {
install_id = *self.id_cache.get(&key).unwrap();
debug!("Found install ID for {:?} in cache", key);
} else {

*self.id_cache.entry(key).or_insert_with(|| {
info!("Looking up install ID for {}/{}", owner, repo);

let lookup_gh = Github::new(
useragent,
Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap())),
Credentials::JWT(jwt.clone())
Credentials::JWT(jwt),
);

install_id = lookup_gh
.app()
.find_repo_installation(owner, repo)?.id;
self.id_cache.insert(key, install_id);
debug!("Received install ID {}", install_id);
}
match lookup_gh.app().find_repo_installation(owner, repo) {
Ok(install_id) => {
debug!("Received install ID {:#?}", install_id);
Some(install_id.id)
}
Err(e) => {
warn!("Error during install ID lookup: {:#?}", e);
None
}
}
})
}

pub fn for_repo<'a>(&'a mut self, owner: &str, repo: &str) -> Option<&'a Github> {
let useragent = self.useragent();
let jwt = self.jwt();
let install_id = self.install_id_for_repo(owner, repo)?;

if ! self.client_cache.contains_key(&install_id) {
let new_client = Github::new(
Some(self.client_cache.entry(install_id).or_insert_with(|| {
Github::new(
useragent,
Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap())),
Credentials::InstallationToken(InstallationTokenGenerator::new(
install_id,
jwt
)),
);
self.client_cache.insert(install_id, new_client);
}

Ok(self.client_cache.get(&install_id).unwrap())
Credentials::InstallationToken(InstallationTokenGenerator::new(install_id, jwt)),
)
}))
}
}
5 changes: 4 additions & 1 deletion ofborg/src/tasks/evaluate.rs
Original file line number Diff line number Diff line change
@@ -321,7 +321,10 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for EvaluationWorker<E>
.all_evaluations_passed(&Path::new(&refpath), &mut overall_status);
match ret {
Ok(builds) => {
info!("Scheduling build jobs {:#?} on arches {:#?}", builds, auto_schedule_build_archs);
info!(
"Scheduling build jobs {:#?} on arches {:#?}",
builds, auto_schedule_build_archs
);
for buildjob in builds {
for arch in auto_schedule_build_archs.iter() {
let (exchange, routingkey) = arch.as_build_destination();
5 changes: 3 additions & 2 deletions ofborg/src/tasks/githubcommentposter.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@ use amqp::protocol::basic::{BasicProperties, Deliver};
use chrono::{DateTime, Utc};
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use message::buildjob::{BuildJob, QueuedBuildJobs};
use ofborg::config::GithubAppVendingMachine;
use ofborg::message::buildresult::{BuildResult, BuildStatus, LegacyBuildResult};
use ofborg::message::Repo;
use ofborg::worker;
use ofborg::config::GithubAppVendingMachine;

pub struct GitHubCommentPoster {
github_vend: GithubAppVendingMachine,
@@ -77,7 +77,8 @@ impl worker::SimpleWorker for GitHubCommentPoster {
println!(":{:?}", check);

let check_create_attempt = self
.github_vend.for_repo(&repo.owner, &repo.name)
.github_vend
.for_repo(&repo.owner, &repo.name)
.unwrap()
.repo(repo.owner.clone(), repo.name.clone())
.checkruns()