Giter VIP home page Giter VIP logo

Comments (14)

shayki5 avatar shayki5 commented on September 25, 2024 1

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.

shayki5 avatar shayki5 commented on September 25, 2024

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.

shayki5 avatar shayki5 commented on September 25, 2024

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.
image

I will check if it could be fixed.

from azure-devops-create-pr-task.

kulmam92 avatar kulmam92 commented on September 25, 2024

@shayki5 I was able to test just now.

I encountered several issues.

  1. Bug in GetReviewerId
    GitSample project was hardcoded.

  2. 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".

  1. 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.

shayki5 avatar shayki5 commented on September 25, 2024

Hi @kulmam92,

Thank you so much for your comments and code!

  1. My fault, I fixed it.

  2. My fault again, system access token should work, I just didn't pass him, I fixed it.

  3. 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.

shayki5 avatar shayki5 commented on September 25, 2024

Hi @kulmam92, could you check if it works for you?

from azure-devops-create-pr-task.

kulmam92 avatar kulmam92 commented on September 25, 2024

@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.

shayki5 avatar shayki5 commented on September 25, 2024

@kulmam92 Could you share the error please?

from azure-devops-create-pr-task.

kulmam92 avatar kulmam92 commented on September 25, 2024

@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.

shayki5 avatar shayki5 commented on September 25, 2024

Oh I missed it! Thanks.
I released a fix, could you check please?

from azure-devops-create-pr-task.

kulmam92 avatar kulmam92 commented on September 25, 2024

@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.

shayki5 avatar shayki5 commented on September 25, 2024

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.

kulmam92 avatar kulmam92 commented on September 25, 2024

@shayki5
It's working now. Thank you for fixing this.

from azure-devops-create-pr-task.

shayki5 avatar shayki5 commented on September 25, 2024

@kulmam92 You're welcome :)
Thank you for reporting the issue!

from azure-devops-create-pr-task.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.