Comments (14)
Hi,
I think i fixed it but I can't test it, could you check if it works now?
(Check that you have the new version - 1.2.81)
from azure-devops-create-pr-task.
Hi @kulmam92,
Thank you for reporting that!
It's wired, I quite sure I did it with ?api-version=4.1-preview.1
because Azure DevOps Server and it worked in the past, so maybe Microsoft removed the support in this version... :/
I will check how I can fix it.
Kind regards,
Shayki
from azure-devops-create-pr-task.
Hi @kulmam92 again :)
Please see issue #3 (I also mentioned it in the Known Issues), I don't remember why but I thought I fixed it, but now I see that is not tested and the commit that fixed it not so clear, so maybe it still an issue.
I will check if it could be fixed.
from azure-devops-create-pr-task.
@shayki5 I was able to test just now.
I encountered several issues.
-
Bug in GetReviewerId
GitSample project was hardcoded. -
Clinet authentication required error.
TF400813: Resource not available for anonymous access. Client authentication required. - Azure DevOps Server
I created the System_AccessToken variable and granted the permission but still getting this error.
Therefore, I changed it to "-UseDefaultCredentials".
- Team member search
This may be my environment setting but team members are registered in "Domain\UserShortname" instead of an email address.
Below is the code that I modified to fix those issues.
function GetReviewerId() {
[CmdletBinding()]
Param
(
[string]$reviewers
)
$serverUrl = $env:System_TeamFoundationCollectionUri
$head = @{ Authorization = "Bearer $env:System_AccessToken" }
# If it's TFS/AzureDevOps Server
if ($serverUrl -notmatch "visualstudio.com" -and $serverUrl -notmatch "dev.azure.com") {
$url = "$($env:System_TeamFoundationCollectionUri)_apis/projects/$($env:System_TeamProject)/teams?api-version=4.1"
# $teams = Invoke-RestMethod -Method Get -Uri $url -Headers $head -ContentType 'application/json'
$teams = Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials -ContentType 'application/json'
Write-Debug $reviewers
$split = $reviewers.Split(';')
$reviewersId = @()
ForEach ($reviewer in $split) {
# If the reviewer is user
if ($reviewer.Contains("@") -or $reviewer.Contains("\")) {
$teams.value.ForEach( {
$teamUrl = "$($env:System_TeamFoundationCollectionUri)_apis/projects/$($env:System_TeamProject)/teams/$($_.id)/members?api-version=4.1"
# $team = Invoke-RestMethod -Method Get -Uri $teamUrl -Headers $head -ContentType 'application/json'
$team = Invoke-RestMethod -Method Get -Uri $teamUrl -UseDefaultCredentials -ContentType 'application/json'
# If the team contains only 1 user
if ($team.count -eq 1) {
if ($team.value.identity.uniqueName -eq $reviewer) {
$userId = $team.value.identity.id
Write-Host $userId -ForegroundColor Green
$reviewersId += @{ id = "$userId" }
break
}
}
else { # If the team contains more than 1 user
$userId = $team.value.identity.Where( { $_.uniqueName -eq $reviewer }).id
if ($userId -ne $null) {
Write-Host $userId -ForegroundColor Green
$reviewersId += @{ id = "$userId" }
break
}
}
})
}
# If the reviewer is team
else {
if ($teams.count -eq 1) {
if ($teams.value.name -eq $u) {
$teamId = $teams.value.id
Write-Host $teamId -ForegroundColor Green
$reviewersId += @{ id = "$userId" }
}
}
else {
$teamId = $teams.value.Where( { $_.name -eq $u }).id
Write-Host $teamId -ForegroundColor Green
$reviewersId += @{ id = "$teamId" }
}
}
}
}
# If it's Azure Devops
else {
$url = "$($env:System_TeamFoundationCollectionUri)_apis/userentitlements?api-version=4.1-preview.1"
# Check if it's the old url or the new url, reltaed to issue #21
# And add "vsaex" to the rest api url
if ($url -match "visualstudio.com") {
$url = $url.Replace(".visualstudio", ".vsaex.visualstudio")
}
else {
$url = $url.Replace("//dev", "//vsaex.dev")
}
# $users = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -Headers $head
$users = Invoke-RestMethod -Uri $url -Method Get -ContentType application/json -UseDefaultCredentials
$teamsUrl = "$($env:System_TeamFoundationCollectionUri)_apis/projects/$($env:System_TeamProject)/teams?api-version=4.1-preview.1"
# $teams = Invoke-RestMethod -Uri $teamsUrl -Method Get -ContentType application/json -Headers $head
$teams = Invoke-RestMethod -Uri $teamsUrl -Method Get -ContentType application/json -UseDefaultCredentials
Write-Debug $reviewers
$split = $reviewers.Split(';')
$reviewersId = @()
ForEach ($reviewer in $split) {
if ($reviewer.Contains("@") -or $reviewer.Contains("\")) {
# Is user
$userId = $users.value.Where( { $_.user.mailAddress -eq $reviewer }).id
$reviewersId += @{ id = "$userId" }
}
else {
# Is team
$teamId = $teams.value.Where( { $_.name -eq $reviewer }).id
$reviewersId += @{ id = "$teamId" }
}
}
}
return $reviewersId
}
from azure-devops-create-pr-task.
Hi @kulmam92,
Thank you so much for your comments and code!
-
My fault, I fixed it.
-
My fault again, system access token should work, I just didn't pass him, I fixed it.
-
In the task you should pass the email address in the reviewers field, I guess the email address are exist also, no?
I uploaded a new version now (1.2.82), please check if it works.
(I didn't use your code with the -UseDefaultCredntials
because I prefer the task will use the access token)
Thank you,
Shayki
from azure-devops-create-pr-task.
Hi @kulmam92, could you check if it works for you?
from azure-devops-create-pr-task.
@shayki5 Unfortunately, it's not.
I got an error due to the following line.
$teamUrl = "$($env:System_TeamFoundationCollectionUri)_apis/projects/GitSample/teams/$($_.id)/members?api-version=4.1"
from azure-devops-create-pr-task.
@kulmam92 Could you share the error please?
from azure-devops-create-pr-task.
@shayki5 I got this error. GitSample should be an actual project name.
##[error]The remote server returned an error: (404) Not Found.
from azure-devops-create-pr-task.
Oh I missed it! Thanks.
I released a fix, could you check please?
from azure-devops-create-pr-task.
@shayki5 I got this error.
The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
from azure-devops-create-pr-task.
Thanks, @kulmam92!
It was a small bug in one of the brackets... I fixed it, please check now :)
Thank you so much!
from azure-devops-create-pr-task.
@shayki5
It's working now. Thank you for fixing this.
from azure-devops-create-pr-task.
@kulmam92 You're welcome :)
Thank you for reporting the issue!
from azure-devops-create-pr-task.
Related Issues (20)
- Does not work under Linux x64 agent HOT 1
- Running Task in self-managed agent behind a Proxy HOT 6
- Getting 403 Forbidden in the CreatePullRequestTask HOT 1
- Set the creator of the PR to the author of the commit instead of the Build Service User HOT 2
- Wildcard support in targetBranch HOT 7
- Create PR by other user than "project collection build service" HOT 9
- Running on Azure windows-latest agent pool still task is failing HOT 2
- Enhancement - Add work item via ID/URL HOT 1
- Getting error The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel HOT 13
- Automatically complete PR HOT 1
- 400 Bad Request to bypass PR policies HOT 4
- Feature request: add support for git tags
- Is "deleteSourch" a typo? HOT 1
- Version 1.2.363 breaks pipeline for branch with forward slash HOT 3
- Can't set Auto Complete to PR HOT 2
- Error (404) Not Found when adding reviewers on my PR (Azure DevOps) HOT 6
- alwaysCreatePr does not work HOT 1
- Use original git commit message as description (ADO) HOT 6
- Can't check "Delete Source Branch" when using "Bypass Policies" HOT 4
- Autocomplete option not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-devops-create-pr-task.