Skip to content

refactor: combine duplicate loops in admin-control-panel-install.sh - #224

Merged
PDowney merged 3 commits into
masterfrom
copilot/refactor-dashboard-loop
May 1, 2026
Merged

PDowney merged 3 commits into
masterfrom
copilot/refactor-dashboard-loop

Conversation

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor

Software Version Updates

The for file in index.html dashboard.js loop was duplicated — once for sed substitution, once for placeholder verification. Merged into a single pass.

Changed Versions

  • scripts/install/tools/frontend/admin-control-panel-install.sh: combined substitution + verification into one loop

Version Diff

-for file in index.html dashboard.js; do
-    sed -i "s|{ES_DASHBOARD_VER}|${ES_DASHBOARD_VER}|g" "/var/www/admin/control-panel/${file}"
-done
-
-# Verify that the dashboard placeholder was successfully replaced to avoid silent failures
-for file in index.html dashboard.js; do
-    if grep -q '{ES_DASHBOARD_VER}' "/var/www/admin/control-panel/${file}"; then
-        echo "Error: Failed to substitute dashboard version in /var/www/admin/control-panel/${file}; placeholder {ES_DASHBOARD_VER} still present." >&2
-        exit 1
-    fi
-done
+# Substitute and verify dashboard version placeholders in one pass
+for file in index.html dashboard.js; do
+    sed -i "s|{ES_DASHBOARD_VER}|${ES_DASHBOARD_VER}|g" "/var/www/admin/control-panel/${file}"
+    if grep -q '{ES_DASHBOARD_VER}' "/var/www/admin/control-panel/${file}"; then
+        echo "Error: Failed to substitute dashboard version in /var/www/admin/control-panel/${file}; placeholder {ES_DASHBOARD_VER} still present." >&2
+        exit 1
+    fi
+done

Verification Checklist

  • Version numbers are correctly formatted
  • Version numbers are stable releases (not beta/RC)
  • No syntax errors in variables file

Notes

No behavioural change. Pure deduplication — substitution and verification now happen per-file in the same iteration rather than two separate full passes.

Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The loop iterating over 'index.html dashboard.js' is duplicated for substitution and verification. Consider combining both operations in a single loop to reduce code duplication and improve maintainability.","fixFiles":[{"filePath":"scripts/install/tools/frontend/admin-control-panel-install.sh","diff":"diff --git a/scripts/install/tools/frontend/admin-control-panel-install.sh b/scripts/install/tools/frontend/admin-control-panel-install.sh\n--- a/scripts/install/tools/frontend/admin-control-panel-install.sh\n+++ b/scripts/install/tools/frontend/admin-control-panel-install.sh\n@@ -39,12 +39,9 @@\n     exit 1\n fi\n \n+# Substitute and verify dashboard version placeholders in one pass\n for file in index.html dashboard.js; do\n     sed -i \"s|{ES_DASHBOARD_VER}|${ES_DASHBOARD_VER}|g\" \"/var/www/admin/control-panel/${file}\"\n-done\n-\n-# Verify that the dashboard placeholder was successfully replaced to avoid silent failures\n-for file in index.html dashboard.js; do\n     if grep -q '{ES_DASHBOARD_VER}' \"/var/www/admin/control-panel/${file}\"; then\n         echo \"Error: Failed to substitute dashboard version in /var/www/admin/control-panel/${file}; placeholder {ES_DASHBOARD_VER} still present.\" >&2\n         exit 1\n"}]}]

Copilot AI changed the title [WIP] Refactor loop for substitution and verification in dashboard files refactor: combine duplicate loops in admin-control-panel-install.sh May 1, 2026
Copilot finished work on behalf of PDowney May 1, 2026 06:19
Copilot AI requested a review from PDowney May 1, 2026 06:19
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

@PDowney
PDowney marked this pull request as ready for review May 1, 2026 20:50
Copilot AI review requested due to automatic review settings May 1, 2026 20:50
@PDowney
PDowney merged commit 59365dc into master May 1, 2026
10 checks passed
@github-actions
github-actions Bot deleted the copilot/refactor-dashboard-loop branch May 1, 2026 20:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the admin control panel install script to reduce duplication by performing dashboard version placeholder substitution and verification in a single loop.

Changes:

  • Combine the sed substitution and {ES_DASHBOARD_VER} placeholder verification into one per-file loop.
  • Add a clarifying comment describing the combined substitution + verification pass.

Comment on lines 43 to 46
for file in index.html dashboard.js; do
sed -i "s|{ES_DASHBOARD_VER}|${ES_DASHBOARD_VER}|g" "/var/www/admin/control-panel/${file}"
done

# Verify that the dashboard placeholder was successfully replaced to avoid silent failures
for file in index.html dashboard.js; do
if grep -q '{ES_DASHBOARD_VER}' "/var/www/admin/control-panel/${file}"; then
echo "Error: Failed to substitute dashboard version in /var/www/admin/control-panel/${file}; placeholder {ES_DASHBOARD_VER} still present." >&2

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep -q inside the if will silently treat missing/unreadable files as “no match” (grep exits 2), so placeholder verification can be skipped without failing the install. Consider explicitly checking that each target file exists/readable before running sed/grep, and/or handling grep’s exit status to error on I/O failures.

Copilot uses AI. Check for mistakes.
Comment on lines +42 to 43
# Substitute and verify dashboard version placeholders in one pass
for file in index.html dashboard.js; do

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repo standard is to record changes in the root CHANGELOG.md when modifying the codebase (see .github/copilot-instructions.md “Documentation & Change Tracking”). This PR changes an install script but doesn’t include a changelog entry.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants