-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add teams api #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ae458d6
feat: added teams api
yuhnix 682007a
feat: added teams api
yuhnix af74f26
Merge branch 'main' into bp/teams-api
Manbearpiet 7a89643
refactor: Improve parameter annotations and streamline function logic…
Manbearpiet f901895
refactor: Simplify output handling and enhance parameter annotations …
Manbearpiet 34935e2
refactor: Rename Get-AzDoProjectTeams to Get-AzDoProjectTeam for clarity
Manbearpiet e32972d
refactor: Rename Get-AzDoTeamMembersExtended to Get-AzDoTeamMembers f…
Manbearpiet 13c073c
refactor: Rename Get-AzDoTeamMembers to Get-AzDoTeamMember for clarity
Manbearpiet 482fcc3
refactor: Update Get-AzDoTeamMember to use Get-AzDoProjectTeam for co…
Manbearpiet 8087957
refactor: Rename New-AzDoTeams to New-AzDoTeam for clarity and improv…
Manbearpiet b18a2e7
refactor: Update error handling to use ThrowTerminatingError for cons…
Manbearpiet ce85012
refactor: Enhance error handling in Get-AzDoProjectTeam to use ThrowT…
Manbearpiet 7d1478f
refactor: Improve error handling in Get-AzDoTeamMember for clearer er…
Manbearpiet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoAllTeams.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| function Get-AzDoAllTeams { | ||
| <# | ||
| .SYNOPSIS | ||
| This script gets all teams within an organization. | ||
| .DESCRIPTION | ||
| This script retrieves all teams within an organization using the Azure DevOps REST API. | ||
| .EXAMPLE | ||
| $params = @{ | ||
| CollectionUri = 'https://dev.azure.com/contoso/' | ||
| ExpandIdentity = $true | ||
| Mine = $true | ||
| } | ||
| Get-AzDoAllTeams @params | ||
|
|
||
| This example gets all teams within 'contoso' where the requesting user is a member. | ||
| .OUTPUTS | ||
| PSObject | ||
| .NOTES | ||
| #> | ||
| [CmdletBinding(SupportsShouldProcess)] | ||
| param ( | ||
| # Collection URI. e.g. https://dev.azure.com/contoso. | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [ValidateScript({ Validate-CollectionUri -CollectionUri $_ })] | ||
| [String] | ||
| $CollectionUri, | ||
|
|
||
| # Whether or not to return detailed identity info | ||
| [Parameter(ValueFromPipelineByPropertyName)] | ||
| [Switch] | ||
| $ExpandIdentity = $false, | ||
|
|
||
| # Filter only teams your identity is member of | ||
| [Parameter(ValueFromPipelineByPropertyName)] | ||
| [Switch] | ||
| $Mine = $false, | ||
|
|
||
| # Skip number N of results | ||
| [Parameter(ValueFromPipelineByPropertyName)] | ||
| [Int] | ||
| $Skip = 0, | ||
|
|
||
| # Show only top N results | ||
| [Parameter(ValueFromPipelineByPropertyName)] | ||
| [Int] | ||
| $Top = 0 | ||
| ) | ||
| process { | ||
| $result = @() | ||
| Write-Verbose "Starting function: Get-AzDoAllTeams" | ||
|
|
||
| $queryParams = @() | ||
| if ($ExpandIdentity) { | ||
| $queryParams += "`$expandIdentity=$ExpandIdentity" | ||
| } | ||
| if ($Mine) { | ||
| $queryParams += "`$mine=$Mine" | ||
| } | ||
| if ($Skip -gt 0) { | ||
| $queryParams += "`$skip=$Skip" | ||
| } | ||
| if ($Top -gt 0) { | ||
| $queryParams += "`$top=$Top" | ||
| } | ||
| $queryParams = $queryParams -join "&" | ||
|
|
||
| $uri = "$CollectionUri/_apis/teams" | ||
| $version = "7.1-preview.3" | ||
|
|
||
| $params = @{ | ||
| Uri = $uri | ||
| Version = $version | ||
| QueryParameters = $queryParams | ||
| Method = 'GET' | ||
| } | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($CollectionUri, "Get all teams in organization")) { | ||
| (Invoke-AzDoRestMethod @params).value | ForEach-Object { | ||
| [PSCustomObject]@{ | ||
| CollectionUri = $CollectionUri | ||
| ProjectName = $_.projectName | ||
| TeamName = $_.name | ||
| TeamId = $_.id | ||
| Description = $_.description | ||
| Url = $_.url | ||
| IdentityUrl = $_.identityUrl | ||
| } | ||
| } | ||
| } else { | ||
| Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)" | ||
| } | ||
| } | ||
| } | ||
90 changes: 90 additions & 0 deletions
90
AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoProjectTeam.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| function Get-AzDoProjectTeam { | ||
| <# | ||
| .SYNOPSIS | ||
| This script gets team details in a given project. | ||
| .DESCRIPTION | ||
| This script gets teams in a given project. | ||
| When used in a pipeline, you can use the pre-defined CollectionUri, ProjectName, and AccessToken (PAT) variables. | ||
| .EXAMPLE | ||
| $params = @{ | ||
| CollectionUri = 'https://dev.azure.com/contoso/' | ||
| ProjectName = 'Project 1' | ||
| TeamName = 'testteam' | ||
| } | ||
| Get-AzDoProjectTeam @params | ||
|
|
||
| This example gets the team 'testteam' in 'Project 1'. | ||
| .EXAMPLE | ||
| $params = @{ | ||
| CollectionUri = 'https://dev.azure.com/contoso/' | ||
| ProjectName = 'Project 1' | ||
| } | ||
| Get-AzDoProjectTeam @params | ||
|
|
||
| This example gets all teams in 'Project 1'. | ||
| .OUTPUTS | ||
| PSObject | ||
| #> | ||
| [CmdletBinding(SupportsShouldProcess)] | ||
| param ( | ||
| # Collection URI | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [ValidateScript({ Validate-CollectionUri -CollectionUri $_ })] | ||
| [string] | ||
| $CollectionUri, | ||
|
|
||
| # Project name of the project | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [string] | ||
| $ProjectName, | ||
|
|
||
| # team name | ||
| [Parameter(ValueFromPipelineByPropertyName)] | ||
| [string] | ||
| $TeamName | ||
| ) | ||
| process { | ||
| Write-Verbose "Starting function: Get-AzDoProjectTeam" | ||
|
|
||
| $params = @{ | ||
| uri = "$CollectionUri/_apis/projects/$ProjectName/teams" | ||
| version = "7.1-preview.3" | ||
| method = 'GET' | ||
| } | ||
| if ($PSCmdlet.ShouldProcess($CollectionUri, "Get teams from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) { | ||
| try { | ||
| $teams = (Invoke-AzDoRestMethod @params).value | ||
| } catch { | ||
| $PSCmdlet.ThrowTerminatingError((Write-AzDoError -message "Failed to get teams for project '$ProjectName'. Error: $_")) | ||
| } | ||
| if ($TeamName) { | ||
| $teams | Where-Object { $_.name -eq $TeamName } | ForEach-Object { | ||
| [PSCustomObject]@{ | ||
| CollectionURI = $CollectionUri | ||
| ProjectName = $ProjectName | ||
| TeamName = $_.name | ||
| TeamId = $_.id | ||
| Description = $_.description | ||
| Url = $_.url | ||
| IdentityUrl = $_.identityUrl | ||
| } | ||
| } | ||
| } else { | ||
| $teams | ForEach-Object { | ||
| [PSCustomObject]@{ | ||
| CollectionURI = $CollectionUri | ||
| ProjectName = $ProjectName | ||
| TeamName = $_.name | ||
| TeamId = $_.id | ||
| Description = $_.description | ||
| Url = $_.url | ||
| IdentityUrl = $_.identityUrl | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)" | ||
| } | ||
| } | ||
| } | ||
|
|
95 changes: 95 additions & 0 deletions
95
AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoTeamMember.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| function Get-AzDoTeamMember { | ||
| <# | ||
| .SYNOPSIS | ||
| This script gets team members with extended properties in a given project and team. | ||
| .DESCRIPTION | ||
| This script gets team members with extended properties in a given project and team. | ||
| When used in a pipeline, you can use the pre-defined CollectionUri, ProjectName, and AccessToken (PAT) variables. | ||
| .EXAMPLE | ||
| $params = @{ | ||
| CollectionUri = 'https://dev.azure.com/contos0' | ||
| ProjectName = 'Project 1' | ||
| TeamName = 'testteam' | ||
| } | ||
| Get-AzDoTeamMember @params | ||
|
|
||
| This example gets the team members with extended properties in 'testteam' within 'Project 1'. | ||
| .OUTPUTS | ||
| PSObject | ||
| .NOTES | ||
| #> | ||
| [CmdletBinding(SupportsShouldProcess)] | ||
| param ( | ||
| # Collection Uri of the organization | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [ValidateScript({ Validate-CollectionUri -CollectionUri $_ })] | ||
| [string] | ||
| $CollectionUri, | ||
|
|
||
| # the projectName | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [string] | ||
| $ProjectName, | ||
|
|
||
| # Team name of the team | ||
| [Parameter(Mandatory, ValueFromPipelineByPropertyName)] | ||
| [string] | ||
| $TeamName | ||
| ) | ||
|
|
||
| process { | ||
| Write-Verbose "Starting function: Get-AzDoTeamMember" | ||
|
|
||
| # Get the team ID using the Get-AzDoProjectTeam function | ||
| $teamParams = @{ | ||
| CollectionUri = $CollectionUri | ||
| ProjectName = $ProjectName | ||
| TeamName = $TeamName | ||
| } | ||
|
|
||
| try { | ||
| $team = Get-AzDoProjectTeam @teamParams | Where-Object { $_.TeamName -eq $TeamName } | ||
| if (-not $team) { | ||
| throw "Team '$TeamName' not found in project '$ProjectName'." | ||
| } | ||
|
|
||
| $teamId = $team.TeamId | ||
| Write-Verbose "Retrieved Team ID: $teamId" | ||
| } catch { | ||
| $PSCmdlet.ThrowTerminatingError((Write-AzDoError "Team '$TeamName' not found in project '$ProjectName'. Error: $_")) | ||
| } | ||
|
|
||
| $params = @{ | ||
| uri = "$CollectionUri/_apis/projects/$ProjectName/teams/$teamId/members" | ||
| version = "7.1-preview.2" | ||
| method = 'GET' | ||
| } | ||
|
|
||
| Write-Verbose "Request URI: $($params.uri)" | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($CollectionUri, "Get team members with extended properties from: $($PSStyle.Bold)$TeamName$($PSStyle.Reset) in project: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) { | ||
| try { | ||
| $members = (Invoke-AzDoRestMethod @params).value | ||
| if (-not $members) { | ||
| Write-Verbose "No members found for team '$TeamName'." | ||
| } else { | ||
| $members | ForEach-Object { | ||
| [PSCustomObject]@{ | ||
| CollectionUri = $CollectionUri | ||
| TeamName = $TeamName | ||
| ProjectName = $ProjectName | ||
| MemberId = $_.identity.id | ||
| DisplayName = $_.identity.displayName | ||
| UniqueName = $_.identity.uniqueName | ||
| IsTeamAdmin = $_.isTeamAdmin ? $true : $false | ||
| } | ||
| } | ||
| } | ||
| } catch { | ||
| $PSCmdlet.ThrowTerminatingError((Write-AzDoError "Error retrieving team members for '$TeamName' Error: $_")) | ||
| } | ||
| } else { | ||
| Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.