in src/output.rs [352:415]
fn get_coveralls_git_info(commit_sha: &str, vcs_branch: &str) -> Value {
let status = Command::new("git")
.arg("status")
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.map(|exit_status| exit_status.success());
if let Ok(true) = status {
// We have a valid Git repo -- the rest of the function will handle this case
} else {
return json!({
"head": {
"id": commit_sha,
},
"branch": vcs_branch,
});
}
// Runs `git log` with a given format, to extract some piece of commit info. On failure,
// returns empty string.
let gitlog = |format| -> String {
get_git_output([
"log",
"--max-count=1",
&format!("--pretty=format:{}", format),
commit_sha,
])
};
let author_name = gitlog("%aN");
let author_email = gitlog("%ae");
let committer_name = gitlog("%cN");
let committer_email = gitlog("%ce");
let message = gitlog("%s");
let remotes: Value = {
let output = get_git_output(["remote", "--verbose"]);
let mut remotes = Vec::<Value>::new();
for line in output.lines() {
if line.ends_with(" (fetch)") {
let mut fields = line.split_whitespace();
if let (Some(name), Some(url)) = (fields.next(), fields.next()) {
remotes.push(json!({"name": name, "url": url}))
};
}
}
json!(remotes)
};
json!({
"head": {
"id": commit_sha,
"author_name": author_name,
"author_email": author_email,
"committer_name": committer_name,
"committer_email": committer_email,
"message": message,
},
"branch": vcs_branch,
"remotes": remotes,
})
}