Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
28d6854
🚀 [Feature]: Update links and documentation format for GitHub workflo…
MariusStorhaug Apr 24, 2025
a7c8566
🚀 [Feature]: Add URL property to GitHubTeam class and update related …
MariusStorhaug Apr 24, 2025
dbe3f3b
🚀 [Feature]: Simplify GraphQL query structure in Get-GitHubTeamBySlug…
MariusStorhaug Apr 24, 2025
8bfd564
🚀 [Feature]: Update Get-GitHubTeam and Update-GitHubTeam functions to…
MariusStorhaug Apr 24, 2025
f64e9bc
🪲 [Fix]: Comment out flaky tests for Update-GitHubUser to prevent fal…
MariusStorhaug Apr 25, 2025
8b50b1c
🚀 [Fix]: Update example in Get-GitHubRepository documentation to use …
MariusStorhaug Apr 25, 2025
f2e7d3e
🚀 [Feature]: Refactor GitHub team functions to consistently use 'Orga…
MariusStorhaug Apr 26, 2025
f766e10
🚀 [Refactor]: Make 'Organization' parameter mandatory in Get-GitHubTe…
MariusStorhaug Apr 26, 2025
3e1d41d
🚀 [Refactor]: Simplify output logic in Get-GitHubTeamBySlug function …
MariusStorhaug Apr 26, 2025
c0c9075
🚀 [Refactor]: Consolidate GraphQL query input structure in Get-GitHub…
MariusStorhaug Apr 26, 2025
bb5a3d6
🚀 [Refactor]: Replace Write-Verbose with Write-Host for output loggin…
MariusStorhaug Apr 26, 2025
737d175
🚀 [Refactor]: Update repository naming convention in test scripts to …
MariusStorhaug Apr 26, 2025
4ad901b
🚀 [Refactor]: Update repository variable references in Secrets.Tests.…
MariusStorhaug Apr 26, 2025
a819388
🚀 [Refactor]: Enhance error handling in Invoke-GitHubAPI by formattin…
MariusStorhaug Apr 26, 2025
e637815
🚀 [Refactor]: Simplify error logging in Invoke-GitHubAPI by directly …
MariusStorhaug Apr 26, 2025
0f26ec3
🚀 [Refactor]: Improve error logging in Invoke-GitHubAPI by restructur…
MariusStorhaug Apr 26, 2025
be9d08e
🚀 [Refactor]: Simplify error logging in Invoke-GitHubAPI by consolida…
MariusStorhaug Apr 26, 2025
b8effb2
🚀 [Refactor]: Enhance error logging in Invoke-GitHubAPI by adding tok…
MariusStorhaug Apr 26, 2025
eec7886
🚀 [Refactor]: Update variable and secret names in Secrets.Tests.ps1 a…
MariusStorhaug Apr 26, 2025
c999f9b
🚀 [Refactor]: Define organization secret and variable names in Secret…
MariusStorhaug Apr 26, 2025
42f6d9e
🚀 [Refactor]: Simplify error logging in Invoke-GitHubAPI by removing …
MariusStorhaug Apr 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/classes/public/Teams/GitHubTeam.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# The description of the team.
[string] $Description

# The HTML URL of the team.
# Example: https://github.com/orgs/github/teams/justice-league
[string] $Url

# The notification setting the team has chosen.
# $true = notifications_enabled - team members receive notifications when the team is @mentioned.
# $false = notifications_disabled - no one receives notifications.
Expand Down
112 changes: 51 additions & 61 deletions src/functions/private/Teams/Get-GitHubTeamBySlug.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
[OutputType([GitHubTeam])]
[CmdletBinding()]
param(
# The slug of the team name.
[Parameter(Mandatory)]
[Alias('team_slug')]
[string] $Slug,

# The organization name. The name is not case sensitive.
# If not provided, the owner from the context will be used.
[Parameter()]
[Parameter(Mandatory)]
[string] $Organization,

# The slug of the team name.
[Parameter(Mandatory)]
[string] $Slug,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter(Mandatory)]
Expand All @@ -36,72 +35,63 @@
}

