Tag PRs based on paths they touch

This commit is contained in:
Graham Christensen 2018-02-03 11:27:09 -05:00
parent a9182ea325
commit de179794cb
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
4 changed files with 38 additions and 1 deletions

View file

@ -40,6 +40,18 @@
"zimbatm"
]
},
"tag_paths": {
"6.topic: python": [
"pkgs/top-level/python-packages.nix",
"pkgs/development/interpreters/python",
"pkgs/development/python-modules",
"doc/languages-frameworks/python.md"
],
"6.topic: ruby": [
"pkgs/development/interpreters/ruby",
"pkgs/development/ruby-modules"
]
},
"checkout": {
"root": "/var/lib/gc-of-borg/.nix-test-rs"
},

View file

@ -39,6 +39,7 @@ fn main() {
cfg.acl(),
cfg.runner.identity.clone(),
events,
cfg.tag_paths.clone().unwrap(),
);
channel.basic_prefetch(1).unwrap();

View file

@ -7,6 +7,7 @@ use hyper::net::HttpsConnector;
use hyper_native_tls::NativeTlsClient;
use hubcaps::{Credentials, Github};
use nix::Nix;
use std::collections::HashMap;
use ofborg::acl;
@ -20,6 +21,7 @@ pub struct Config {
pub rabbitmq: RabbitMQConfig,
pub github: Option<GithubConfig>,
pub log_storage: Option<LogStorage>,
pub tag_paths: Option<HashMap<String, Vec<String>>>,
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -15,7 +15,7 @@ use ofborg::nix::Nix;
use ofborg::acl::ACL;
use ofborg::stats;
use ofborg::worker;
use ofborg::tagger::{StdenvTagger, RebuildTagger};
use ofborg::tagger::{StdenvTagger, RebuildTagger, PathsTagger};
use ofborg::outpathdiff::{OutPaths, OutPathDiff};
use ofborg::evalchecker::EvalChecker;
use ofborg::commitstatus::CommitStatus;
@ -30,6 +30,7 @@ pub struct MassRebuildWorker<E> {
acl: ACL,
identity: String,
events: E,
tag_paths: HashMap<String, Vec<String>>,
}
impl<E: stats::SysEvents> MassRebuildWorker<E> {
@ -40,6 +41,7 @@ impl<E: stats::SysEvents> MassRebuildWorker<E> {
acl: ACL,
identity: String,
events: E,
tag_paths: HashMap<String, Vec<String>>,
) -> MassRebuildWorker<E> {
return MassRebuildWorker {
cloner: cloner,
@ -48,12 +50,27 @@ impl<E: stats::SysEvents> MassRebuildWorker<E> {
acl: acl,
identity: identity,
events: events,
tag_paths: tag_paths
};
}
fn actions(&self) -> massrebuildjob::Actions {
return massrebuildjob::Actions {};
}
fn tag_from_paths(&self, issue: &hubcaps::issues::IssueRef, paths: Vec<String>) {
let mut tagger = PathsTagger::new(self.tag_paths.clone());
for path in paths {
tagger.path_changed(&path);
}
update_labels(
&issue,
tagger.tags_to_add(),
tagger.tags_to_remove(),
);
}
}
impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
@ -199,6 +216,11 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
vec!["".to_owned()],
));
self.tag_from_paths(
&issue,
co.files_changed_from_head(&job.pr.head_sha).unwrap_or(vec![])
);
overall_status.set_with_description("Merging PR", hubcaps::statuses::State::Pending);
if let Err(_) = co.merge_commit(job.pr.head_sha.as_ref()) {