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