-
Notifications
You must be signed in to change notification settings - Fork 18
/
glBranches.sh
executable file
·165 lines (146 loc) · 4.28 KB
/
glBranches.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
function display_usage {
echo "Usage: $0
Get branches configuration (ALPHA)
$0 --config --id PROJECT_ID [ --name BRANCH_NAME]
" >&2
exit 100
}
function ensure_action_empty {
local action=$1
ensure_empty "${action}" "action already define: '${action}'"
}
function main {
local action=
local project_id=
local branch_name=
while [[ $# -gt 0 ]]; do
param="$1"
shift
case "${param}" in
--config)
ensure_action_empty "${action}"
action=showConfigAction
;;
--create)
ensure_action_empty "${action}"
action=createAction
;;
--delete)
ensure_action_empty "${action}"
action=deleteAction
;;
--edit)
ensure_action_empty "${action}"
action=editAction
;;
-i|--id|--project-id)
project_id="$1"
shift
;;
--list-path)
ensure_action_empty "${action}"
action=listPathsAction
;;
--list-id)
ensure_action_empty "${action}"
action=listIdsAction
;;
--membership_lock)
param_group_membership_lock="$1"
shift
ensure_boolean "${param_group_membership_lock}" '--membership_lock'
;;
-n|--name)
branch_name="$1"
shift
;;
--path)
param_group_path="$1"
shift
;;
--request_access_enabled)
param_group_request_access_enabled="$1"
shift
ensure_boolean "${param_group_request_access_enabled}" '--request_access_enabled'
;;
--share_with_group_lock)
param_group_share_with_group_lock="$1"
shift
ensure_boolean "${param_group_share_with_group_lock}" '--share_with_group_lock'
;;
--visibility)
param_group_visibility="$1"
shift
case "${param_group_visibility}" in
private|internal|public)
;;
*)
echo "Illegal value '${param_group_visibility}'. --visibility should be private, internal or public." >&2
display_usage
;;
esac
;;
*)
# unknown option
echo "Unknown parameter ${param}" >&2
display_usage
;;
esac
done
case "${action}" in
createAction)
ensure_not_empty param_group_path
create_group_handle_params "${param_group_path}" "${param_group_name}" "${param_group_description}" \
"${param_group_lfs_enabled}" "${param_group_membership_lock}" "${param_group_request_access_enabled}" \
"${param_group_share_with_group_lock}" "${param_group_visibility}" \
| jq .
;;
deleteAction)
ensure_not_empty param_group_id
delete_group "${param_group_id}" \
| jq .
;;
editAction)
ensure_not_empty param_group_id
ensure_not_empty param_group_name
ensure_not_empty param_group_path
ensure_not_empty param_group_visibility
edit_group "${param_group_id}" "${param_group_name}" "${param_group_path}" \
"${param_group_description_define}" "${param_group_description}" \
"${param_group_visibility}" "${param_group_lfs_enabled}" "${param_group_request_access_enabled}" \
| jq .
;;
listPathsAction)
list_groups_paths_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}"
;;
listIdsAction)
list_groups_ids_handle_params "${param_all_groups}" "${param_group_id}" "${param_group_path}"
;;
showConfigAction)
list_branches "${project_id}" "${branch_name}" | jq .
;;
*)
# unknown option
echo "Missing --config, --list-name, --list-id, --edit or --delete" >&2
echo "Unexpected value for action: '${action}'" >&2
display_usage
;;
esac
}
# Configuration - BEGIN
if [ -z "$GITLAB_BASH_API_PATH" ]; then
GITLAB_BASH_API_PATH=$(dirname "$(realpath "$0")")
fi
if [ ! -f "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh" ]; then
echo "gitlab-bash-api.sh not found! - Please set GITLAB_BASH_API_PATH" >&2
exit 1
fi
source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api.sh"
# Configuration - END
# Script start here
source "${GITLAB_BASH_API_PATH}/api/gitlab-bash-api-branch.sh"
if [ $# -eq 0 ]; then
display_usage
fi
main "$@"