Merge "VOL-5410 & VOL-5411: Changes to github release job"
diff --git a/jjb/github-release.yaml b/jjb/github-release.yaml
index 1e8a10a..f8e1261 100644
--- a/jjb/github-release.yaml
+++ b/jjb/github-release.yaml
@@ -29,7 +29,7 @@
           jenkins-ssh-credential: '{gerrit-ssh-credential}'
       - credentials-binding:
           - text:
-              credential-id: onf-voltha  # github-release-token
+              credential-id: github-release-2025
               variable: GITHUB_TOKEN
 
     scm:
diff --git a/jjb/shell/github-release.sh b/jjb/shell/github-release.sh
index 8cbd044..913792f 100755
--- a/jjb/shell/github-release.sh
+++ b/jjb/shell/github-release.sh
@@ -143,9 +143,6 @@
         /bin/rm -fr "$scratch"
     fi
 
-    # shellcheck disable=SC2119
-    do_logout
-
     return
 }
 trap sigtrap EXIT
@@ -303,18 +300,6 @@
 }
 
 ## -----------------------------------------------------------------------
-## Intent: Script self checking, direct API access for troubleshooting
-## -----------------------------------------------------------------------
-function do_api_validation()
-{
-    # if --verify credentials
-    do_login
-    # shellcheck disable=SC2119
-    do_logout
-    return
-}
-
-## -----------------------------------------------------------------------
 ## Intent: Verify sandbox/build is versioned for release.
 ## -----------------------------------------------------------------------
 function getGitVersion()
@@ -462,7 +447,7 @@
 }
 
 ## -----------------------------------------------------------------------
-## Intent: Retrieve repository organizaiton name
+## Intent: Retrieve repository name
 ## -----------------------------------------------------------------------
 function get_gh_repo_name()
 {
@@ -501,6 +486,27 @@
 }
 
 ## -----------------------------------------------------------------------
+## Intent: Return whether the repo has discussions enabled
+## -----------------------------------------------------------------------
+function get_discussions()
+{
+    declare -g HAS_DISCUSSIONS
+
+    local repo_org
+    get_gh_repo_org repo_org
+
+    local repo_name
+    get_gh_repo_name repo_name
+
+    local repo_uri
+    repo_uri="repos/${repo_org}/${repo_name}"
+
+    func_echo "RUNNING: $gh_cmd api $repo_uri | jq '.has_discussions'"
+    HAS_DISCUSSIONS=$($gh_cmd api $repo_uri | jq '.has_discussions')
+    return
+}
+
+## -----------------------------------------------------------------------
 ## Intent: Retrieve repository path argument
 ## -----------------------------------------------------------------------
 function get_argv_repo()
@@ -613,7 +619,7 @@
       - refactor redundant paths into local vars.
       - see comments, do we have a one-off failure condition ?
   o PATH += golang appended 3 times, release needs a single, reliable answer.
-  o do_login, do_logout and api calls do not use the my_gh wrapper:
+  o do_login and api calls do not use the my_gh wrapper:
       - Add a lookup function to cache and retrieve path to downloaded gh command.
 
 EOT
@@ -714,9 +720,13 @@
     declare -a args=()
     args+=('--host-repo')
     args+=('--title')
+
+    # Check if repo has discussions enabled
+    get_discussions
+
     if [[ -v draft_release ]]; then
         args+=('--draft')
-    else
+    elif [[ $HAS_DISCUSSIONS == "true" ]]; then
         args+=('--discussion-category' 'Announcements')
     fi
 
@@ -796,28 +806,6 @@
 }
 
 ## -----------------------------------------------------------------------
-## Intent: Destroy credentials/gh session authenticated by do_login
-## -----------------------------------------------------------------------
-## NOTE: my_gh currently unused due to "<<< 'y'"
-## -----------------------------------------------------------------------
-function do_logout()
-{
-    declare -i -g active_login
-    [[ ! -v active_login ]] && return
-
-    declare -a logout_args=()
-    [[ $# -gt 0 ]] && logout_args+=("$@")
-
-    get_gh_hostname logout_args
-
-    banner "${logout_args[@]}"
-    func_echo "$gh_cmd auth logout ${logout_args[*]} <<< 'Y'"
-    "$gh_cmd" auth logout "${logout_args[@]}" <<< 'Y'
-    unset active_login
-    return
-}
-
-## -----------------------------------------------------------------------
 ## Intent: Query for repository version strings
 ## -----------------------------------------------------------------------
 function get_releases()
@@ -1101,8 +1089,6 @@
 init
 install_gh_binary
 
-[[ -v argv_self_check ]] && { do_api_validation; exit 0; }
-
 do_login "$*"
 
 release_path='/dev/null'
@@ -1164,9 +1150,6 @@
 
 popd  || { error "pushd failed: dir is [$release_path]"; }
 
-# shellcheck disable=SC2119
-do_logout
-
 # [SEE ALSO]
 # -----------------------------------------------------------------------
 # https://www.shellcheck.net/wiki/SC2236