diff --git a/scripts/bash/get-pr-context.sh b/scripts/bash/get-pr-context.sh index 406985eb34..f10dc92e95 100755 --- a/scripts/bash/get-pr-context.sh +++ b/scripts/bash/get-pr-context.sh @@ -18,7 +18,11 @@ set -o pipefail #============================================================================== SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +if git rev-parse --show-toplevel >/dev/null 2>&1; then + REPO_ROOT="$(git rev-parse --show-toplevel)" +else + REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" +fi PR_NUMBER="" JSON_MODE=false diff --git a/scripts/powershell/get-pr-context.ps1 b/scripts/powershell/get-pr-context.ps1 index b70059301d..e3e8c3c4c3 100644 --- a/scripts/powershell/get-pr-context.ps1 +++ b/scripts/powershell/get-pr-context.ps1 @@ -32,7 +32,12 @@ $ErrorActionPreference = "Stop" #============================================================================== $scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path -$repoRoot = (Resolve-Path "$scriptPath\..\..") +$gitRoot = try { git rev-parse --show-toplevel 2>$null } catch { $null } +if ($LASTEXITCODE -eq 0 -and $gitRoot) { + $repoRoot = $gitRoot.Trim() +} else { + $repoRoot = (Resolve-Path "$scriptPath\..\..\..\").Path +} #============================================================================== # Utility Functions @@ -170,16 +175,16 @@ if (-not $IncludeAllFiles -and $filesChangedTotal -gt $FileSampleLimit) { } # Check for constitution -$constitutionPath = Join-Path $repoRoot.Path ".documentation\memory\constitution.md" +$constitutionPath = Join-Path $repoRoot ".documentation\memory\constitution.md" $constitutionExists = Test-Path $constitutionPath # Prepare review directory -$reviewDir = Join-Path $repoRoot.Path ".documentation\specs\pr-review" +$reviewDir = Join-Path $repoRoot ".documentation\specs\pr-review" # Build output if ($Json) { $output = @{ - REPO_ROOT = $repoRoot.Path + REPO_ROOT = $repoRoot PR_CONTEXT = @{ enabled = $true pr_number = $prData.number