I am working on a project where I want to add different reviewers for different branch of my repository.
I generally add reviewers with this command:
git push --receive-pack='git receive-pack --reviewer=abc.def --reviewer=john.doe' origin HEAD:refs/for/<branch_name>
Since I use powershell terminal I wrote few scripts to ease my work. How can I add different reviewers group dynamically based on my current repository branch?
So far my powershell function look like this...
$BranchReviewerMap = @{
'devO' = "'git receive-pack --reviewer=abc.def --reviewer=efg.hij'"
'devI' = "'git receive-pack --reviewer=m.ks --reviewer=t.ch --reviewer=imt.h'"
'devT' = "'git receive-pack --reviewer=m.ks --reviewer=t.ch --reviewer=ay.an'"
'test' = "'git receive-pack --reviewer=m.ks'"
}
function mkb_git_push {
[CmdletBinding()]
param (
[ValidateSet("merge", "commit", "test")]
[String] $commit_type = "commit"
)
$default_commit = "commit"
$test_commit = "test"
Clear-Host
# ===========>>> Please ignore below parts. These are working just fine <<<=========== #
# Get Current branch
$cur_branch = git branch --show-current
# Some other calculation and logic, which works.
# ===========>>> Please ignore above parts. These are working just fine <<<=========== #
#Not able to make it work. Tried both from below two lines.
$reviewer = [String] $BranchReviewerMap[$cur_branch]
#$reviewer = $BranchReviewerMap[$cur_branch]
git push --receive-pack=$reviewer origin HEAD:refs/for/$cur_branch
}
The error I get is..
fatal: Gerrit Code Review: $reviewer: not found fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I am not looking for any if()-else if()-else type solution.
FYI: This is my first post on. Kindly ignore my mistakes on the post.