diff --git a/Actions/.Modules/settings.schema.json b/Actions/.Modules/settings.schema.json index 46a1378d4..498240bda 100644 --- a/Actions/.Modules/settings.schema.json +++ b/Actions/.Modules/settings.schema.json @@ -371,7 +371,8 @@ "properties": { "enabled": { "type": "boolean", - "description": "Enable Copilot code review workflows." + "default": false, + "description": "Enable Copilot code review in PTE and AppSource repositories. Update AL-Go System Files adds the automatic review triggers only when true; otherwise it removes the review workflows. Raw templates are manual-only and skip manual runs." }, "branches": { "type": "array", diff --git a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 index cc7dc4b36..915eb1ac4 100644 --- a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 +++ b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 @@ -133,6 +133,10 @@ function ModifyPullRequestHandlerWorkflow { $yaml.Replace("on:/$($repoSettings.pullRequestTrigger):/branches:", "branches: [ '$($CICDPullRequestBranches -join "', '")' ]") } +<# +.SYNOPSIS +Adds the pull request trigger and configured target branches to the enabled review intake workflow. +#> function ModifyCopilotPRReviewWorkflow { Param( [Yaml] $yaml, @@ -150,7 +154,10 @@ function ModifyCopilotPRReviewWorkflow { } $branchesJson = ConvertTo-Json -InputObject $codeReviewBranches -Compress - $yaml.Replace("on:/pull_request:/branches:", "branches: $branchesJson") + $yaml.ReplaceOrAdd('on:/', 'pull_request:', @( + "branches: $branchesJson" + 'types: [ opened, reopened, synchronize, ready_for_review ]' + )) } function ModifyRunsOnAndShell { @@ -593,8 +600,21 @@ function GetWorkflowContentWithChangesFromSettings { ModifyPullRequestHandlerWorkflow -yaml $yaml -repoSettings $repoSettings } - if ([System.IO.Path]::GetFileName($srcFile) -eq "CopilotPRReview.yaml") { - ModifyCopilotPRReviewWorkflow -yaml $yaml -repoSettings $repoSettings + if ( + $repoSettings.Keys -contains 'CodeReviewAgent' -and + $repoSettings.CodeReviewAgent -is [System.Collections.IDictionary] -and + $repoSettings.CodeReviewAgent.Keys -contains 'enabled' -and + $repoSettings.CodeReviewAgent.enabled + ) { + if ($baseName -eq 'CopilotPRReview') { + ModifyCopilotPRReviewWorkflow -yaml $yaml -repoSettings $repoSettings + } + elseif ($baseName -eq 'CopilotPRReviewRunner') { + $yaml.ReplaceOrAdd('on:/', 'workflow_run:', @( + 'workflows: [ Copilot PR Review ]' + 'types: [ completed ]' + )) + } } $criticalWorkflows = @('UpdateGitHubGoSystemFiles', 'Troubleshooting', 'CopilotPRReviewRunner') diff --git a/Scenarios/Agents/CopilotCodeReview.md b/Scenarios/Agents/CopilotCodeReview.md index 3d4800faf..3e5474d44 100644 --- a/Scenarios/Agents/CopilotCodeReview.md +++ b/Scenarios/Agents/CopilotCodeReview.md @@ -31,7 +31,11 @@ Add the following repository-level setting to `.github/AL-Go-Settings.json`: } ``` -Run the **Update AL-Go System Files** workflow to add the review workflows. Subsequent eligible pull requests targeting a branch configured in `CodeReviewAgent.branches` will be reviewed automatically. +Code review is off by default. The PTE and AppSource templates include review workflow files, but these files do not automatically review pull requests. Running them manually also skips all review jobs. + +To turn on automatic reviews, set `CodeReviewAgent.enabled` to `true` and run **Update AL-Go System Files** using the latest AL-Go version. This configures the workflows to review eligible pull requests targeting the branches in `CodeReviewAgent.branches`. + +To turn reviews off, set `CodeReviewAgent.enabled` to `false` and run **Update AL-Go System Files** again. This removes both review workflows. BCQuality defaults to the trusted `microsoft/BCQuality` marketplace release, retains all content layers, and supplies the internal AL review context. Advanced filtering remains available through `BCQuality.enabledLayers`, `disabledSkills`, and `knowledge`. An empty `enabledLayers` list retains Microsoft, community, and custom content; an explicit list retains only those layers. `CodeReviewAgent.branches` controls the target branches reviewed independently of pull request build branches. Its empty default means `main`; an explicit list replaces that fallback and uses ordered GitHub Actions branch patterns, including `!` exclusions. The trusted runner checks the authoritative pull request base branch against these patterns before review. `model` controls final self-review and consolidation, while `leafModel` controls the isolated review processes. `excludedAuthors` contains GitHub login names whose pull requests should not be reviewed. The author list is empty by default. diff --git a/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml b/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml index 302e8c6f5..b6a1bcaff 100644 --- a/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml +++ b/Templates/AppSource App/.github/workflows/CopilotPRReview.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review on: - pull_request: - branches: [ 'main' ] - types: [ opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: concurrency: group: copilot-pr-review-${{ github.event.pull_request.number }} @@ -18,6 +16,7 @@ permissions: jobs: Intake: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Upload pull request metadata diff --git a/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml b/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml index 0c8a379d0..e243f5796 100644 --- a/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml +++ b/Templates/AppSource App/.github/workflows/CopilotPRReviewRunner.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review Runner on: - workflow_run: - workflows: [ Copilot PR Review ] - types: [ completed ] + workflow_dispatch: concurrency: group: copilot-pr-review-runner-${{ github.event.workflow_run.id }} @@ -21,7 +19,7 @@ env: jobs: prepare: - if: github.event.workflow_run.conclusion == 'success' + if: github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: [ windows-latest ] permissions: actions: read diff --git a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml index 302e8c6f5..b6a1bcaff 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReview.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review on: - pull_request: - branches: [ 'main' ] - types: [ opened, reopened, synchronize, ready_for_review ] + workflow_dispatch: concurrency: group: copilot-pr-review-${{ github.event.pull_request.number }} @@ -18,6 +16,7 @@ permissions: jobs: Intake: + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Upload pull request metadata diff --git a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml index 0c8a379d0..e243f5796 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CopilotPRReviewRunner.yaml @@ -1,9 +1,7 @@ name: Copilot PR Review Runner on: - workflow_run: - workflows: [ Copilot PR Review ] - types: [ completed ] + workflow_dispatch: concurrency: group: copilot-pr-review-runner-${{ github.event.workflow_run.id }} @@ -21,7 +19,7 @@ env: jobs: prepare: - if: github.event.workflow_run.conclusion == 'success' + if: github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' runs-on: [ windows-latest ] permissions: actions: read diff --git a/Tests/CheckForUpdates.Action.Test.ps1 b/Tests/CheckForUpdates.Action.Test.ps1 index a9a5b88e2..999c1571b 100644 --- a/Tests/CheckForUpdates.Action.Test.ps1 +++ b/Tests/CheckForUpdates.Action.Test.ps1 @@ -390,6 +390,74 @@ Describe "CheckForUpdates Action: CheckForUpdates.HelperFunctions.ps1" { { ModifyRunsOnAndShell -yaml $yaml -repoSettings $repoSettings } | Should -Throw '*The shell cannot be set to powershell when runs-on is ubuntu-latest*' } + It 'Adds Copilot review triggers only when enabled in