job: read remotes list from repository
This commit is contained in:
parent
2bd817099f
commit
f13d8e142e
45
src/job.rs
45
src/job.rs
|
@ -17,8 +17,6 @@ pub(crate) struct Job {
|
||||||
// TODO: implement git operations with git2-rs where possible
|
// TODO: implement git operations with git2-rs where possible
|
||||||
|
|
||||||
impl Job {
|
impl Job {
|
||||||
const REMOTES: &'static [&'static str] = &["github", "gitlab"];
|
|
||||||
|
|
||||||
pub(crate) fn new(repo: Repository) -> Self {
|
pub(crate) fn new(repo: Repository) -> Self {
|
||||||
Self {
|
Self {
|
||||||
repo,
|
repo,
|
||||||
|
@ -93,16 +91,12 @@ impl Job {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_mirrors(&self) -> anyhow::Result<()> {
|
fn get_remotes(&self) -> anyhow::Result<String> {
|
||||||
for remote in Self::REMOTES.iter() {
|
|
||||||
info!("Updating mirror {}:{}...", remote, self.repo.full_name);
|
|
||||||
|
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg(format!("{}", self.local_path.as_ref().unwrap().display()))
|
.arg(format!("{}", self.local_path.as_ref().unwrap().display()))
|
||||||
.arg("push")
|
.arg("show")
|
||||||
.arg("--mirror")
|
.arg("HEAD:.lohr")
|
||||||
.arg(format!("git@{}.com:{}", remote, self.repo.full_name))
|
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
|
@ -113,7 +107,38 @@ impl Job {
|
||||||
.unwrap_or_else(|| output.status.signal().unwrap());
|
.unwrap_or_else(|| output.status.signal().unwrap());
|
||||||
|
|
||||||
bail!(
|
bail!(
|
||||||
"couldn't update origin remote: exit code {}, stderr:\n{}",
|
"couldn't read .lohr file from repo {}: exit code {}, stderr:\n{}",
|
||||||
|
self.repo.full_name,
|
||||||
|
code,
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(String::from_utf8(output.stdout)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_mirrors(&self) -> anyhow::Result<()> {
|
||||||
|
for remote in self.get_remotes()?.lines() {
|
||||||
|
info!("Updating mirror {}:{}...", remote, self.repo.full_name);
|
||||||
|
|
||||||
|
let output = Command::new("git")
|
||||||
|
.arg("-C")
|
||||||
|
.arg(format!("{}", self.local_path.as_ref().unwrap().display()))
|
||||||
|
.arg("push")
|
||||||
|
.arg("--mirror")
|
||||||
|
.arg(remote)
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = str::from_utf8(&output.stderr)?;
|
||||||
|
let code = output
|
||||||
|
.status
|
||||||
|
.code()
|
||||||
|
.unwrap_or_else(|| output.status.signal().unwrap());
|
||||||
|
|
||||||
|
bail!(
|
||||||
|
"couldn't update remote {}: exit code {}, stderr:\n{}",
|
||||||
|
remote,
|
||||||
code,
|
code,
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue