Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ## ----------------------------------------------------------------------- |
| 3 | ## Intent: Construct gerrit server queries and URLs based on arguments |
| 4 | ## ----------------------------------------------------------------------- |
| 5 | |
| 6 | { # loader |
| 7 | declare pgm='' |
| 8 | pgm="$(realpath --canonicalize-existing "$0")" |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 9 | readonly pgm |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 10 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 11 | declare libdir="${pgm%/*}" |
| 12 | libdir="${libdir%/*}/gerrit" |
| 13 | readonly libdir |
| 14 | |
| 15 | declare root='' |
| 16 | root="${pgm%%/gerrit/bin/gerrit.sh}" |
| 17 | source "$root/lf/onf-common/common.sh" '--common-args-begin--' |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | declare -g serv='gerrit.opencord.org' |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 24 | declare -x -g BROWSER="${BROWSER:-/usr/local/bin/firefox}" |
| 25 | declare -g -a me=() |
| 26 | |
| 27 | ##--------------------## |
| 28 | ##---] INCLUDES [---## |
| 29 | ##--------------------## |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 30 | source "${libdir}/filters/include.sh" |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 31 | source "${libdir}/usage/include.sh" |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 32 | |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 33 | ## -------------------------------------------------------------------- |
| 34 | ## -------------------------------------------------------------------- |
| 35 | function error() |
| 36 | { |
| 37 | cat <<ERROR |
| 38 | |
| 39 | ** ----------------------------------------------------------------------- |
| 40 | ** IAM: ${FUNCNAME[1]} |
| 41 | ** ERROR: $@ |
| 42 | ** ----------------------------------------------------------------------- |
| 43 | ERROR |
| 44 | echo |
| 45 | exit 1 |
| 46 | } |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 47 | |
| 48 | ## ----------------------------------------------------------------------- |
| 49 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 50 | # function join_by_orig() |
| 51 | function join_by() |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 52 | { |
| 53 | local d=${1-} f=${2-}; if shift 2; then printf %s "$f" "${@/#/$d}"; fi; |
| 54 | } |
| 55 | |
| 56 | ## ----------------------------------------------------------------------- |
| 57 | ## Usage: $0 --repo voltha-go --search --wip |
| 58 | ## ----------------------------------------------------------------------- |
| 59 | function do_gerrit_search() |
| 60 | { |
| 61 | local -n ref_urls=$1 ; shift |
| 62 | local -n ref_repos=$1 ; shift |
| 63 | local -n ref_status=$1 ; shift |
| 64 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 65 | ref_urls=() |
| 66 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 67 | # local stem='https://gerrit.opencord.org/q/project:voltha-go+status:open' |
| 68 | local stem='https://gerrit.opencord.org/q/' |
| 69 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 70 | local -a common=() |
| 71 | [[ -v me ]] && { common+=("${me[@]}"); } |
| 72 | common+=("${ref_status[@]}") |
| 73 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 74 | local repo |
| 75 | for repo in "${ref_repos[@]}"; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 76 | do |
| 77 | local -a args=() |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 78 | args+=("project:${repo}") |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 79 | args+=("${common[@]}") |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 80 | |
| 81 | local url="$stem" |
| 82 | url+="$(join_by '+' "${args[@]}")" |
| 83 | ref_urls+=("$url") |
| 84 | done |
| 85 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 86 | if [[ ${#ref_urls[@]} -eq 0 ]]; then |
| 87 | local -a args=() |
| 88 | args=("${common[@]}") |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 89 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 90 | local url="$stem" |
| 91 | url+="$(join_by '+' "${args[@]}")" |
| 92 | ref_urls+=("$url") |
| 93 | fi |
| 94 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 95 | # --debug) declare -g -i debug=1 ;; |
| 96 | # --search) declare -g -i search=1 ;; |
| 97 | # --wip) declare -g -i status_is_open=1 ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 98 | |
| 99 | return |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 102 | ## ----------------------------------------------------------------------- |
| 103 | ## Usage: $0 --status open --reviewer [u] |
| 104 | ## ----------------------------------------------------------------------- |
| 105 | function do_gerrit_review() |
| 106 | { |
| 107 | local -n ref_urls=$1 ; shift |
| 108 | local -n ref_repos=$1 ; shift |
| 109 | local -n ref_status=$1 ; shift |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 110 | |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 111 | ref_urls=() |
| 112 | |
| 113 | # local stem='https://gerrit.opencord.org/q/project:voltha-go+status:open' |
| 114 | local stem='https://gerrit.opencord.org/q/' |
| 115 | |
| 116 | local -a common=() |
| 117 | [[ -v me ]] && { common+=('reviewer:self') } |
| 118 | |
| 119 | for reviewer in "${argv_reviewer[@]}"; do |
| 120 | common+=("reviewer:${reviewer}") |
| 121 | done |
| 122 | |
| 123 | local repo |
| 124 | for repo in "${ref_repos[@]}"; |
| 125 | do |
| 126 | local -a args=() |
| 127 | args+=("project:${repo}") |
| 128 | args+=("${common[@]}") |
| 129 | |
| 130 | local url="$stem" |
| 131 | url+="$(join_by '+' "${args[@]}")" |
| 132 | ref_urls+=("$url") |
| 133 | done |
| 134 | |
| 135 | ## If not repo specific then query all |
| 136 | if [[ ${#ref_urls[@]} -eq 0 ]]; then |
| 137 | local -a args=() |
| 138 | args=("${common[@]}") |
| 139 | |
| 140 | local url="$stem" |
| 141 | url+="$(join_by '+' "${args[@]}")" |
| 142 | ref_urls+=("$url") |
| 143 | fi |
| 144 | |
| 145 | # --debug) declare -g -i debug=1 ;; |
| 146 | # --search) declare -g -i search=1 ;; |
| 147 | # --wip) declare -g -i status_is_open=1 ;; |
| 148 | |
| 149 | return |
| 150 | } |
| 151 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 152 | ## ----------------------------------------------------------------------- |
| 153 | ## Intent: Iterate over --admin values and generate repositories |
| 154 | ## ----------------------------------------------------------------------- |
| 155 | function gen_admin_urls() |
| 156 | { |
| 157 | local -n ref=$1 ; shift |
| 158 | local -n _repos=$1 ; shift |
| 159 | local -n _admins=$1 ; shift |
| 160 | |
| 161 | local repo |
| 162 | for repo in "${_repos[@]}"; |
| 163 | do |
| 164 | local attr |
| 165 | for admin in "${_admins[@]}"; |
| 166 | do |
| 167 | # https://gerrit.opencord.org/admin/repos/voltha-go |
| 168 | case "$admin" in |
| 169 | branches) |
| 170 | ref+=("https://gerrit.opencord.org/admin/repos/${repo},branches") |
| 171 | ;; |
| 172 | tags) |
| 173 | ref+=("https://gerrit.opencord.org/admin/repos/${repo},tags") |
| 174 | ;; |
| 175 | *) error "Unknown --admin type [$admin]" ;; |
| 176 | esac |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 177 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 178 | done # admins[@] |
| 179 | done # repos[@] |
| 180 | return |
| 181 | } |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 182 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 183 | ## ----------------------------------------------------------------------- |
| 184 | ## Intent: Iterate over --admin values and generate repositories |
| 185 | ## ----------------------------------------------------------------------- |
| 186 | function gen_view_urls() |
| 187 | { |
| 188 | local -n ref=$1 ; shift |
| 189 | local -n _repos=$1 ; shift |
| 190 | local -n _views=$1 ; shift |
| 191 | |
| 192 | local -a view_keys=("${!_views[@]}") |
| 193 | local stem0="https://gerrit.opencord.org/plugins/gitiles" |
| 194 | |
| 195 | # https://gerrit.opencord.org/plugins/gitiles/ofagent-go |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 196 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 197 | local repo |
| 198 | for repo in "${_repos[@]}"; |
| 199 | do |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 200 | local stem="${stem0}/$repo" |
| 201 | local view |
| 202 | for view in "${view_keys[@]}"; |
| 203 | do |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 204 | # https://gerrit.opencord.org/admin/repos/voltha-go |
| 205 | case "$view" in |
| 206 | # https://gerrit.opencord.org/plugins/gitiles/voltha-system-tests |
| 207 | search) continue ;; |
| 208 | default) ref+=("$stem") ;; |
| 209 | # repo*) ref+=("$stem/$repo") ;; |
| 210 | repo*) ref+=("$stem") ;; |
| 211 | master) |
| 212 | ref+=("$stem/+/refs/heads/master") |
| 213 | ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 214 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 215 | voltha-*) |
| 216 | echo "STEM: $stem" |
| 217 | if false; then |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 218 | ref+=("$stem/+/refs/tags/${view}") |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 219 | ref+=("$stem/+/refs/heads/${view}") |
| 220 | fi |
| 221 | # ref+=("$stem/+/refs/heads/${view}") |
| 222 | ref+=("$stem/+/refs/heads/${view}") |
| 223 | ;; |
| 224 | |
| 225 | v*) ref+=("$stem/+/refs/tags/${view}") ;; |
| 226 | *) error "Unknown --view type [$view]" ;; |
| 227 | esac |
| 228 | done # views[@] |
| 229 | done # repos[@] |
| 230 | |
| 231 | for r in "${ref[@]}"; |
| 232 | do |
| 233 | echo "REPO: $r" |
| 234 | done |
| 235 | |
| 236 | return |
| 237 | } |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 238 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 239 | ## ----------------------------------------------------------------------- |
| 240 | ## ----------------------------------------------------------------------- |
| 241 | function get_urls() |
| 242 | { |
| 243 | local -n ref="$1"; shift |
| 244 | local _srv="$1"; shift |
| 245 | |
| 246 | local gerrit="https://${_srv}" |
| 247 | ref=(\ |
| 248 | ['admin']="$gerrit/admin/repos" |
| 249 | ['base']="$gerrit"\ |
| 250 | ['dashboard']="$gerrit/dashboard/self"\ |
| 251 | ) |
| 252 | return |
| 253 | } |
| 254 | |
| 255 | ## ----------------------------------------------------------------------- |
| 256 | ## ----------------------------------------------------------------------- |
| 257 | function changeset() |
| 258 | { |
| 259 | local _repo="$1"; shift |
| 260 | local _id="$1"; shift |
| 261 | local -n ref=$1; shift |
| 262 | |
| 263 | local url="https://gerrit.opencord.org/c/${repo}/+/${id}" |
| 264 | ref+=("$url") |
| 265 | return |
| 266 | } |
| 267 | |
| 268 | ## ----------------------------------------------------------------------- |
| 269 | ## ----------------------------------------------------------------------- |
| 270 | function browse() |
| 271 | { |
| 272 | local -n _urls=$1; shift |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 273 | "${BROWSER}" "${_urls[@]}" >/dev/null 2>/dev/null & |
| 274 | return |
| 275 | } |
| 276 | |
| 277 | ## ----------------------------------------------------------------------- |
| 278 | ## ----------------------------------------------------------------------- |
| 279 | function access_url() |
| 280 | { |
| 281 | local -n ref=$1; shift |
| 282 | local _repo="$1"; shift |
| 283 | |
| 284 | declare -A data=() |
| 285 | get_urls data "$serv" |
| 286 | |
| 287 | # declare -p data | tr '=' '\n' |
| 288 | # ref+=("https://gerrit.opencord.org/admin/repos/${_repo},access") |
| 289 | ref+=("${data['admin']}/${_repo},access") |
| 290 | |
| 291 | # browse urls |
| 292 | return |
| 293 | } |
| 294 | |
| 295 | ## ----------------------------------------------------------------------- |
| 296 | ## ----------------------------------------------------------------------- |
| 297 | function branch_url() |
| 298 | { |
| 299 | local _repo="$1"; shift |
| 300 | local -a urls=() |
| 301 | urls+=("https://gerrit.opencord.org/admin/repos/${_repo},branches") |
| 302 | browse urls |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | ## ----------------------------------------------------------------------- |
| 307 | ## ----------------------------------------------------------------------- |
| 308 | function do_gerrit_dashboard() |
| 309 | { |
| 310 | local -n ref=$1; shift |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 311 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 312 | declare -A data=() |
| 313 | get_urls data "$serv" |
| 314 | ref+=("${data['dashboard']}") |
| 315 | return |
| 316 | } |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 317 | |
| 318 | # https://gerrit.opencord.org/q/status:open+-is:wip |
| 319 | |
| 320 | # repo='' |
| 321 | declare -a urls=() |
| 322 | |
| 323 | ##----------------## |
| 324 | ##---] MAIN [---## |
| 325 | ##----------------## |
| 326 | [[ $# -eq 0 ]] && { set -- '--help'; } |
| 327 | |
| 328 | while [ $# -ne 0 ]; do |
| 329 | arg="$1"; shift |
| 330 | case "$arg" in |
| 331 | --help) usage; exit 0 ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 332 | --help-*) |
| 333 | case "$arg" in |
| 334 | --help-status) usage_verbose "$arg" ;; |
| 335 | *) usage ;; |
| 336 | esac |
| 337 | exit 0 |
| 338 | ;; |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 339 | |
| 340 | ## Modes |
| 341 | --debug) |
| 342 | declare -g -i argv_debug=1 |
| 343 | declare -g -i debug=1 |
| 344 | ;; |
| 345 | --search) declare -g -i argv_search=1 ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 346 | |
| 347 | --me) |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 348 | declare -g -i argv_me=1 |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 349 | me+=("owner:${USER}@opennetworking.org") |
| 350 | ;; |
| 351 | |
| 352 | --todo) source "$root/gerrit/todo.sh" ;; |
| 353 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 354 | --wip) |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 355 | declare -a args=() |
| 356 | args=('--status' 'open') |
| 357 | [[ $# -gt 0 ]] && { args+=("$@"); } |
| 358 | set -- "${args[@]}" |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 359 | ;; |
| 360 | |
| 361 | --admin) |
| 362 | [[ ! -v admins ]] && { declare -a admins=(); } |
| 363 | arg="$1"; shift |
| 364 | case "$arg" in |
| 365 | br*) admins+=('branches') ;; |
| 366 | ta*) admins+=('tags') ;; |
| 367 | *) error "Unknown --attr value [$attr]" ;; |
| 368 | ## Also master and voltha-2.12 |
| 369 | # https://gerrit.opencord.org/plugins/gitiles/voltha-go/+/refs/heads/voltha-2.12 |
| 370 | esac |
| 371 | ;; |
| 372 | |
| 373 | --all) |
| 374 | repo="$1"; shift |
| 375 | declare -a args=() |
| 376 | args+=('--repo' "$repo") |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 377 | # |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 378 | args+=('--admin' 'branches') |
| 379 | args+=('--admin' 'tags') |
| 380 | |
| 381 | # args+=('--view') # post getopts expansion |
| 382 | # if @versions() else master |
| 383 | if [[ ${#versions[@]} -eq 0 ]]; then |
| 384 | versions+=('master') |
| 385 | fi |
| 386 | |
| 387 | # args+=('--view' 'voltha-2.11') |
| 388 | args+=('--view' 'voltha-2.12') |
| 389 | set -- "${args[@]}" "$@" |
| 390 | ;; |
| 391 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 392 | --repo) |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 393 | repo="$1"; shift |
| 394 | [[ ! -v repos ]] && { declare -a repos=(); } |
| 395 | repos+=("$repo") |
| 396 | ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 397 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 398 | --serv) serv="$1"; shift |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 399 | case "$serv" in |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 400 | *cord*) serv='gerrit.opencord.org' ;; |
| 401 | *onos*) serv='gerrit.onosproject.org' ;; |
| 402 | *) error "Detected invalid --serv $serv" ;; |
| 403 | esac |
| 404 | ;; |
| 405 | |
| 406 | --access) |
| 407 | [[ ! -v repo ]] && { error "--repo is required"; } |
| 408 | access_url urls "$repo" |
| 409 | ;; |
| 410 | |
| 411 | --branch) |
| 412 | [[ ! -v repo ]] && { error "--repo is required"; } |
| 413 | branch_url "$repo" |
| 414 | ;; |
| 415 | |
| 416 | --crowd*) |
| 417 | # https://crowd.opennetworking.org/crowd/console/secure/group/browse.action?directoryId=163841&updateSuccessful= |
| 418 | declare https='https://crowd.opennetworking.org' |
| 419 | declare base_url="${https}/crowd/console/secure/group/browse.action" |
| 420 | case "$arg" in |
| 421 | --crowd-*) |
| 422 | # urls+=("${base_url}?directoryId=163841&updateSuccessful=") |
| 423 | urls+=("${base_url}") |
| 424 | ;; |
| 425 | *) |
| 426 | # https://crowd.opennetworking.org/crowd/console/secure/group/browse.action?search=%22VOLTHACore%22 |
| 427 | [[ $# -eq 0 ]] && { error "--crowd requires an argument"; } |
| 428 | arg="$1"; shift |
| 429 | urls+=("${base_url}?search=%22${arg}%22") |
| 430 | ;; |
| 431 | esac |
| 432 | ;; |
| 433 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 434 | --*desk) error "Try --dashboard instead" ;; |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 435 | --dash*) do_gerrit_dashboard urls ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 436 | |
| 437 | # |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 438 | --group*) |
| 439 | case "$arg" in |
| 440 | --group*) |
| 441 | urls+=("https://${serv}/admin/groups") |
| 442 | ;; |
| 443 | *) |
| 444 | [[ $# -eq 0 ]] && { error "--group requires an argument"; } |
| 445 | arg="$1"; shift |
| 446 | urls+=("https://${serv}/admin/groups/q/filter:${arg}}") |
| 447 | ;; |
| 448 | esac |
| 449 | ;; |
| 450 | |
| 451 | --id) |
| 452 | id="$1"; shift |
| 453 | [[ ${#repo} -eq 0 ]] && { error "--repo is required"; } |
| 454 | changeset "$repo" "$id" urls |
| 455 | ;; |
| 456 | |
| 457 | --status) |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 458 | arg="$1"; shift # open, closed, merged |
| 459 | case "$arg" in |
| 460 | closed|open|merged) add_filter_status "$arg";; |
| 461 | *) error "Detected invalid --status [$arg]" ;; |
| 462 | esac |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 463 | ;; |
| 464 | |
| 465 | --patch*) |
| 466 | repo="$1"; shift |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 467 | urls+=("https://gerrit.opencord.org/q/${repo}+status:open") |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 468 | # https://gerrit.opencord.org/q/voltha-openolt-adapter-go |
| 469 | ;; |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 470 | |
| 471 | --reviewer) |
| 472 | arg="$1"; shift |
| 473 | add_filter_reviewer "$arg" |
| 474 | |
| 475 | declare -g -i argv_review=1 |
| 476 | # Replace with: set -- '--review' "$@" |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 477 | ;; |
| 478 | |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 479 | --review) declare -g -i argv_review=1 ;; |
| 480 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 481 | --ver*) |
| 482 | [[ $# -eq 0 ]] && { error "Usage: $arg [str]"; } |
| 483 | arg="$1"; shift |
| 484 | [[ ! -v versions ]] && { declare -a versions=(); } |
| 485 | versions+=("$arg") |
| 486 | ;; |
| 487 | |
| 488 | # post getopt expansion to support --version x --version y |
| 489 | --view) |
| 490 | [[ $# -eq 0 ]] && { set -- '--default'; } |
| 491 | arg="$1"; shift |
| 492 | # [[ "${#views[@]}" -gt 0 ]] |
| 493 | [[ ! -v views ]] && { declare -A views=(); } |
| 494 | case "$arg" in |
| 495 | |
| 496 | search*) |
| 497 | urls+=('https://gerrit.opencord.org/admin/repos') |
| 498 | ;; |
| 499 | |
| 500 | repo) views['repository']=1 ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 501 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 502 | # https://gerrit.opencord.org/plugins/gitiles/voltha-go |
| 503 | master) views['master']=1 ;; |
| 504 | voltha*) views["$arg"]=1 ;; |
| 505 | v*) views["$arg"]=1 ;; |
| 506 | *) |
| 507 | # Missing latest tags |
| 508 | views['default']=1 |
| 509 | views['master']=1 |
| 510 | ;; |
| 511 | esac |
| 512 | ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 513 | |
| 514 | -*) |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 515 | echo "ERROR: Unknown argument [$arg]" |
| 516 | exit 1 |
| 517 | ;; |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 518 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 519 | [[:alnum:]]*) |
| 520 | declare -a what=() |
| 521 | # whats+=('patches') |
| 522 | whats+=('versions') |
| 523 | |
| 524 | stem="https://gerrit.opencord.org/q/${arg}" |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 525 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 526 | for what in "${whats[@]}"; |
| 527 | do |
| 528 | case "$what" in |
| 529 | patches) urls+=("https://gerrit.opencord.org/q/${arg}") ;; |
| 530 | versions) |
| 531 | urls+=("https://gerrit.opencord.org/plugins/gitiles/${arg}/+/refs/heads/master/VERSION") |
| 532 | # urls+=("https://gerrit.opencord.org/plugins/gitiles/${arg}/+/refs/tags/v0.3.6/VERSION") |
| 533 | urls+=("https://gerrit.opencord.org/plugins/gitiles/${arg}/+/refs/heads/voltha-2.12/VERSION") |
| 534 | ;; |
| 535 | '??') urls+=("https://gerrit.opencord.org/plugins/gitiles/${arg}") ;; |
| 536 | *) urls+=("https://gerrit.opencord.org/q/${arg}") ;; |
| 537 | esac |
| 538 | done |
| 539 | esac |
| 540 | done |
| 541 | |
Joey Armstrong | c5542fa | 2024-03-25 11:49:47 -0400 | [diff] [blame^] | 542 | [[ -v argv_search ]] && { do_gerrit_search urls repos argv_status; } |
| 543 | [[ -v admins ]] && { gen_admin_urls urls repos admins; } |
| 544 | |
| 545 | # ----------------------------------------------------------------------- |
| 546 | # Generalize: |
| 547 | # o --review function like a simple search filter. |
| 548 | # o piece missing is defining query URL stem= when needed. |
| 549 | # ----------------------------------------------------------------------- |
| 550 | [[ -v argv_review ]] && { do_gerrit_review urls repos argv_status; } |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 551 | |
| 552 | ## are --views working ? |
| 553 | [[ "${#views[@]}" -gt 0 ]] && { gen_view_urls urls repos views; } |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 554 | |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 555 | if [[ ${#urls[@]} -eq 0 ]]; then |
| 556 | declare -a show_all=() # show all for visiblity |
| 557 | do_gerrit_search urls repos show_all |
| 558 | fi |
| 559 | |
| 560 | |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 561 | [[ -v debug ]] && { echo "$BROWSER" "${urls[@]}"; } |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 562 | |
| 563 | if [[ ${#urls[@]} -gt 0 ]]; then |
| 564 | apply_filter_status urls |
| 565 | browse urls |
| 566 | fi |
Joey Armstrong | dc364a1 | 2024-02-29 15:14:11 -0500 | [diff] [blame] | 567 | |
| 568 | ## ----------------------------------------------------------------------- |
| 569 | ## [TODO] |
| 570 | ## Query patches by repo:voltha-lib-go |
| 571 | ## ssh gerrit.opencord.org gerrit query --patch-sets projects:voltha-lib-go | grep -i description |
| 572 | # ssh gerrit.opencord.org gerrit query --patch-sets 'projects:voltha-lib-go AND status:open limit:2' | |
| 573 | |
| 574 | # Show URL and Commit message |
| 575 | # ssh gerrit.opencord.org gerrit query --format=JSON --patch-sets 'projects:voltha-lib-go AND status:open limit:2' | jq '.url,.commitMessage' |
| 576 | ## ----------------------------------------------------------------------- |
| 577 | |
| 578 | # [EOF] |
Joey Armstrong | 76f861a | 2024-03-13 16:01:24 -0400 | [diff] [blame] | 579 | |
| 580 | |
| 581 | # 1) gerrit.sh --search --me --wip |
| 582 | # query> owner:joey@opennetworking.org status:open |
| 583 | |
| 584 | # --search --me |
| 585 | # args+=("owner:${USER}@opennetworking.org") |
| 586 | |
| 587 | # --wip) |
| 588 | # argv_status+=('status:open') |
| 589 | # ;; |
| 590 | |
| 591 | |
| 592 | # [EOF] |