Skip to content

Commit 1d98daf

Browse files
🚀 [Feature]: Teams and Workflows cleanup (#368)
## Description This pull request introduces several updates focusing on enhancements to the Teams and Workflows functions. Key changes include adding the `Url` property for GitHub teams, improving query structures, refining parameters for public functions, and updating documentation links for workflows. ### Enhancements to Teams Functionality * Added a new `Url` property to the `GitHubTeam` class and updated related queries (`Get-GitHubTeamBySlug`, `Get-GitHubTeamListByOrg`, and `New-GitHubTeam`) to include the `url` field in their responses. * ⚠️ Refined parameter handling for several public functions (`Get-GitHubTeam`, `New-GitHubTeam`, `Remove-GitHubTeam`, `Update-GitHubTeam`) by renaming, reordering and clarifying mandatory parameters like `Organization` and `Slug` (previously `Name`). * Simplified logic for handling `ParentTeamID` in `New-GitHubTeam` by replacing a conditional check with direct nullable type usage. ### Documentation and Query Improvements * Updated `.NOTES` and `.LINK` sections in the documentation for all workflow-related functions to ensure accurate links and better clarity. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [x] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent b013aed commit 1d98daf

24 files changed

+389
-263
lines changed

src/classes/public/Teams/GitHubTeam.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# The description of the team.
1515
[string] $Description
1616

17+
# The HTML URL of the team.
18+
# Example: https://github.com/orgs/github/teams/justice-league
19+
[string] $Url
20+
1721
# The notification setting the team has chosen.
1822
# $true = notifications_enabled - team members receive notifications when the team is @mentioned.
1923
# $false = notifications_disabled - no one receives notifications.

src/functions/private/Teams/Get-GitHubTeamBySlug.ps1

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
[OutputType([GitHubTeam])]
1414
[CmdletBinding()]
1515
param(
16-
# The slug of the team name.
17-
[Parameter(Mandatory)]
18-
[Alias('team_slug')]
19-
[string] $Slug,
20-
2116
# The organization name. The name is not case sensitive.
2217
# If not provided, the owner from the context will be used.
23-
[Parameter()]
18+
[Parameter(Mandatory)]
2419
[string] $Organization,
2520

21+
# The slug of the team name.
22+
[Parameter(Mandatory)]
23+
[string] $Slug,
24+
2625
# The context to run the command in. Used to get the details for the API call.
2726
# Can be either a string or a GitHubContext object.
2827
[Parameter(Mandatory)]
@@ -36,72 +35,63 @@
3635
}
3736

3837
process {
39-
$query = @"
40-
query(`$org: String!, `$teamSlug: String!) {
41-
organization(login: `$org) {
42-
team(slug: `$teamSlug) {
43-
id
38+
$inputObject = @{
39+
Query = @'
40+
query($org: String!, $teamSlug: String!) {
41+
organization(login: $org) {
42+
team(slug: $teamSlug) {
43+
id
44+
name
45+
slug
46+
url
47+
combinedSlug
48+
databaseId
49+
description
50+
notificationSetting
51+
privacy
52+
parentTeam {
4453
name
4554
slug
46-
combinedSlug
47-
databaseId
48-
description
49-
notificationSetting
50-
privacy
51-
parentTeam {
55+
}
56+
childTeams(first: 100) {
57+
nodes {
5258
name
53-
slug
5459
}
55-
organization {
56-
login
57-
}
58-
childTeams(first: 100) {
59-
nodes {
60-
name
61-
}
62-
}
63-
createdAt
64-
updatedAt
6560
}
61+
createdAt
62+
updatedAt
6663
}
6764
}
6865
}
69-
"@
70-
71-
# Variables hash that will be sent with the query
72-
$variables = @{
73-
org = $Organization
74-
teamSlug = $Slug
66+
'@
67+
Variables = @{
68+
org = $Organization
69+
teamSlug = $Slug
70+
}
71+
Context = $Context
7572
}
76-
77-
# Send the request to the GitHub GraphQL API
78-
$data = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context
79-
80-
# Extract team data
73+
$data = Invoke-GitHubGraphQLQuery @inputObject
8174
$team = $data.organization.team
82-
83-
# Output the team object
84-
if (-not $team) {
85-
return
75+
if ($team) {
76+
[GitHubTeam](
77+
@{
78+
Name = $team.name
79+
Slug = $team.slug
80+
NodeID = $team.id
81+
Url = $team.url
82+
CombinedSlug = $team.CombinedSlug
83+
ID = $team.DatabaseId
84+
Description = $team.description
85+
Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
86+
Visible = $team.privacy -eq 'VISIBLE' ? $true : $false
87+
ParentTeam = $team.parentTeam.slug
88+
Organization = $Organization
89+
ChildTeams = $team.childTeams.nodes.name
90+
CreatedAt = $team.createdAt
91+
UpdatedAt = $team.updatedAt
92+
}
93+
)
8694
}
87-
88-
[GitHubTeam](
89-
@{
90-
Name = $team.name
91-
Slug = $team.slug
92-
NodeID = $team.id
93-
CombinedSlug = $team.CombinedSlug
94-
ID = $team.DatabaseId
95-
Description = $team.description
96-
Notifications = $team.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
97-
Visible = $team.privacy -eq 'VISIBLE' ? $true : $false
98-
ParentTeam = $team.parentTeam.slug
99-
Organization = $team.organization.login
100-
ChildTeams = $team.childTeams.nodes.name
101-
CreatedAt = $team.createdAt
102-
UpdatedAt = $team.updatedAt
103-
}
104-
)
10595
}
10696

10797
end {

src/functions/private/Teams/Get-GitHubTeamListByOrg.ps1

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
99
.EXAMPLE
1010
Get-GitHubTeamListByOrg -Organization 'github'
11-
12-
.NOTES
13-
[List teams](https://docs.github.com/rest/teams/teams#list-teams)
1411
#>
1512
[OutputType([GitHubTeam[]])]
1613
[CmdletBinding()]
@@ -33,14 +30,16 @@
3330
}
3431

3532
process {
36-
$query = @"
37-
query(`$org: String!, `$after: String) {
38-
organization(login: `$org) {
39-
teams(first: 100, after: `$after) {
33+
$inputObject = @{
34+
Query = @'
35+
query($org: String!, $after: String) {
36+
organization(login: $org) {
37+
teams(first: 100, after: $after) {
4038
nodes {
4139
id
4240
name
4341
slug
42+
url
4443
combinedSlug
4544
databaseId
4645
description
@@ -50,9 +49,6 @@ query(`$org: String!, `$after: String) {
5049
name
5150
slug
5251
}
53-
organization {
54-
login
55-
}
5652
childTeams(first: 100) {
5753
nodes {
5854
name
@@ -68,49 +64,40 @@ query(`$org: String!, `$after: String) {
6864
}
6965
}
7066
}
71-
"@
72-
73-
# Variables hash that will be sent with the query
74-
$variables = @{
75-
org = $Organization
67+
'@
68+
Variables = @{
69+
org = $Organization
70+
}
71+
Context = $Context
7672
}
77-
78-
# Prepare to store results and handle pagination
7973
$hasNextPage = $true
8074
$after = $null
8175

8276
do {
8377
# Update the cursor for pagination
84-
$variables['after'] = $after
85-
86-
# Send the request to the GitHub GraphQL API
87-
$data = Invoke-GitHubGraphQLQuery -Query $query -Variables $variables -Context $Context
88-
89-
# Extract team data
78+
$inputObject['Variables']['after'] = $after
79+
$data = Invoke-GitHubGraphQLQuery @inputObject
9080
$teams = $data.organization.teams
91-
92-
# Accumulate the teams in results
9381
$teams.nodes | ForEach-Object {
9482
[GitHubTeam](
9583
@{
9684
Name = $_.name
9785
Slug = $_.slug
9886
NodeID = $_.id
87+
Url = $_.url
9988
CombinedSlug = $_.combinedSlug
10089
ID = $_.databaseId
10190
Description = $_.description
10291
Notifications = $_.notificationSetting -eq 'NOTIFICATIONS_ENABLED' ? $true : $false
10392
Visible = $_.privacy -eq 'VISIBLE' ? $true : $false
10493
ParentTeam = $_.parentTeam.slug
105-
Organization = $_.organization.login
94+
Organization = $Organization
10695
ChildTeams = $_.childTeams.nodes.name
10796
CreatedAt = $_.createdAt
10897
UpdatedAt = $_.updatedAt
10998
}
11099
)
111100
}
112-
113-
# Check if there's another page to fetch
114101
$hasNextPage = $teams.pageInfo.hasNextPage
115102
$after = $teams.pageInfo.endCursor
116103
} while ($hasNextPage)

src/functions/public/API/Invoke-GitHubAPI.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,21 @@ filter Invoke-GitHubAPI {
315315
Information = $errordetails.documentation_url
316316
Status = $failure.Exception.Message
317317
StatusCode = $errordetails.status
318+
ErrorTime = Get-Date -Format 's'
318319
}
319-
$APICall.HttpVersion = $APICall.HttpVersion.ToString()
320-
$APICall.Headers = $APICall.Headers | ConvertTo-Json
321-
$APICall.Method = $APICall.Method.ToString()
322320

323321
$exception = @"
324322
----------------------------------
323+
Request:
324+
$([pscustomobject]$APICall | Format-List -Property Headers, HttpVersion, Method, Uri, ContentType, Authentication, Token | Out-String)
325+
----------------------------------
326+
Response Headers:
327+
$($headers | Format-List | Out-String)
328+
----------------------------------
329+
Error:
325330
$($errorResult | Format-List | Out-String)
326331
----------------------------------
332+
327333
"@
328334
$PSCmdlet.ThrowTerminatingError(
329335
[System.Management.Automation.ErrorRecord]::new(

src/functions/public/Repositories/Get-GitHubRepository.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Gets the repositories for the specified user.
2727
2828
.EXAMPLE
29-
Get-GitHubRepository -Owner 'github' -Name 'octocat'
29+
Get-GitHubRepository -Organization 'github' -Name 'octocat'
3030
3131
Gets the specified repository.
3232

src/functions/public/Teams/Get-GitHubTeam.ps1

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@
1717
Get-GitHubTeam -Organization 'github' -Slug 'my-team-name'
1818
1919
Gets the team with the slug 'my-team-name' in the `github` organization.
20+
21+
.NOTES
22+
[List teams](https://docs.github.com/rest/teams/teams#list-teams)
23+
24+
.LINK
25+
https://psmodule.io/GitHub/Functions/Teams/Get-GitHubTeam
2026
#>
2127
[OutputType([GitHubTeam])]
22-
[CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
28+
[CmdletBinding(DefaultParameterSetName = 'List all teams in an organization')]
2329
param(
24-
# The slug of the team name.
25-
[Parameter(
26-
Mandatory,
27-
ParameterSetName = 'BySlug'
28-
)]
29-
[Alias('team_slug')]
30-
[string] $Slug,
31-
3230
# The organization name. The name is not case sensitive.
3331
# If not provided, the owner from the context will be used.
34-
[Parameter()]
32+
[Parameter(Mandatory)]
3533
[string] $Organization,
3634

35+
# The slug of the team name.
36+
[Parameter(Mandatory, ParameterSetName = 'BySlug')]
37+
[string] $Slug,
38+
3739
# The context to run the command in. Used to get the details for the API call.
3840
# Can be either a string or a GitHubContext object.
3941
[Parameter()]
@@ -45,11 +47,6 @@
4547
Write-Debug "[$stackPath] - Start"
4648
$Context = Resolve-GitHubContext -Context $Context
4749
Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT
48-
49-
if ([string]::IsNullOrEmpty($Organization)) {
50-
$Organization = $Context.Owner
51-
}
52-
Write-Debug "Organization: [$Organization]"
5350
}
5451

5552
process {
@@ -71,5 +68,3 @@
7168
Write-Debug "[$stackPath] - End"
7269
}
7370
}
74-
75-
#SkipTest:FunctionTest:Will add a test for this function in a future PR

0 commit comments

Comments
 (0)