Skip to content

Commit

Permalink
Add remote name & remote url to request_review_post_sync hook args
Browse files Browse the repository at this point in the history
Add remote name & remote url to request_review_post_sync hook args so
that the hook implementers can use that information to implement hooks
in a more generic fashion.

One use case this specifically aids is when dealing with multiple patch
stacks associated with different remotes. It allows you to implement
hooks in a fashion that your commands can interact with the remote
associated with the upstream branch that the patch is associated with.
In turn enabling the hook to be patch stack/remote aware.

skip_ticket_id_check

[changelog]
added: remote name & remote url to request_review_post_sync hook args

<!-- ps-id: 12387a02-0b03-40e1-a505-66f072873634 -->
  • Loading branch information
drewdeponte committed Jun 21, 2023
1 parent 2d0e1d2 commit c2376fe
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/ps/public/request_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum RequestReviewError {
FindRemoteRequestReviewBranchFailed(git2::Error),
GetRemoteCommitFailed(git2::Error),
RemoteCommitDiffPatchIdFailed(git::CommitDiffPatchIdError),
FindRemoteFailed(git2::Error),
RemoteUrlNotUtf8,
}

impl From<hooks::FindHookError> for RequestReviewError {
Expand Down Expand Up @@ -100,6 +102,10 @@ impl fmt::Display for RequestReviewError {
Self::RemoteCommitDiffPatchIdFailed(e) => {
write!(f, "Failed to get remote commit's diff patch id - {:?}", e)
}
Self::RemoteUrlNotUtf8 => write!(f, "Failed to process remote url as it is NOT utf8"),
Self::FindRemoteFailed(e) => {
write!(f, "Failed to find remote - {:?}", e)
}
}
}
}
Expand Down Expand Up @@ -153,6 +159,13 @@ pub fn request_review(
let remote_name = repo
.branch_remote_name(&branch_upstream_name)
.map_err(|_| RequestReviewError::GetRemoteNameFailed)?;
let remote_name_str = remote_name
.as_str()
.ok_or(RequestReviewError::BranchNameNotUtf8)?;
let remote = repo
.find_remote(remote_name_str)
.map_err(RequestReviewError::FindRemoteFailed)?;
let remote_url_str = remote.url().ok_or(RequestReviewError::RemoteUrlNotUtf8)?;

let pattern = format!(
"refs/remotes/{}/",
Expand All @@ -162,9 +175,6 @@ pub fn request_review(
);
let upstream_branch_shorthand = str::replace(&branch_upstream_name, pattern.as_str(), "");

let remote_name_str = remote_name
.as_str()
.ok_or(RequestReviewError::BranchNameNotUtf8)?;
let remote_rr_branch = repo
.find_branch(
format!("{}/{}", remote_name_str, created_branch_name).as_str(),
Expand All @@ -185,6 +195,8 @@ pub fn request_review(
rerequesting_review(&patch_meta_data),
&created_branch_name,
&upstream_branch_shorthand,
&remote_name_str,
&remote_url_str,
],
)
.map_err(RequestReviewError::HookExecutionFailed)?;
Expand Down

0 comments on commit c2376fe

Please sign in to comment.