|
59 | 59 | $this.RepositorySelection = $Object.repository_selection
|
60 | 60 | $this.Permissions = [GitHubPermission]::NewPermissionList($Object.permissions, $this.Type)
|
61 | 61 | $this.Events = , ($Object.events)
|
62 |
| - $this.FilePaths = $Object.single_file_paths |
| 62 | + $this.FilePaths = , ($Object.single_file_paths) |
63 | 63 | $this.CreatedAt = $Object.created_at
|
64 | 64 | $this.UpdatedAt = $Object.updated_at
|
65 | 65 | $this.SuspendedAt = $Object.suspended_at
|
|
76 | 76 | $this.RepositorySelection = $Object.repository_selection
|
77 | 77 | $this.Permissions = [GitHubPermission]::NewPermissionList($Object.permissions, $this.Type)
|
78 | 78 | $this.Events = , ($Object.events)
|
79 |
| - $this.FilePaths = $Object.single_file_paths |
| 79 | + $this.FilePaths = , ($Object.single_file_paths) |
80 | 80 | $this.CreatedAt = $Object.created_at
|
81 | 81 | $this.UpdatedAt = $Object.updated_at
|
82 | 82 | $this.SuspendedAt = $Object.suspended_at
|
83 | 83 | $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
|
84 | 84 | $this.Url = $Object.html_url
|
85 |
| - $this.UpdateStatus() |
| 85 | + $this.SetStatus() |
86 | 86 | }
|
87 | 87 |
|
88 |
| - GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [GitHubContext] $Context) { |
| 88 | + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) { |
89 | 89 | $this.ID = $Object.id
|
90 | 90 | $this.App = [GitHubApp]::new(
|
91 | 91 | [PSCustomObject]@{
|
|
96 | 96 | $this.Target = [GitHubOwner]@{
|
97 | 97 | Name = $Target
|
98 | 98 | Type = $Type
|
99 |
| - Url = "https://$($Context.HostName)/$Target" |
| 99 | + Url = "https://$HostName/$Target" |
100 | 100 | }
|
101 | 101 | $this.Type = $Type
|
102 | 102 | $this.RepositorySelection = $Object.repository_selection
|
|
107 | 107 | $this.UpdatedAt = $Object.updated_at
|
108 | 108 | $this.SuspendedAt = $Object.suspended_at
|
109 | 109 | $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by)
|
110 |
| - $this.Url = "https://$($Context.HostName)/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" |
| 110 | + $this.Url = "https://$HostName/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" |
111 | 111 | $this.Status = 'Unknown'
|
112 | 112 | }
|
113 | 113 |
|
114 |
| - GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [GitHubContext] $Context, [GitHubApp] $App) { |
115 |
| - $this.ID = $Object.id |
116 |
| - $this.App = $App |
117 |
| - $this.Target = [GitHubOwner]@{ |
118 |
| - Name = $Target |
119 |
| - Type = $Type |
120 |
| - Url = "https://$($Context.HostName)/$Target" |
121 |
| - } |
122 |
| - $this.Type = $Type |
123 |
| - $this.RepositorySelection = $Object.repository_selection |
124 |
| - $this.Permissions = [GitHubPermission]::NewPermissionList($Object.permissions, $this.Type) |
125 |
| - $this.Events = , ($Object.events) |
126 |
| - $this.FilePaths = $Object.single_file_paths |
127 |
| - $this.CreatedAt = $Object.created_at |
128 |
| - $this.UpdatedAt = $Object.updated_at |
129 |
| - $this.SuspendedAt = $Object.suspended_at |
130 |
| - $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) |
131 |
| - $this.Url = "https://$($Context.HostName)/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" |
132 |
| - $this.UpdateStatus() |
133 |
| - } |
134 |
| - |
135 | 114 | # Updates the Status property by comparing installation permissions with app permissions
|
136 | 115 | # filtered by the appropriate scope based on installation type
|
137 |
| - [void] UpdateStatus() { |
| 116 | + [void] SetStatus() { |
138 | 117 | if (-not $this.App -or -not $this.App.Permissions) {
|
139 | 118 | $this.Status = 'Unknown'
|
140 | 119 | return
|
141 | 120 | }
|
| 121 | + if (-not $this.Permissions) { |
| 122 | + $this.Status = 'Unknown' |
| 123 | + return |
| 124 | + } |
142 | 125 |
|
143 | 126 | # Get app permissions filtered by installation type scope
|
144 | 127 | $appPermissionsFiltered = switch ($this.Type) {
|
|
156 | 139 | }
|
157 | 140 | }
|
158 | 141 |
|
159 |
| - # Compare permissions by creating lookup dictionaries |
160 |
| - $appPermissionLookup = @{} |
161 |
| - foreach ($perm in $appPermissionsFiltered) { |
162 |
| - $appPermissionLookup[$perm.Name] = $perm.Value |
163 |
| - } |
164 |
| - |
165 |
| - $installationPermissionLookup = @{} |
166 |
| - foreach ($perm in $this.Permissions) { |
167 |
| - $installationPermissionLookup[$perm.Name] = $perm.Value |
168 |
| - } |
169 |
| - |
170 |
| - # Check if permissions match |
171 |
| - $permissionsMatch = $true |
172 |
| - |
173 |
| - # Check if all app permissions exist in installation with same values |
174 |
| - foreach ($name in $appPermissionLookup.Keys) { |
175 |
| - if (-not $installationPermissionLookup.ContainsKey($name) -or |
176 |
| - $installationPermissionLookup[$name] -ne $appPermissionLookup[$name]) { |
177 |
| - $permissionsMatch = $false |
178 |
| - break |
179 |
| - } |
180 |
| - } |
181 |
| - |
182 |
| - # Check if installation has any extra permissions not in the app |
183 |
| - if ($permissionsMatch) { |
184 |
| - foreach ($name in $installationPermissionLookup.Keys) { |
185 |
| - if (-not $appPermissionLookup.ContainsKey($name)) { |
186 |
| - $permissionsMatch = $false |
187 |
| - break |
188 |
| - } |
189 |
| - } |
190 |
| - } |
| 142 | + $permissionsMatch = Compare-Object -ReferenceObject $appPermissionsFiltered -DifferenceObject $this.Permissions | Measure-Object |
191 | 143 |
|
192 | 144 | $this.Status = $permissionsMatch ? 'Ok' : 'Outdated'
|
193 | 145 | }
|
|
0 commit comments