Test the fetching of commit messages, return a list of messages instead of a big string of messages
This commit is contained in:
parent
5e4360e6af
commit
b2655cac5b
|
@ -148,7 +148,8 @@ impl CachedProjectCo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn commit_messages_from_head(&self, commit: &str) -> Result<String, Error> {
|
||||
|
||||
pub fn commit_messages_from_head(&self, commit: &str) -> Result<Vec<String>, Error> {
|
||||
let mut lock = self.lock()?;
|
||||
|
||||
let result = Command::new("git")
|
||||
|
@ -161,7 +162,12 @@ impl CachedProjectCo {
|
|||
lock.unlock();
|
||||
|
||||
if result.status.success() {
|
||||
return Ok(String::from_utf8_lossy(&result.stdout).to_lowercase());
|
||||
return Ok(
|
||||
String::from_utf8_lossy(&result.stdout)
|
||||
.lines()
|
||||
.map(|l| l.to_owned())
|
||||
.collect()
|
||||
);
|
||||
} else {
|
||||
return Err(Error::new(ErrorKind::Other,
|
||||
String::from_utf8_lossy(&result.stderr).to_lowercase()));
|
||||
|
@ -217,3 +223,52 @@ impl clone::GitClonable for CachedProject {
|
|||
return vec![OsStr::new("--bare")];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use ofborg::test_scratch::TestScratch;
|
||||
|
||||
fn tpath(component: &str) -> PathBuf {
|
||||
return Path::new(env!("CARGO_MANIFEST_DIR")).join(component);
|
||||
}
|
||||
|
||||
fn make_pr_repo(bare: &Path, co: &Path) -> String {
|
||||
let output = Command::new("./make-pr.sh")
|
||||
.current_dir(tpath("./test-srcs"))
|
||||
.arg(bare)
|
||||
.arg(co)
|
||||
.stderr(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.output()
|
||||
.expect("building the test PR failed");
|
||||
let hash = String::from_utf8(output.stdout).expect("Should just be a hash");
|
||||
return hash.trim().to_owned();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_commit_msg_list() {
|
||||
let workingdir = TestScratch::new_dir("test-test-commit-msg-list");
|
||||
|
||||
let bare = TestScratch::new_dir("bare-commit-messages");
|
||||
let mk_co = TestScratch::new_dir("mk-commit-messages");
|
||||
let hash = make_pr_repo(&bare.path(), &mk_co.path());
|
||||
|
||||
let cloner = cached_cloner(&workingdir.path());
|
||||
let project = cloner.project("commit-msg-list".to_owned(), bare.string());
|
||||
let working_co = project.clone_for("testing-commit-msgs".to_owned(), "123".to_owned()).expect("clone should work");
|
||||
working_co.checkout_origin_ref(OsStr::new("master"));
|
||||
|
||||
let expect: Vec<String> = vec![
|
||||
"check out this cool PR".to_owned()
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
working_co.commit_messages_from_head(&hash).expect("fetching messages should work"),
|
||||
expect
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ impl<E: stats::SysEvents> worker::SimpleWorker for MassRebuildWorker<E> {
|
|||
}
|
||||
|
||||
let possibly_touched_packages = parse_commit_messages(
|
||||
&co.commit_messages_from_head(&job.pr.head_sha).unwrap_or("".to_owned())
|
||||
co.commit_messages_from_head(&job.pr.head_sha).unwrap_or(vec!["".to_owned()])
|
||||
);
|
||||
|
||||
overall_status.set_with_description("Merging PR", hubcaps::statuses::State::Pending);
|
||||
|
@ -660,9 +660,9 @@ fn file_to_str(f: &mut File) -> String {
|
|||
return String::from(String::from_utf8_lossy(&buffer));
|
||||
}
|
||||
|
||||
fn parse_commit_messages(messages: &str) -> Vec<String> {
|
||||
fn parse_commit_messages(messages: Vec<String>) -> Vec<String> {
|
||||
messages
|
||||
.lines()
|
||||
.iter()
|
||||
.filter_map(|line| {
|
||||
// Convert "foo: some notes" in to "foo"
|
||||
let parts: Vec<&str> = line.splitn(2, ":").collect();
|
||||
|
@ -727,7 +727,7 @@ mod tests {
|
|||
Merge pull request #34188 from dotlambda/home-assistant
|
||||
Merge pull request #34414 from dotlambda/postfix
|
||||
foo,bar: something here: yeah
|
||||
"),
|
||||
".lines().map(|l| l.to_owned()).collect()),
|
||||
expect
|
||||
);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ impl TestScratch {
|
|||
pub fn path(&self) -> PathBuf {
|
||||
self.root.clone()
|
||||
}
|
||||
|
||||
pub fn string(&self) -> String {
|
||||
self.path().to_str().unwrap().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestScratch {
|
||||
|
|
Loading…
Reference in a new issue