From 5e2ff950c2bfa36b71f0196435feca1e1bc5b49d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 18:27:25 +0000 Subject: [PATCH 1/5] Allow azure-sdk PRs to bypass CODEOWNERS section check and rename CodeownersChanged to ShouldCheckCodeownersEdits Agent-Logs-Url: https://github.com/Azure/azure-sdk-tools/sessions/6acbd501-14e8-4108-9213-c49d035fb815 Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> --- .../steps/verify-codeowners-sections.yml | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml index 6e0c59305d6b..c8164b8ff463 100644 --- a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml +++ b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml @@ -8,8 +8,15 @@ parameters: steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - # 1. Check if CODEOWNERS changed; skip everything if it hasn't + # 1. Check if CODEOWNERS changed; skip everything if it hasn't or if opened by azure-sdk - pwsh: | + $prCreator = "$(Build.RequestedFor)" + if ($prCreator -eq "azure-sdk") { + Write-Host "PR opened by azure-sdk. Skipping CODEOWNERS section check." + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" + exit 0 + } + $scriptPath = [System.IO.Path]::Combine("${{ parameters.SourceRootPath }}", "eng", "common", "scripts", "get-changedfiles.ps1") try { $changedFiles = & $scriptPath ` @@ -27,10 +34,10 @@ steps: if (!$changedFiles) { Write-Host "CODEOWNERS file has not changed." - Write-Host "##vso[task.setvariable variable=CodeownersChanged]false" + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" } else { Write-Host "CODEOWNERS file has changed." - Write-Host "##vso[task.setvariable variable=CodeownersChanged]true" + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]true" } displayName: 'Check if CODEOWNERS changed' workingDirectory: ${{ parameters.SourceRootPath }} @@ -40,7 +47,7 @@ steps: - template: /eng/common/pipelines/templates/steps/install-azsdk-cli.yml parameters: SourceRootPath: ${{ parameters.SourceRootPath }} - Condition: and(succeeded(), eq(variables['CodeownersChanged'], 'true')) + Condition: and(succeeded(), eq(variables['ShouldCheckCodeownersEdits'], 'true')) # 3. Prepare before/after CODEOWNERS files - pwsh: | @@ -61,13 +68,13 @@ steps: if ($LASTEXITCODE) { Write-Host "Could not retrieve CODEOWNERS from HEAD~1. The file may be newly added. Skipping." - Write-Host "##vso[task.setvariable variable=CodeownersChanged]false" + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" exit 0 } Write-Host "Extracted parent CODEOWNERS to $beforeFile" displayName: 'Prepare CODEOWNERS before/after files' workingDirectory: ${{ parameters.SourceRootPath }} - condition: and(succeeded(), eq(variables['CodeownersChanged'], 'true')) + condition: and(succeeded(), eq(variables['ShouldCheckCodeownersEdits'], 'true')) # 4. Run the section comparison script - task: Powershell@2 @@ -83,4 +90,4 @@ steps: -TempDirectory "${{ parameters.TempDirectory }}" pwsh: true workingDirectory: ${{ parameters.SourceRootPath }} - condition: and(succeeded(), eq(variables['CodeownersChanged'], 'true')) + condition: and(succeeded(), eq(variables['ShouldCheckCodeownersEdits'], 'true')) From 1f2c45ccecc8494a35465751de3add1221561077 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:42:45 +0000 Subject: [PATCH 2/5] Use gh pr view to detect PR author instead of Build.RequestedFor Agent-Logs-Url: https://github.com/Azure/azure-sdk-tools/sessions/e2fb79aa-7ed3-45dd-a0ba-3ebb24b10e4b Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> --- .../steps/verify-codeowners-sections.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml index c8164b8ff463..a96f2f8e9af9 100644 --- a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml +++ b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml @@ -10,11 +10,20 @@ steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: # 1. Check if CODEOWNERS changed; skip everything if it hasn't or if opened by azure-sdk - pwsh: | - $prCreator = "$(Build.RequestedFor)" - if ($prCreator -eq "azure-sdk") { - Write-Host "PR opened by azure-sdk. Skipping CODEOWNERS section check." - Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" - exit 0 + $prNumber = "$(System.PullRequest.PullRequestNumber)" + $repoName = "$(Build.Repository.Name)" + $prAuthorJson = gh pr view $prNumber --repo $repoName --json author 2>&1 + if ($LASTEXITCODE -eq 0) { + $prAuthor = ($prAuthorJson | ConvertFrom-Json).author.login + Write-Host "PR author: $prAuthor" + if ($prAuthor -ieq "azure-sdk") { + Write-Host "PR opened by azure-sdk. Skipping CODEOWNERS section check." + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" + exit 0 + } + } else { + Write-Host "Could not determine PR author via gh CLI: $prAuthorJson" + Write-Host "Continuing with CODEOWNERS section check." } $scriptPath = [System.IO.Path]::Combine("${{ parameters.SourceRootPath }}", "eng", "common", "scripts", "get-changedfiles.ps1") From 5e2395e676df6542c7aea0eb466bf241d79b4a5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:20:06 +0000 Subject: [PATCH 3/5] Reorder logic: check CODEOWNERS changed before gh API call, remove stderr capture Agent-Logs-Url: https://github.com/Azure/azure-sdk-tools/sessions/747d7c1f-ba14-4781-83e1-6b80bf475318 Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> --- .../steps/verify-codeowners-sections.yml | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml index a96f2f8e9af9..797a1468442c 100644 --- a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml +++ b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml @@ -8,24 +8,8 @@ parameters: steps: - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - # 1. Check if CODEOWNERS changed; skip everything if it hasn't or if opened by azure-sdk + # 1. Check if CODEOWNERS changed; if so, check whether the PR was opened by azure-sdk - pwsh: | - $prNumber = "$(System.PullRequest.PullRequestNumber)" - $repoName = "$(Build.Repository.Name)" - $prAuthorJson = gh pr view $prNumber --repo $repoName --json author 2>&1 - if ($LASTEXITCODE -eq 0) { - $prAuthor = ($prAuthorJson | ConvertFrom-Json).author.login - Write-Host "PR author: $prAuthor" - if ($prAuthor -ieq "azure-sdk") { - Write-Host "PR opened by azure-sdk. Skipping CODEOWNERS section check." - Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" - exit 0 - } - } else { - Write-Host "Could not determine PR author via gh CLI: $prAuthorJson" - Write-Host "Continuing with CODEOWNERS section check." - } - $scriptPath = [System.IO.Path]::Combine("${{ parameters.SourceRootPath }}", "eng", "common", "scripts", "get-changedfiles.ps1") try { $changedFiles = & $scriptPath ` @@ -44,10 +28,24 @@ steps: if (!$changedFiles) { Write-Host "CODEOWNERS file has not changed." Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" - } else { - Write-Host "CODEOWNERS file has changed." - Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]true" + exit 0 } + + Write-Host "CODEOWNERS file has changed." + + $prNumber = "$(System.PullRequest.PullRequestNumber)" + $repoName = "$(Build.Repository.Name)" + $prAuthorJson = gh pr view $prNumber --repo $repoName --json author + $prAuthor = ($prAuthorJson | ConvertFrom-Json).author.login + Write-Host "PR author: $prAuthor" + + if ($prAuthor -ieq "azure-sdk") { + Write-Host "PR opened by azure-sdk. Skipping CODEOWNERS section check." + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]false" + exit 0 + } + + Write-Host "##vso[task.setvariable variable=ShouldCheckCodeownersEdits]true" displayName: 'Check if CODEOWNERS changed' workingDirectory: ${{ parameters.SourceRootPath }} condition: and(succeeded(), ne(variables['Skip.VerifyCodeownersSections'], 'true')) From 81563371f83661f86ada871e5c46d4f64fe189ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 22:02:36 +0000 Subject: [PATCH 4/5] Replace gh CLI with Invoke-RestMethod for PR author detection Agent-Logs-Url: https://github.com/Azure/azure-sdk-tools/sessions/56bb56b5-f097-48df-90ab-de347a28634f Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> --- .../pipelines/templates/steps/verify-codeowners-sections.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml index 797a1468442c..177715614823 100644 --- a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml +++ b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml @@ -35,8 +35,9 @@ steps: $prNumber = "$(System.PullRequest.PullRequestNumber)" $repoName = "$(Build.Repository.Name)" - $prAuthorJson = gh pr view $prNumber --repo $repoName --json author - $prAuthor = ($prAuthorJson | ConvertFrom-Json).author.login + $prUrl = "https://api.github.com/repos/$repoName/pulls/$prNumber" + $prData = Invoke-RestMethod -Uri $prUrl + $prAuthor = $prData.user.login Write-Host "PR author: $prAuthor" if ($prAuthor -ieq "azure-sdk") { From 88b0a33080ee01c61ada88bf70ae2e8ee75c237f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Apr 2026 22:15:53 +0000 Subject: [PATCH 5/5] Add retry parameters to Invoke-RestMethod for PR author lookup Agent-Logs-Url: https://github.com/Azure/azure-sdk-tools/sessions/d8f97723-9352-41c9-8005-356bde3313c4 Co-authored-by: danieljurek <2158838+danieljurek@users.noreply.github.com> --- .../pipelines/templates/steps/verify-codeowners-sections.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml index 177715614823..229d24f996a4 100644 --- a/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml +++ b/eng/common/pipelines/templates/steps/verify-codeowners-sections.yml @@ -36,7 +36,7 @@ steps: $prNumber = "$(System.PullRequest.PullRequestNumber)" $repoName = "$(Build.Repository.Name)" $prUrl = "https://api.github.com/repos/$repoName/pulls/$prNumber" - $prData = Invoke-RestMethod -Uri $prUrl + $prData = Invoke-RestMethod -Uri $prUrl -MaximumRetryCount 10 -RetryIntervalSec 6 $prAuthor = $prData.user.login Write-Host "PR author: $prAuthor"