MethodsAndPractices / vsteam

PowerShell module for accessing Azure DevOps Services and Azure DevOps Server (formerly VSTS or TFS)
https://methodsandpractices.github.io/vsteam-docs/
MIT License
445 stars 155 forks source link

Project name with spaces causing problems #334

Closed thgossler closed 4 years ago

thgossler commented 4 years ago

Steps to reproduce

$vstsProjectName = "project name with spaces"
Set-VSTeamAccount -Account $vstsAccountName -PersonalAccessToken $personalAccessToken
Set-VSTeamDefaultProject -Project $vstsProjectName
$jsonBodyObject = @{
    name = $repoName
    project = @{
        name = $vstsProjectName
    }
}
$jsonBody = ConvertTo-Json -InputObject $jsonBodyObject
$repo = Invoke-VSTeamRequest -Method Post -Area git -Resource repositories -Body $jsonBody -ContentType 'application/json' -version '5.1-preview'

Expected behavior

Project is created without error.

Actual behavior

$resp = Invoke-RestMethod @params
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"$id":"1","innerException":null,"message":"Invalid argument value.\r\nParameter name: The project ID in the URI does not match the project ID in the
     | request.","typeName":"Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException,
     | Microsoft.TeamFoundation.SourceControl.WebServer","typeKey":"InvalidArgumentValueException","errorCode":0,"eventId":0}

Environment data

OS

Server

> Get-VSTeamAPIVersion

Name                           Value
----                           -----
Packaging                      5.1-preview
VariableGroups                 5.0-preview.1
Git                            5.1-preview
TaskGroups                     5.1-preview.1
ServiceFabricEndpoint          5.0-preview
Build                          5.0-preview
Graph                          5.1-preview
MemberEntitlementManagement    5.1-preview
Release                        5.1-preview
Tfvc                           5.0
Version                        VSTS
ExtensionsManagement           5.1-preview
Core                           5.0
DistributedTask                5.0-preview
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.1
PSEdition                      Core
GitCommitId                    7.0.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
SebastianSchuetze commented 4 years ago

thx for reporting! We will check this.

SebastianSchuetze commented 4 years ago

@tgossler it seems to me that there is an issue for this and it does not seem to be a problem of the module, but the API. But I will check more

https://developercommunity.visualstudio.com/content/problem/547038/selected-version-azure-devops-services-rest-api-fo.html

SebastianSchuetze commented 4 years ago

I checked a bit more and something is mixed up in your requirements.

You said in expected behaviour that a project should be created, but the API you are using is for working with repositories and forks.

https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-5.1#examples

In case you meant repository then also there is not an example that uses the name of the project with a new repository. Instead, the project Id is requested. If you changed your code to

$vstsProjectName = "project name with spaces"
Set-VSTeamAccount -Account $vstsAccountName -PersonalAccessToken $personalAccessToken
Set-VSTeamDefaultProject -Project $vstsProjectName
$project = Get-VSTeamProject -Name $vstsProjectName
$jsonBodyObject = @{
   name = $repoName
   project = @{       
       id = $project.ID
   }
}
$jsonBody = ConvertTo-Json -InputObject $jsonBodyObject
$repo = Invoke-VSTeamRequest -Method Post -Area git -Resource repositories -Body $jsonBody -ContentType 'application/json' -version '5.1-preview'

then the repository is created successfully.

If you intended to create a project, then you should use Add-VSTeamProject.

I am closing this as it seems to me that it is a wrong use of the API due to a probably inconsistent API and bad documentation.

thgossler commented 4 years ago

Hi,

you are right, I meant creating repos not projects.

I have tested this but it seems not to work. Do you seen an error in my code (see screenshot)?

[cid:image003.jpg@01D6488E.11A9B9A0]

From: Sebastian Schütze notifications@github.com Sent: Friday, June 19, 2020 7:47 PM To: DarqueWarrior/vsteam vsteam@noreply.github.com Cc: Gossler, Thomas (SHS DI DH TP PL) thomas.gossler@siemens-healthineers.com; Mention mention@noreply.github.com Subject: Re: [DarqueWarrior/vsteam] Project name with spaces causing problems (#334)

I checked a bit more and something is mixed up in your requirements.

You said in expected behaviour that a project should be created, but the API you are using is for working with repositories and forks.

https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/create?view=azure-devops-rest-5.1#examples

In case you meant repository then also there is not an example that uses the name of the project with a new repository. Instead, the project Id is requested. If you changed your code to

$vstsProjectName = "project name with spaces"

Set-VSTeamAccount -Account $vstsAccountName -PersonalAccessToken $personalAccessToken

Set-VSTeamDefaultProject -Project $vstsProjectName

$project = Get-VSTeamProject -Name $vstsProjectName

$jsonBodyObject = @{

name = $repoName

project = @{

   id = $project.ID

}

}

$jsonBody = ConvertTo-Json -InputObject $jsonBodyObject

$repo = Invoke-VSTeamRequest -Method Post -Area git -Resource repositories -Body $jsonBody -ContentType 'application/json' -version '5.1-preview'

then the repository is created successfully.

If you intended to create a project, then you should use Add-VSTeamProject.

I am closing this as it seems to me that it is a wrong use of the API due to a probably inconsistent API and bad documentation.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DarqueWarrior/vsteam/issues/334#issuecomment-646788221, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AN2MQJRYQ4A24KTXO7QMWOLRXOP6HANCNFSM4N5U6NIQ.

SebastianSchuetze commented 4 years ago

@tgossler there is no screenshot added. Answering via mail is not the best option when answering GitHub issues. Could you add your screenshot or the code you used?

thgossler commented 4 years ago

Sorry, I have added the screenshot above.