Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(submit): print submit status for each commit individually #1311

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion git-branchless-lib/src/core/eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ INSERT INTO event_log VALUES (
///
/// Returns: All the events in the database, ordered from oldest to newest.
#[instrument]

pub fn get_events(&self) -> eyre::Result<Vec<Event>> {
let mut stmt = self.conn.prepare(
"
Expand Down
40 changes: 29 additions & 11 deletions git-branchless-submit/src/branch_forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use lib::try_exit_code;
use lib::util::{ExitCode, EyreExitOr};
use tracing::{instrument, warn};

use crate::{CommitStatus, CreateStatus, Forge, SubmitOptions, SubmitStatus};
use crate::{CommitStatus, CreateStatus, Forge, SubmitOptions, SubmitStatus, UpdateStatus};

#[derive(Debug)]
pub struct BranchForge<'a> {
Expand Down Expand Up @@ -253,7 +253,7 @@ These remotes are available: {}",
commit_status.local_commit_name.map(|local_commit_name| {
(
commit_oid,
CreateStatus {
CreateStatus::Created {
final_commit_oid: commit_oid,
local_commit_name,
},
Expand All @@ -269,20 +269,20 @@ These remotes are available: {}",
&mut self,
commits: HashMap<NonZeroOid, CommitStatus>,
_options: &SubmitOptions,
) -> EyreExitOr<()> {
let branches_by_remote: BTreeMap<String, BTreeSet<String>> = commits
.into_values()
.flat_map(|commit_status| match commit_status {
) -> EyreExitOr<HashMap<NonZeroOid, UpdateStatus>> {
let branches_by_remote: BTreeMap<String, BTreeSet<(String, NonZeroOid)>> = commits
.into_iter()
.flat_map(|(commit_oid, commit_status)| match commit_status {
CommitStatus {
submit_status: _,
remote_name: Some(remote_name),
local_commit_name: Some(local_commit_name),
remote_commit_name: _,
} => Some((remote_name, local_commit_name)),
} => Some((remote_name, (local_commit_name, commit_oid))),
commit_status => {
warn!(
?commit_status,
"Commit was requested to be updated, but it did not have the requisite information (remote name, local branch name)."
"Commit was requested to be updated, but it did not have an associated remote and a local commit name"
);
None
}
Expand All @@ -299,24 +299,42 @@ These remotes are available: {}",
.values()
.map(|branch_names| branch_names.len())
.sum();
let mut result = HashMap::new();
progress.notify_progress(0, total_num_branches);
for (remote_name, branch_names) in branches_by_remote {
let mut args = vec!["push", "--force-with-lease", &remote_name];
args.extend(branch_names.iter().map(|s| s.as_str()));
args.extend(
branch_names
.iter()
.map(|(branch, _commit_oid)| branch.as_str()),
);
match self.git_run_info.run(&effects, Some(event_tx_id), &args)? {
Ok(()) => {}
Err(exit_code) => {
writeln!(
effects.get_output_stream(),
"Failed to push branches: {}",
branch_names.into_iter().join(", ")
branch_names
.iter()
.map(|(branch, _commit_oid)| branch)
.join(", ")
)?;
return Ok(Err(exit_code));
}
}
progress.notify_progress_inc(branch_names.len());

// FIXME: report push errors
result.extend(branch_names.iter().map(|(branch, commit_oid)| {
(
*commit_oid,
UpdateStatus::Updated {
local_commit_name: branch.to_owned(),
},
)
}));
}

Ok(Ok(()))
Ok(Ok(result))
}
}
25 changes: 20 additions & 5 deletions git-branchless-submit/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use tracing::warn;

use crate::branch_forge::BranchForge;
use crate::SubmitStatus;
use crate::UpdateStatus;
use crate::{CommitStatus, CreateStatus, Forge, SubmitOptions};

/// Testing environment variable. When this is set, the executable will use the
Expand Down Expand Up @@ -298,7 +299,7 @@ impl Forge for GithubForge<'_> {
.copied()
.map(|(commit_oid, commit_status)| {
let commit_status = match created_branches.get(&commit_oid) {
Some(CreateStatus {
Some(CreateStatus::Created {
final_commit_oid: _,
local_commit_name,
}) => CommitStatus {
Expand All @@ -309,7 +310,9 @@ impl Forge for GithubForge<'_> {
// Expecting this to be the same as the local branch name (for now):
remote_commit_name: Some(local_commit_name.clone()),
},
None => commit_status.clone(),
Some(CreateStatus::Skipped { .. } | CreateStatus::Err { .. }) | None => {
commit_status.clone()
}
};
(commit_oid, commit_status)
})
Expand Down Expand Up @@ -368,7 +371,7 @@ impl Forge for GithubForge<'_> {
&mut self,
commit_statuses: HashMap<NonZeroOid, CommitStatus>,
options: &SubmitOptions,
) -> EyreExitOr<()> {
) -> EyreExitOr<HashMap<NonZeroOid, UpdateStatus>> {
let effects = self.effects;
let SubmitOptions {
create: _,
Expand All @@ -392,6 +395,7 @@ impl Forge for GithubForge<'_> {

let commit_set: CommitSet = commit_statuses.keys().copied().collect();
let commit_oids = self.dag.sort(&commit_set)?;
let mut result = HashMap::new();
{
let (effects, progress) = effects.start_operation(OperationType::UpdateCommits);
progress.notify_progress(0, commit_oids.len());
Expand Down Expand Up @@ -472,7 +476,7 @@ impl Forge for GithubForge<'_> {
branch_forge.update(singleton(&commit_statuses, commit_oid, |x| x), options)?
);

// Update metdata:
// Update metadata:
try_exit_code!(self.client.update_pull_request(
&effects,
pull_request_info.number,
Expand All @@ -485,10 +489,21 @@ impl Forge for GithubForge<'_> {
options
)?);
progress.notify_progress_inc(1);

// FIXME: report push/update errors
result.insert(
commit_oid,
UpdateStatus::Updated {
local_commit_name: commit_status
.local_commit_name
.clone()
.unwrap_or_else(|| commit_oid.to_string()),
},
);
}
}

Ok(Ok(()))
Ok(Ok(result))
}
}

Expand Down
Loading
Loading