File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1435,7 +1435,29 @@ jobs:
14351435
14361436 # Get permission level of user who created the comment. Need to use .role_name instead of .permission because .permission provides only legacy values.
14371437 # .role_name provides legacy plus triage, maintain, and custom roles like write-elevated.
1438- $UserPermission = $(Invoke-RestMethod -Method GET -Headers $GitHubHeaders -Uri $UserPermissionUrl).role_name
1438+ # Copilot isn't a real user so attempting to retrieve its permissions on the repo will fail. Set $UserPermission to read if copilot is the submitter.
1439+ If ($PrCreator -ne "copilot") {
1440+
1441+ Try {
1442+
1443+ $UserPermission = $(Invoke-RestMethod -Method GET -Headers $GitHubHeaders -Uri $UserPermissionUrl).role_name
1444+
1445+ } Catch {
1446+
1447+ Write-Host "Failed to retrieve user permission for $PrCreator. Defaulting to read. Error : $_"
1448+
1449+ $UserPermission = "read"
1450+
1451+ }
1452+
1453+ } Else {
1454+
1455+ Write-Host "PR creator is copilot. Defaulting to read permissions."
1456+
1457+ $UserPermission = "read"
1458+
1459+ }
1460+
14391461
14401462 # Only add reviewers if the submitter can't sign off on their own PR.
14411463 If (($UserPermission -eq "read") -or ($UserPermission -eq "") -or ($UserPermission -eq $Null)) {
You can’t perform that action at this time.
0 commit comments