Skip to content

Extract duplicated code into shared libraries#10

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-duplicated-code
Draft

Extract duplicated code into shared libraries#10
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-duplicated-code

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

Setup scripts contained ~300 lines of duplicated code across bash and PowerShell implementations. Logging, OS detection, privilege checking, and package installation logic were repeated in each script.

Changes

Bash Scripts

  • Created lib/common.sh: Extracted log(), command_exists(), detect_os(), and color constants
  • Updated 3 scripts to source common library: setup-desktop.sh, setup-server.sh, setup-environment.sh

PowerShell Scripts

  • Created lib/common.psm1: Extracted Write-Log(), Test-Administrator(), Require-Administrator(), Install-Chocolatey(), Install-JavaJDK17(), Set-JavaHome(), Update-EnvironmentPath()
  • Updated 3 scripts to import module: setup-desktop.ps1, setup-server.ps1, setup-environment.ps1

Example

Before:

# setup-desktop.ps1 (repeated in setup-server.ps1)
function Write-Log {
    param([string]$Message, [string]$Level = "INFO")
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $logMessage = "[$timestamp] [$Level] $Message"
    Write-Host $logMessage
    if ($LogFile) { Add-Content -Path $LogFile -Value $logMessage }
}

After:

# All scripts
Import-Module "$PSScriptRoot\lib\common.psm1" -Force

Impact

  • Net -47 LOC (removed 383, added 336 for libraries)
  • Eliminates duplicate maintenance for common functionality
  • Bash and PowerShell implementations now symmetrical
Original prompt

Find and refactor duplicated code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 24, 2026 18:11
Co-authored-by: Kcato1 <193196419+Kcato1@users.noreply.github.com>
Co-authored-by: Kcato1 <193196419+Kcato1@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Extract duplicated code into shared libraries Jan 24, 2026
Copilot AI requested a review from Kcato1 January 24, 2026 18:20
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.

2 participants