Skip to content

Commit 7baaed8

Browse files
🩹 [Patch]: Cleanup of Context usage in classes, and functions for Repository Rule Suites (Insights) (#461)
## Description This pull request introduces several changes across multiple files to enhance the functionality and structure of GitHub-related classes in the codebase. The most notable updates include replacing `HostName` with `GitHubContext` for improved context management, restructuring properties in `GitHubOwner` subclasses, and updating XML format definitions to reflect the new structure. - Fixes #454 ### Context Management Updates: * Replaced the `HostName` parameter with `GitHubContext` in constructors across multiple classes (`GitHubAppInstallation`, `GitHubArtifact`, `GitHubEnvironment`, `GitHubOrganization`). This change centralizes context-related properties, such as `HostName`, for better scalability and readability. ### GitHubOwner Class Restructuring: * Removed redundant properties (e.g., `Company`, `Blog`, `Plan`) from the `GitHubOwner` class and its subclasses (`GitHubEnterprise`, `GitHubOrganization`, `GitHubUser`). Added new properties such as `Description` and `Website` to better align with GraphQL schema mappings. ### GraphQL Mapping Enhancements: * Introduced static `$PropertyToGraphQLMap` hashtables in `GitHubEnterprise` and `GitHubOrganization` classes to define mappings between class properties and GraphQL fields, improving maintainability and integration with GraphQL APIs. ### XML Format Updates: * Updated the `GitHubOwner.Format.ps1xml` file to include new properties (`DisplayName`, `CreatedAt`) in table views for improved visualization of `GitHubOwner` objects. Removed deprecated columns such as `Company` and `Plan`. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [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 12903bc commit 7baaed8

File tree

45 files changed

+534
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+534
-326
lines changed

.github/PSModule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Test:
22
CodeCoverage:
3-
PercentTarget: 0
3+
PercentTarget: 50

src/classes/public/App/GitHubAppInstallation.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
$this.Url = $Object.html_url
6666
}
6767

