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" "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": { "checkout": {
"root": "/var/lib/gc-of-borg/.nix-test-rs" "root": "/var/lib/gc-of-borg/.nix-test-rs"
}, },

View file

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

View file

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

View file

@ -15,7 +15,7 @@ use ofborg::nix::Nix;
use ofborg::acl::ACL; use ofborg::acl::ACL;
use ofborg::stats; use ofborg::stats;
use ofborg::worker; use ofborg::worker;
use ofborg::tagger::{StdenvTagger, RebuildTagger}; use ofborg::tagger::{StdenvTagger, RebuildTagger, PathsTagger};
use ofborg::outpathdiff::{OutPaths, OutPathDiff}; use ofborg::outpathdiff::{OutPaths, OutPathDiff};
use ofborg::evalchecker::EvalChecker; use ofborg::evalchecker::EvalChecker;
use ofborg::commitstatus::CommitStatus; use ofborg::commitstatus::CommitStatus;
@ -30,6 +30,7 @@ pub struct MassRebuildWorker<E> {
acl: ACL, acl: ACL,
identity: String, identity: String,
events: E, events: E,
tag_paths: HashMap<String, Vec<String>>,
} }
impl<E: stats::SysEvents> MassRebuildWorker<E> { impl<E: stats::SysEvents> MassRebuildWorker<E> {
@ -40,6 +41,7 @@ impl<E: stats::SysEvents> MassRebuildWorker<E> {
acl: ACL, acl: ACL,
identity: String, identity: String,
events: E, events: E,
tag_paths: HashMap<String, Vec<String>>,
) -> MassRebuildWorker<E> { ) -> MassRebuildWorker<E> {
return MassRebuildWorker { return MassRebuildWorker {
cloner: cloner, cloner: cloner,
@ -48,12 +50,27 @@ impl<E: stats::SysEvents> MassRebuildWorker<E> {
acl: acl, acl: acl,
identity: identity, identity: identity,
events: events, events: events,
tag_paths: tag_paths
}; };
} }
fn actions(&self) -> massrebuildjob::Actions { fn actions(&self) -> massrebuildjob::Actions {
return 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> { 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()], 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); overall_status.set_with_description("Merging PR", hubcaps::statuses::State::Pending);
if let Err(_) = co.merge_commit(job.pr.head_sha.as_ref()) { if let Err(_) = co.merge_commit(job.pr.head_sha.as_ref()) {