-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-post-review
executable file
·62 lines (53 loc) · 1.67 KB
/
git-post-review
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -e
echo "Hey Hey! Thanks for using reviewboard! If you run into any issues, email [email protected]"
function config_exists {
value=$(git config --get $1)
if [ $? == 0 ]; then
echo "true"
else
echo "false"
fi
}
function get_config {
git config --get $1
}
function current_branch {
br=`git branch | grep "*"`
echo ${br/* /}
}
config_exists=$(config_exists reviewboard.url)
if [ "$config_exists" = "false" ]; then
echo "We need to do a little setup first"
read -p "What is the full reviewboard url e.g. https://reviewboard.mycompany.com? " url
git config reviewboard.url $url
fi
current_branch=$(current_branch)
if [ "$current_branch" = "master" ]; then
echo "Not a good idea to use this on master"
exit 1
fi
if [ ! -f $HOME/.post-review-cookies.txt ]; then
echo "You don't have a ~/.post-review-cookies.txt file."
echo "You should run post-review manually once and type in your"
echo "username and password at the prompt to set your reviewboard cookie."
echo "This is on my todo list to handle more gracefully =)"
echo "Run this command:"
echo "post-review"
exit 1
fi
config_exists=$(config_exists reviewboardids.$current_branch)
if [ "$config_exists" = "true" ]; then
review_id=$(get_config reviewboardids.$current_branch)
echo "Using existing review found for this branch: $review_id"
post-review --parent master -d -o -r $review_id
else
log=$(post-review --parent master -g -o -d)
echo "$log"
review_line=$(echo "$log" | tail -3 | head -1)
review_line=${review_line/Review request #/}
review_line=${review_line/ posted./}
review_id=$review_line
git config reviewboardids.$current_branch $review_id
fi
echo "Done. Success."