gerrit: add age query args

Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
Change-Id: I4c01d5c40d427506de9b6c45b9392ffeb5dacc37
diff --git a/gerrit/bin/gerrit.sh b/gerrit/bin/gerrit.sh
index 4e51869..b12d0bf 100755
--- a/gerrit/bin/gerrit.sh
+++ b/gerrit/bin/gerrit.sh
@@ -55,52 +55,6 @@
 }
 
 ## -----------------------------------------------------------------------
-## Usage: $0 --repo voltha-go --search --wip
-## -----------------------------------------------------------------------
-function do_gerrit_search_orig()
-{
-    local -n ref_urls=$1   ; shift
-    local -n ref_repos=$1   ; shift
-    local -n ref_status=$1 ; shift
-
-    ref_urls=()
-
-    # local stem='https://gerrit.opencord.org/q/project:voltha-go+status:open'
-    local stem='https://gerrit.opencord.org/q/'
-
-    local -a common=()
-    [[ -v me ]] && { common+=("${me[@]}"); }
-    common+=("${ref_status[@]}")
-
-    local repo
-    for repo in "${ref_repos[@]}";
-    do
-        local -a args=()
-        args+=("project:${repo}")
-        args+=("${common[@]}")
-
-        local url="$stem"
-        url+="$(join_by '+' "${args[@]}")"
-        ref_urls+=("$url")
-    done
-
-    if [[ ${#ref_urls[@]} -eq 0 ]]; then
-        local -a args=()
-        args=("${common[@]}")
-
-        local url="$stem"
-        url+="$(join_by '+' "${args[@]}")"
-        ref_urls+=("$url")
-    fi
-
-    # --debug)  declare -g -i debug=1 ;;
-    # --search) declare -g -i search=1 ;;
-    # --wip)    declare -g -i status_is_open=1 ;;
-
-    return
-}
-
-## -----------------------------------------------------------------------
 ## Intent: Iterate over --admin values and generate repositories
 ## -----------------------------------------------------------------------
 function gen_admin_urls()
@@ -294,11 +248,30 @@
             ;;
 
         ## Modes
+        --age) # https://gerrit-review.googlesource.com/Documentation/user-search.html
+            arg="$1"; shift
+            add_filter_age "$arg"
+            ;;
+
+        ## FMT: 2006-01-02[ 15:04:05[.890][ -0700]]; 
+        --after|--since) # https://gerrit-review.googlesource.com/Documentation/user-search.html            
+            arg="$1"; shift
+            add_filter_after "$arg"
+            ;;
+
+        ## FMT: 2006-01-02[ 15:04:05[.890][ -0700]]; 
+        --before) # https://gerrit-review.googlesource.com/Documentation/user-search.html            
+            arg="$1"; shift
+            add_filter_before "$arg"
+            ;;
+
+        ## Modes
         --debug)
             # shellcheck disable=SC2034
             declare -g -i argv_debug=1
             declare -g -i debug=1
             ;;
+
         --search) declare -g -i argv_search=1 ;;
 
         --me)
diff --git a/gerrit/gerrit/do/search.sh b/gerrit/gerrit/do/search.sh
index d2fbf28..0c92574 100644
--- a/gerrit/gerrit/do/search.sh
+++ b/gerrit/gerrit/do/search.sh
@@ -43,15 +43,20 @@
         args+=("project:${repo}")
         args+=("${common[@]}")
 
+        apply_filter_age args
+
         local url="$stem"
         url+="$(join_by '+' "${args[@]}")"
         ref_urls+=("$url")
     done
 
