diff --git a/CommunityRepos.json b/CommunityRepos.json new file mode 100644 index 000000000000..0d76fe4a39f9 --- /dev/null +++ b/CommunityRepos.json @@ -0,0 +1,53 @@ +[ + { + "Id": "930523724", + "Name": "CIPP-Templates", + "Description": "CIPP Community Templates", + "URL": "https://github.com/CyberDrain/CIPP-Templates", + "FullName": "CyberDrain/CIPP-Templates", + "Owner": "CyberDrain", + "Visibility": "public", + "WriteAccess": false, + "RepoPermissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": true + } + }, + { + "Id": "784230225", + "Name": "ConditionalAccessBaseline", + "Description": "", + "URL": "https://github.com/j0eyv/ConditionalAccessBaseline", + "FullName": "j0eyv/ConditionalAccessBaseline", + "Owner": "j0eyv", + "Visibility": "public", + "WriteAccess": false, + "RepoPermissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": true + } + }, + { + "Id": "493403016", + "Name": "OpenIntuneBaseline", + "Description": "Community-driven baseline to accelerate Intune adoption and learning.", + "URL": "https://github.com/SkipToTheEndpoint/OpenIntuneBaseline", + "FullName": "SkipToTheEndpoint/OpenIntuneBaseline", + "Owner": "SkipToTheEndpoint", + "Visibility": "public", + "WriteAccess": false, + "RepoPermissions": { + "admin": false, + "maintain": false, + "push": false, + "triage": false, + "pull": true + } + } +] diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 index 44b5087a2ff0..58e03e6b196a 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tools/GitHub/Invoke-ListCommunityRepos.ps1 @@ -13,7 +13,36 @@ function Invoke-ListCommunityRepos { param($Request, $TriggerMetadata) $Table = Get-CIPPTable -TableName CommunityRepos - $Repos = Get-CIPPAzDataTableEntity @Table | ForEach-Object { + $Repos = Get-CIPPAzDataTableEntity @Table + + $CIPPRoot = (Get-Item (Get-Module -Name CIPPCore).ModuleBase).Parent.Parent.FullName + $CommunityRepos = Join-Path -Path $CIPPRoot -ChildPath 'CommunityRepos.json' + $DefaultCommunityRepos = Get-Content -Path $CommunityRepos -Raw | ConvertFrom-Json + + $DefaultsMissing = $false + foreach ($Repo in $DefaultCommunityRepos) { + if ($Repos.Url -notcontains $Repo.Url) { + $Entity = [PSCustomObject]@{ + PartitionKey = 'CommunityRepos' + RowKey = $Repo.Id + Name = $Repo.Name + Description = $Repo.Description + URL = $Repo.URL + FullName = $Repo.FullName + Owner = $Repo.Owner + Visibility = $Repo.Visibility + WriteAccess = $Repo.WriteAccess + Permissions = [string]($Repo.RepoPermissions | ConvertTo-Json) + } + Add-CIPPAzDataTableEntity @Table -Entity $Entity + $DefaultsMissing = $true + } + } + if ($DefaultsMissing) { + $Repos = Get-CIPPAzDataTableEntity @Table + } + + $Repos = $Repos | ForEach-Object { [pscustomobject]@{ Id = $_.RowKey Name = $_.Name @@ -28,7 +57,7 @@ function Invoke-ListCommunityRepos { } $Body = @{ - Results = @($Repos) + Results = @($Repos | Sort-Object -Property FullName) } Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ diff --git a/Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1 b/Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1 index 1ae9c28e6e8d..9f5b433caccd 100644 --- a/Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1 +++ b/Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1 @@ -34,12 +34,16 @@ function Invoke-GitHubApiRequest { $RestMethod.ResponseHeadersVariable = 'ResponseHeaders' } - $Response = Invoke-RestMethod @RestMethod - if ($ReturnHeaders.IsPresent) { - $ResponseHeaders - } else { - $Response - } + try { + $Response = Invoke-RestMethod @RestMethod + if ($ReturnHeaders.IsPresent) { + $ResponseHeaders + } else { + $Response + } + } catch { + Write-Error $_.Exception.Message + } } else { throw 'GitHub API is not enabled' } diff --git a/Modules/CippExtensions/Public/GitHub/Search-GitHub.ps1 b/Modules/CippExtensions/Public/GitHub/Search-GitHub.ps1 index 4d2ce0e02b60..c630d524c149 100644 --- a/Modules/CippExtensions/Public/GitHub/Search-GitHub.ps1 +++ b/Modules/CippExtensions/Public/GitHub/Search-GitHub.ps1 @@ -2,7 +2,8 @@ function Search-GitHub { [CmdletBinding()] Param ( [string[]]$Repository, - [string[]]$User, + [string]$User, + [string]$Org, [string]$Path, [string[]]$SearchTerm, [string]$Language, @@ -34,15 +35,10 @@ function Search-GitHub { } } if ($User) { - $UserParts = [System.Collections.Generic.List[string]]::new() - foreach ($U in $User) { - $UserParts.Add("user:$U") - } - if (($UserParts | Measure-Object).Count -gt 1) { - $QueryParts.Add('(' + ($UserParts -join ' OR ') + ')') - } else { - $QueryParts.Add($UserParts[0]) - } + $QueryParts.Add("user:$User") + } + if ($Org) { + $QueryParts.Add("org:$Org") } if ($Path) { $QueryParts.Add("path:$Path")