process {
$query = @"
query(`$org: String!, `$teamSlug: String!) {
organization(login: `$org) {
team(slug: `$teamSlug) {
id
$inputObject = @{
Query = @'
query($org: String!, $teamSlug: String!) {
organization(login: $org) {
team(slug: $teamSlug) {
id
name
slug
url
combinedSlug
databaseId
description
notificationSetting
privacy
parentTeam {
name
slug
combinedSlug
databaseId
description
notificationSetting
privacy
parentTeam {
}
childTeams(first: 100) {
nodes {
name
slug
}
organization {
login
}
childTeams(first: 100) {
nodes {
name
}
}
createdAt
updatedAt
}
createdAt
updatedAt
}
}
}
"@

# Variables hash that will be sent with the query
$variables = @{
org = $Organization
teamSlug = $Slug
'@
Variables = @{
org = $Organization
teamSlug = $Slug
}
Context = $Context
}

# Send the request to the GitHub GraphQL API
$data = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context

# Extract team data
$data = Invoke-GitHubGraphQLQuery @inputObject
$team = $data.organization.team

# Output the team object
if (-not $team) {
return
if ($team) {
[GitHubTeam](
@{
Name = $team.name
Slug = $team.slug
NodeID = $team.id
Url = $team.url
CombinedSlug = $team.CombinedSlug
ID = $team.DatabaseId
Description = $team.description
Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
Visible = $team.privacy -eq 'VISIBLE' ? $true : $false
ParentTeam = $team.parentTeam.slug
Organization = $Organization
ChildTeams = $team.childTeams.nodes.name
CreatedAt = $team.createdAt
UpdatedAt = $team.updatedAt
}
)
}

[GitHubTeam](
@{
Name = $team.name
Slug = $team.slug
NodeID = $team.id
CombinedSlug = $team.CombinedSlug
ID = $team.DatabaseId
Description = $team.description
Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
Visible = $team.privacy -eq 'VISIBLE' ? $true : $false
ParentTeam = $team.parentTeam.slug
Organization = $team.organization.login
ChildTeams = $team.childTeams.nodes.name
CreatedAt = $team.createdAt
UpdatedAt = $team.updatedAt
}
)
}

end {
Expand Down
43 changes: 15 additions & 28 deletions src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

.EXAMPLE
Get-GitHubTeamListByOrg -Organization 'github'

.NOTES
[List teams](https://docs.github.com/rest/teams/teams#list-teams)
#>
[OutputType([GitHubTeam[]])]
[CmdletBinding()]
Expand All @@ -33,14 +30,16 @@
}

process {
$query = @"
query(`$org: String!, `$after: String) {
organization(login: `$org) {
teams(first: 100, after: `$after) {
$inputObject = @{
Query = @'
query($org: String!, $after: String) {
organization(login: $org) {
teams(first: 100, after: $after) {
nodes {
id
name
slug
url
combinedSlug
databaseId
description
Expand All @@ -50,9 +49,6 @@ query(`$org: String!, `$after: String) {
name
slug
}
organization {
login
}
childTeams(first: 100) {
nodes {
name
Expand All @@ -68,49 +64,40 @@ query(`$org: String!, `$after: String) {
}
}
}
"@

# Variables hash that will be sent with the query
$variables = @{
org = $Organization
'@
Variables = @{
org = $Organization
}
Context = $Context
}

# Prepare to store results and handle pagination
$hasNextPage = $true
$after = $null

do {
# Update the cursor for pagination
$variables['after'] = $after

# Send the request to the GitHub GraphQL API
$data = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context

# Extract team data
$inputObject['Variables']['after'] = $after
$data = Invoke-GitHubGraphQLQuery @inputObject
$teams = $data.organization.teams

# Accumulate the teams in results
$teams.nodes | ForEach-Object {
[GitHubTeam](
@{
Name = $_.name
Slug = $_.slug
NodeID = $_.id
Url = $_.url
CombinedSlug = $_.combinedSlug
ID = $_.databaseId
Description = $_.description
Notifications = $_.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
Visible = $_.privacy -eq 'VISIBLE' ? $true : $false
ParentTeam = $_.parentTeam.slug
Organization = $_.organization.login
Organization = $Organization
ChildTeams = $_.childTeams.nodes.name
CreatedAt = $_.createdAt
UpdatedAt = $_.updatedAt
}
)
}

# Check if there's another page to fetch
$hasNextPage = $teams.pageInfo.hasNextPage
$after = $teams.pageInfo.endCursor
} while ($hasNextPage)
Expand Down
12 changes: 9 additions & 3 deletions src/functions/public/API/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,21 @@ filter Invoke-GitHubAPI {
Information = $errordetails.documentation_url
Status = $failure.Exception.Message
StatusCode = $errordetails.status
ErrorTime = Get-Date -Format 's'
}
$APICall.HttpVersion = $APICall.HttpVersion.ToString()
$APICall.Headers = $APICall.Headers | ConvertTo-Json
$APICall.Method = $APICall.Method.ToString()

$exception = @"
----------------------------------
Request:
$([pscustomobject]$APICall | Format-List -Property Headers, HttpVersion, Method, Uri, ContentType, Authentication, Token | Out-String)
----------------------------------
Response Headers:
$($headers | Format-List | Out-String)
----------------------------------
Error:
$($errorResult | Format-List | Out-String)
----------------------------------

"@
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Gets the repositories for the specified user.

.EXAMPLE
Get-GitHubRepository -Owner 'github' -Name 'octocat'
Get-GitHubRepository -Organization 'github' -Name 'octocat'

Gets the specified repository.

Expand Down
29 changes: 12 additions & 17 deletions src/functions/public/Teams/Get-GitHubTeam.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@
Get-GitHubTeam -Organization 'github' -Slug 'my-team-name'

Gets the team with the slug 'my-team-name' in the `github` organization.

.NOTES
[List teams](https://docs.github.com/rest/teams/teams#list-teams)

.LINK
https://psmodule.io/GitHub/Functions/Teams/Get-GitHubTeam
#>
[OutputType([GitHubTeam])]
[CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
[CmdletBinding(DefaultParameterSetName = 'List all teams in an organization')]
param(
# The slug of the team name.
[Parameter(
Mandatory,
ParameterSetName = 'BySlug'
)]
[Alias('team_slug')]
[string] $Slug,

# The organization name. The name is not case sensitive.
# If not provided, the owner from the context will be used.
[Parameter()]
[Parameter(Mandatory)]
[string] $Organization,

# The slug of the team name.
[Parameter(Mandatory, ParameterSetName = 'BySlug')]
[string] $Slug,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
Expand All @@ -45,11 +47,6 @@
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT

if ([string]::IsNullOrEmpty($Organization)) {
$Organization = $Context.Owner
}
Write-Debug "Organization: [$Organization]"
}

process {
Expand All @@ -71,5 +68,3 @@
Write-Debug "[$stackPath] - End"
}
}

#SkipTest:FunctionTest:Will add a test for this function in a future PR
Loading