+    # https://gerrit.opencord.org/q/status:open+after:%222024-04-24%22
     if [[ ${#ref_urls[@]} -eq 0 ]]; then
         local -a args=()
         args=("${common[@]}")
 
+        apply_filter_age args
+        
         local url="$stem"
         url+="$(join_by '+' "${args[@]}")"
         ref_urls+=("$url")
diff --git a/gerrit/gerrit/filters/age.sh b/gerrit/gerrit/filters/age.sh
new file mode 100644
index 0000000..d8376a7
--- /dev/null
+++ b/gerrit/gerrit/filters/age.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+# -----------------------------------------------------------------------
+# Copyright 2024 Open Networking Foundation Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http:#www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Update gerrit query to filter based on age
+## -----------------------------------------------------------------------
+function add_filter_age()
+{
+    local val="$1"; shift
+
+    case "$val" in
+        *y|*year*) ;;     # 1 y[ear(s)]
+        *m|*mon*)  ;;     # 1 m[onth(s)]
+        *d|*day*)  ;;     # 1 d[ay(s)]
+        *h|*hour*) ;;     # 1 h[our(s)]
+        *) error "--age [$val] is invalid" ;;
+    esac
+
+    [[ -v argv_age ]] && { error '--age: detected multiple switches'; }
+    declare -g -a argv_age=("$age")
+    return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Update gerrit query to filter based on created after date
+## FMT: 2006-01-02[ 15:04:05[.890][ -0700]]; 
+## -----------------------------------------------------------------------
+function add_filter_after()
+{
+    local val="$1"; shift
+ 
+    [[ -v argv_after ]] && { error '--after: detected multiple switches'; }
+    declare -g -a argv_after=("$arg")
+    return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Update gerrit query to filter based on created before date
+## FMT: 2006-01-02[ 15:04:05[.890][ -0700]]; 
+## -----------------------------------------------------------------------
+function add_filter_before()
+{
+    local val="$1"; shift
+ 
+    [[ -v argv_before ]] && { error '--before: detected multiple switches'; }
+    declare -g -a argv_before=("$arg")
+    return
+}
+
+## -----------------------------------------------------------------------
+## Intent: Merge status attributes into a URL query
+## -----------------------------------------------------------------------
+function apply_filter_age()
+{
+    local -n ref=$1; shift
+
+    [[ -v argv_age ]]    && { ref+=("age:\"${argv_age[@]}\""); }
+
+    [[ -v argv_after ]]  && { ref+=("after:\"${argv_after}\""); }
+    [[ -v argv_before ]] && { ref+=("before:\"${argv_before}\""); }
+
+    :
+    return
+}
+
+: # ($?==0) for source script
+
+# [EOF]
diff --git a/gerrit/gerrit/filters/include.sh b/gerrit/gerrit/filters/include.sh
index 34c84ea..ca67f2c 100644
--- a/gerrit/gerrit/filters/include.sh
+++ b/gerrit/gerrit/filters/include.sh
@@ -21,6 +21,7 @@
 ##--------------------##
 ##---]  INCLUDES  [---##
 ##--------------------##
+source "${libdir}/filters/age.sh"
 source "${libdir}/filters/status.sh"
 source "${libdir}/filters/reviewers.sh"
 
diff --git a/gerrit/gerrit/usage/main.sh b/gerrit/gerrit/usage/main.sh
index 7a9f4ed..caceadc 100644
--- a/gerrit/gerrit/usage/main.sh
+++ b/gerrit/gerrit/usage/main.sh
@@ -66,11 +66,14 @@
     v2.3.3           View a tag
 
 [REVIEW]
-  --review         Load pending code review requests
-  --review --me    Load only my pending requests
-  --reviewer       Load reviews by user
+  --review           Load pending code review requests
+  --review --me      Load only my pending requests
+  --reviewer         Load reviews by user
 
 [FILTER(s)]
+  --age
+  --before           Change time modified before (alias: --until)
+  --after            Change time modified after  (alias: --since)
   --status [s]       Filter query results by status={open,merged,closed}
     s=open (is:open)
     s=merged
@@ -82,16 +85,20 @@
 
 
 [USAGE]
-  % gerrit.sh --wip
-      Display unmerged patches
 
-  % gerrit.sh --wip --me
-      Display my unmerged patches
+  # Display my unmerged patches
+    % gerrit.sh --wip
+
+  # Display my unmerged patches
+    % gerrit.sh --wip --me
 
   % gerrit.sh --repo voltha-go --admin tags --admin branches
 
-  ## Search for umerged patches in repo:voltha-go
-  % gerrit.sh --repo voltha-go --search --wip
+  # Search for umerged patches in repo:voltha-go
+    % gerrit.sh --repo voltha-go --search --wip
+
+  # Display new patches created since 'yesterday'
+     % gerrit.sh --wip --since '2024-04-24'
 
 [HELP: Extended]
   --help-status
diff --git a/jenkins/bin/jenkins.sh b/jenkins/bin/jenkins.sh
index 29c8f51..47f7b49 100755
--- a/jenkins/bin/jenkins.sh
+++ b/jenkins/bin/jenkins.sh
@@ -74,11 +74,15 @@
             esac
             ;;
 
-        *)
-            arg="$1"; shift
+        -*)
+            shopt -s extglob # ON
+            arg="${arg##+(-)}" # remove switch prefix
+            shopt -u extglob # OFF
             search+=("$arg")
             declare -g -i argv_search=1
             ;;