68-
GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) {
68+
GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [GitHubContext] $Context) {
6969
$this.ID = $Object.id
7070
$this.App = [GitHubApp]::new(
7171
[PSCustomObject]@{
@@ -77,7 +77,7 @@
7777
$this.Target = [GitHubOwner]@{
7878
Name = $Target
7979
Type = $Type
80-
Url = "https://$HostName/$Target"
80+
Url = "https://$($Context.HostName)/$Target"
8181
}
8282
$this.Type = $Type
8383
$this.RepositorySelection = $Object.repository_selection
@@ -88,6 +88,6 @@
8888
$this.UpdatedAt = $Object.updated_at
8989
$this.SuspendedAt = $Object.suspended_at
9090
$this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
91-
$this.Url = "https://$HostName/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)"
91+
$this.Url = "https://$($Context.HostName)/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)"
9292
}
9393
}

src/classes/public/Artifacts/GitHubArtifact.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737

3838
GitHubArtifact() {}
3939

40-
GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [string]$HostName) {
40+
GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) {
4141
$this.ID = $Object.id
4242
$this.NodeID = $Object.node_id
4343
$this.Name = $Object.name
4444
$this.Owner = $Owner
4545
$this.Repository = $Repository
4646
$this.Size = $Object.size_in_bytes
47-
$this.Url = "https://$($HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)"
47+
$this.Url = "https://$($Context.HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)"
4848
$this.ArchiveDownloadUrl = $Object.archive_download_url
4949
$this.Expired = $Object.expired
5050
$this.Digest = $Object.digest

src/classes/public/Environment/GitHubEnvironment.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
GitHubEnvironment() {}
3030

31-
GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository) {
31+
GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) {
3232
$this.ID = $Object.id
3333
$this.NodeID = $Object.node_id
3434
$this.Name = $Object.name
3535
$this.Owner = $Owner
3636
$this.Repository = $Repository
37+
$this.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($Object.id)/edit"
3738
$this.CreatedAt = $Object.created_at
3839
$this.UpdatedAt = $Object.updated_at
3940
$this.AdminsCanBypass = $Object.can_admins_bypass

src/classes/public/Owner/GitHubOwner.ps1

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,17 @@
1919
# Example: User
2020
[string] $Type
2121

22-
# The company the account is affiliated with.
23-
# Example: GitHub
24-
[string] $Company
25-
26-
# The blog URL of the account.
27-
# Example: https://github.com/blog
28-
[string] $Blog
29-
3022
# The location of the account.
3123
# Example: San Francisco
3224
[string] $Location
3325

34-
# The email of the account.
35-
# Example: [email protected]
36-
[string] $Email
37-
38-
# The Twitter username.
39-
# Example: monalisa
40-
[string] $TwitterUsername
41-
42-
# The number of public repositories.
43-
# Example: 2
44-
[System.Nullable[uint]] $PublicRepos
26+
# The description of the organization.
27+
# Example: A great organization
28+
[string] $Description
4529

46-
# The number of public gists.
47-
# Example: 1
48-
[System.Nullable[uint]] $PublicGists
49-
50-
# The number of followers.
51-
# Example: 20
52-
[System.Nullable[uint]] $Followers
53-
54-
# The number of accounts this account is following.
55-
# Example: 0
56-
[System.Nullable[uint]] $Following
30+
# The website URL of the account.
31+
# Example: https://github.com/blog
32+
[string] $Website
5733

5834
# The creation date of the account.
5935
# Example: 2008-01-14T04:33:35Z
@@ -63,10 +39,6 @@
6339
# Example: 2008-01-14T04:33:35Z
6440
[System.Nullable[datetime]] $UpdatedAt
6541

66-
# The user's plan.
67-
# Includes: Name, Collaborators, PrivateRepos, Space
68-
[GitHubPlan] $Plan
69-
7042
GitHubOwner() {}
7143

7244
GitHubOwner([PSCustomObject]$Object) {
@@ -78,20 +50,13 @@
7850
$this.Name = $Object.slug ?? $Object.login
7951
$this.DisplayName = $Object.name
8052
$this.AvatarUrl = $Object.avatar_url
81-
$this.Url = $Object.html_url
53+
$this.Url = $Object.html_url ?? $Object.url
8254
$this.Type = $Object.type
83-
$this.Company = $Object.company
84-
$this.Blog = $Object.website_url ?? $Object.blog
8555
$this.Location = $Object.location
86-
$this.Email = $Object.email
87-
$this.TwitterUsername = $Object.twitter_username
88-
$this.PublicRepos = $Object.public_repos
89-
$this.PublicGists = $Object.public_gists
90-
$this.Followers = $Object.followers
91-
$this.Following = $Object.following
56+
$this.Description = $Object.description ?? $Object.bio
57+
$this.Website = $Object.websiteUrl ?? $Object.blog
9258
$this.CreatedAt = $Object.created_at
9359
$this.UpdatedAt = $Object.updated_at
94-
$this.Plan = [GitHubPlan]::New($Object.plan)
9560
}
9661

9762
[string] ToString() {

src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
class GitHubEnterprise : GitHubOwner {
2-
# The description of the enterprise.
3-
# Example: A great enterprise
4-
[string] $Description
5-
6-
# The description of the enterprise, as HTML.
7-
# Example: <div>A great enterprise</div>
8-
[string] $DescriptionHTML
9-
10-
# The billing information for the organization.
11-
[GitHubBillingInfo] $BillingInfo
12-
13-
# The billing email address for the organization.
14-
# Example: [email protected]
15-
[string] $BillingEmail
16-
172
# The readme of the enterprise.
183
# Example: This is the readme for the enterprise
194
[string] $Readme
@@ -22,6 +7,22 @@
227
# Example: <p>This is the readme for the enterprise</p>
238
[string] $ReadmeHTML
249

10+
static [hashtable] $PropertyToGraphQLMap = @{
11+
ID = 'databaseId'
12+
NodeID = 'id'
13+
Name = 'slug'
14+
DisplayName = 'name'
15+
AvatarUrl = 'avatarUrl'
16+
Url = 'url'
17+
Website = 'websiteUrl'
18+
Location = 'location'
19+
CreatedAt = 'createdAt'
20+
UpdatedAt = 'updatedAt'
21+
Description = 'description'
22+
Readme = 'readme'
23+
ReadmeHTML = 'readmeHTML'
24+
}
25+
2526
GitHubEnterprise() {}
2627

2728
GitHubEnterprise([PSCustomObject] $Object) {
@@ -35,17 +36,13 @@
3536
$this.AvatarUrl = $Object.avatarUrl
3637
$this.Url = $Object.url
3738
$this.Type = $Object.type ?? 'Enterprise'
38-
$this.Company = $Object.company
39-
$this.Blog = $Object.websiteUrl
4039
$this.Location = $Object.location
40+
$this.Description = $Object.description
41+
$this.Website = $Object.websiteUrl
4142
$this.CreatedAt = $Object.createdAt
4243
$this.UpdatedAt = $Object.updatedAt
4344

4445
# From GitHubEnterprise
45-
$this.Description = $Object.description
46-
$this.DescriptionHTML = $Object.descriptionHTML
47-
$this.BillingEmail = $Object.billingEmail
48-
$this.BillingInfo = [GitHubBillingInfo]::new($Object.billingInfo)
4946
$this.Readme = $Object.readme
5047
$this.ReadmeHTML = $Object.readmeHTML
5148
}

src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
class GitHubOrganization : GitHubOwner {
2-
# The description of the organization.
3-
# Example: A great organization
4-
[string] $Description
2+
# The email of the account.
3+
# Example: [email protected]
4+
[string] $Email
5+
6+
# The Twitter username.
7+
# Example: monalisa
8+
[string] $TwitterUsername
9+
10+
# The user's plan.
11+
# Includes: Name, Collaborators, PrivateRepos, Space
12+
[GitHubPlan] $Plan
13+
14+
# The number of public repositories.
15+
# Example: 2
16+
[System.Nullable[uint]] $PublicRepos
17+
18+
# The number of public gists.
19+
# Example: 1
20+
[System.Nullable[uint]] $PublicGists
21+
22+
# The number of followers.
23+
# Example: 20
24+
[System.Nullable[uint]] $Followers
25+
26+
# The number of accounts this account is following.
27+
# Example: 0
28+
[System.Nullable[uint]] $Following
529

630
# The number of private gists.
731
# Example: 81
@@ -49,7 +73,7 @@
4973

5074
# Whether two-factor authentication is required for members.
5175
# Example: $true
52-
[System.Nullable[bool]] $TwoFactorRequirementEnabled
76+
[System.Nullable[bool]] $RequiresTwoFactorAuthentication
5377

5478
# The type of repositories members can create.
5579
# Example: all
@@ -134,54 +158,74 @@
134158
# The date and time when the organization was archived, if applicable.
135159
[System.Nullable[datetime]] $ArchivedAt
136160

161+
static [hashtable] $PropertyToGraphQLMap = @{
162+
ArchivedAt = 'archivedAt'
163+
AvatarUrl = 'avatarUrl'
164+
CreatedAt = 'createdAt'
165+
Description = 'description'
166+
DisplayName = 'name'
167+
Email = 'email'
168+
ID = 'databaseId'
169+
Location = 'location'
170+
Name = 'login'
171+
NodeID = 'id'
172+
IsVerified = 'isVerified'
173+
# MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories'
174+
# RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication'
175+
TwitterUsername = 'twitterUsername'
176+
UpdatedAt = 'updatedAt'
177+
Url = 'url'
178+
# RequireWebCommitSignoff = 'webCommitSignoffRequired'
179+
Website = 'websiteUrl'
180+
}
181+
137182
GitHubOrganization() {}
138183

139-
GitHubOrganization([PSCustomObject] $Object, [string] $HostName) {
184+
GitHubOrganization([PSCustomObject] $Object, [GitHubContext] $Context) {
140185
# From GitHubNode
141-
$this.ID = $Object.id
142-
$this.NodeID = $Object.node_id
186+
$this.ID = $Object.databaseId ?? $Object.id
187+
$this.NodeID = $Object.node_id ?? $Object.id
143188

144189
# From GitHubOwner
145190
$this.Name = $Object.login
146191
$this.DisplayName = $Object.name
147-
$this.AvatarUrl = $Object.avatar_url
148-
$this.Url = $Object.html_url ?? "https://$($HostName)/$($Object.login)"
149-
$this.Type = $Object.type
150-
$this.Company = $Object.company
151-
$this.Blog = $Object.blog
192+
$this.AvatarUrl = $Object.avatar_url ?? $Object.avatarUrl
193+
$this.Url = $Object.html_url ?? $Object.url ?? "https://$($Context.HostName)/$($Object.login)"
194+
$this.Type = $Object.type ?? 'Organization'
152195
$this.Location = $Object.location
196+
$this.Description = $Object.description
197+
$this.Website = $Object.website ?? $Object.blog
198+
$this.CreatedAt = $Object.created_at ?? $Object.createdAt
199+
$this.UpdatedAt = $Object.updated_at ?? $Object.updatedAt
200+
201+
# From GitHubOrganization
153202
$this.Email = $Object.email
154-
$this.TwitterUsername = $Object.twitter_username
203+
$this.TwitterUsername = $Object.twitter_username ?? $Object.twitterUsername
204+
$this.Plan = [GitHubPlan]::New($Object.plan)
155205
$this.PublicRepos = $Object.public_repos
156206
$this.PublicGists = $Object.public_gists
157207
$this.Followers = $Object.followers
158208
$this.Following = $Object.following
159-
$this.CreatedAt = $Object.created_at
160-
$this.UpdatedAt = $Object.updated_at
161-
$this.Plan = [GitHubPlan]::New($Object.plan)
162-
163-
# From GitHubOrganization
164-
$this.Description = $Object.description
165209
$this.PrivateGists = $Object.total_private_gists
166210
$this.TotalPrivateRepos = $Object.total_private_repos
167211
$this.OwnedPrivateRepos = $Object.owned_private_repos
168212
$this.DiskUsage = $Object.disk_usage
169213
$this.Collaborators = $Object.collaborators
170-
$this.IsVerified = $Object.is_verified
214+
$this.IsVerified = $Object.is_verified ?? $Object.isVerified
171215
$this.HasOrganizationProjects = $Object.has_organization_projects
172216
$this.HasRepositoryProjects = $Object.has_repository_projects
173217
$this.BillingEmail = $Object.billing_email
174218
$this.DefaultRepositoryPermission = $Object.default_repository_permission
175219
$this.MembersCanCreateRepositories = $Object.members_can_create_repositories
176-
$this.TwoFactorRequirementEnabled = $Object.two_factor_requirement_enabled
220+
$this.RequiresTwoFactorAuthentication = $Object.two_factor_requirement_enabled ?? $Object.requiresTwoFactorAuthentication
177221
$this.MembersAllowedRepositoryCreationType = $Object.members_allowed_repository_creation_type
178222
$this.MembersCanCreatePublicRepositories = $Object.members_can_create_public_repositories
179223
$this.MembersCanCreatePrivateRepositories = $Object.members_can_create_private_repositories
180224
$this.MembersCanCreateInternalRepositories = $Object.members_can_create_internal_repositories
181225
$this.MembersCanInviteCollaborators = $Object.members_can_invite_collaborators
182226
$this.MembersCanCreatePages = $Object.members_can_create_pages
183-
$this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories
184-
$this.RequireWebCommitSignoff = $Object.web_commit_signoff_required
227+
$this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories ?? $Object.membersCanForkPrivateRepositories
228+
$this.RequireWebCommitSignoff = $Object.web_commit_signoff_required ?? $Object.requiresTwoFactorAuthentication
185229
$this.DeployKeysEnabledForRepositories = $Object.deploy_keys_enabled_for_repositories
186230
$this.MembersCanCreatePublicPages = $Object.members_can_create_public_pages
187231
$this.MembersCanCreatePrivatePages = $Object.members_can_create_private_pages
@@ -194,7 +238,7 @@
194238
$this.SecretScanningPushProtectionCustomLinkEnabled = $Object.secret_scanning_push_protection_custom_link_enabled
195239
$this.SecretScanningPushProtectionCustomLink = $Object.secret_scanning_push_protection_custom_link
196240
$this.SecretScanningValidityChecksEnabled = $Object.secret_scanning_validity_checks_enabled
197-
$this.ArchivedAt = $Object.archived_at
241+
$this.ArchivedAt = $Object.archived_at ?? $Object.archivedAt
198242
}
199243

200244
[string] ToString() {

0 commit comments

Comments
 (0)