-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-request.sh
executable file
·111 lines (94 loc) · 2.35 KB
/
merge-request.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash -e
# @installable
MYSELF="$(readlink -f "$0")"
MYDIR="${MYSELF%/*}"
ME=$(basename $MYSELF)
source $MYDIR/env
[[ -f $LOCAL_ENV ]] && source $LOCAL_ENV
source $MYDIR/log.sh
source $MYDIR/db.sh
wip=false
description="auto generated by gclit"
info "merge request..."
debug "options: $@"
if [[ $# -gt 0 && "$1" != '-'* ]]; then
# message was passed directly as first arg with no prefix
message="$1"
shift
fi
while test $# -gt 0
do
case "$1" in
--message|-m)
shift
message="$1"
;;
--wip)
wip=true
;;
--label)
shift
label="$1"
;;
--description|-d)
shift
description="$1"
;;
--target)
shift
target="$1"
;;
-*)
echo "bad option '$1'"
exit 1
;;
esac
shift
done
if [[ ! -n "$(curr_branch)" ]]; then
err "you have to be inside the repository directory"
branchd="$(db CURR_FEATURE_DIR)"
if [[ -d "$branchd" ]]; then
info "maybe you want to go to $branchd ?"
fi
exit 1
fi
[[ -z "$target" ]] && target=$(curr_branch)
info "target branch: $target"
name="$(db CURR_FEATURE)"
if [[ ! -n "$name" ]]; then
err "you're not working on any features, make sure to start one with gclit-feature"
exit 1
fi
while [[ -z "$label" ]]; do
if [[ -n "$DEFAULT_MR_LABEL" ]]; then
label="$DEFAULT_MR_LABEL"
else
info "choose merge request label:"
read label
fi
done
info "#$label - creating request to merge back to $target ..."
git checkout $name
while [[ ! -n "$message" ]]; do
info "${name}'s MR message (new line then ctrl+d to finish):"
readarray -t msg
message=$(printf '%s\n' "${msg[@]}")
done
debug "MR message: '$message'"
if [[ $wip == true ]]; then
message="[WIP] $message"
info "WIP prefix added"
fi
# TODO merge request is not opened if all changes are already pushed
# https://docs.gitlab.com/ee/user/project/push_options.html
# TODO redirecionar todo output e grep 'remote: View merge request for' e já abrir o link localmente
git push \
-o merge_request.create \
-o merge_request.target=$target \
-o merge_request.remove_source_branch \
-o merge_request.title="$message" \
-o merge_request.description="$description" \
-o merge_request.label="$label"
debug "mr comment"
$MYDIR/rr-comment.sh "opened MR to $target" || true