+
+        *) error "Detected invalid argument [$arg]" ;;
     esac
 done
 
diff --git a/jira/README.md b/jira/README.md
index 05cbd08..ff616d8 100644
--- a/jira/README.md
+++ b/jira/README.md
@@ -1,34 +1,27 @@
-# jira-search
+jira-search
+===========
 
 A script for constructing jira JCL queries
 
 ```bash
 % git clone ssh://gerrit.opencord.org/onf-scripts
-
-# Checkout git submodules
-% make -C onf-scripts
-
 % cd onf-scripts/jira/bin
+
 % ./jira-search.sh –help
 ```
 
-## Conditional Search
+Conditional Searches
+====================
 
-```bash
-% jira-search.sh --server opencord --unresolved ({search-by-flags})
-```
+| Jira | Command | Description |
+| ---- | ------- | ----------- |
+| [x](https://jira.opencord.org/browse/VOL-5287?jql=component%20IN%20(bbsim)%20AND%20(resolved%20IS%20EMPTY)) | ./jira-search.sh -–opencord –-unresolved –-component bbsim | Search for unresolved tickets with a component of bbsim |
+| [x](https://jira.opencord.org/browse/VOL-5220?jql=(labels%20IN%20(bbsim))%20AND%20(resolved%20IS%20EMPTY)) | ./jira-search.sh -–opencord -–unresolved -–label bbsim | Search for unresolved tickets with 'bbsim' mentioned in the label field. |
+| [x](https://jira.opencord.org/browse/VOL-5118?jql=(text%20~%20"bbsim")%20AND%20(resolved%20IS%20EMPTY)) | ./jira-search.sh -–opencord -–unresolved -–text bbsim | Search for unresolved tickets with 'bbsim' mentioned in the description |
+| [x](https://jira.opencord.org/browse/VOL-5293?jql=component%20IN%20(onos%2Cbbsim)%20AND%20(resolved%20IS%20EMPTY)) | ./jira-search.sh -–opencord -–component onos -–component bbsim | Switches can be combined but construction logic still needs work.  Query will be loaded into a browser and can be manually cleaned up. |
 
-### Search Switches
-
-| Jira | Switches | Description |
-| ---- | -------- | ----------- |
-| [x](https://jira.opencord.org/browse/VOL-5287?jql=component%20IN%20(bbsim)%20AND%20(resolved%20IS%20EMPTY)) | –-component bbsim | Search for records with component type bbsim |
-| [x](https://jira.opencord.org/browse/VOL-5220?jql=(labels%20IN%20(bbsim))%20AND%20(resolved%20IS%20EMPTY)) | -–label bbsim | Search label field for string |
-| [x](https://jira.opencord.org/browse/VOL-5118?jql=(text%20~%20"bbsim")%20AND%20(resolved%20IS%20EMPTY)) | -–text bbsim | Search ticket description for string |
-| [x](https://jira.opencord.org/browse/VOL-5293?jql=component%20IN%20(onos%2Cbbsim)%20AND%20(resolved%20IS%20EMPTY)) | -–component onos -–component bbsim | WIP Query for two component types.<br>Manual cleanup of JCL query needed|
-
-
-## Help
+Help
+====
 
 | Command | Description |
 | ------- | ----------- |
@@ -37,4 +30,3 @@
 | ./jira-search.sh --usage-resolved | Display use cases for resolved based searches |
 | ./jira-search.sh --help-user | Display assigned, requested-by or 'my' jira tickets' |
 
-# See Also