Skip to content

Commit

Permalink
github updates
Browse files Browse the repository at this point in the history
adding default repositories
  • Loading branch information
JohnDuprey committed Feb 10, 2025
1 parent 41b1dd9 commit 94b082c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 18 deletions.
53 changes: 53 additions & 0 deletions CommunityRepos.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +57,7 @@ function Invoke-ListCommunityRepos {
}

$Body = @{
Results = @($Repos)
Results = @($Repos | Sort-Object -Property FullName)
}

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
Expand Down
16 changes: 10 additions & 6 deletions Modules/CippExtensions/Public/GitHub/Invoke-GitHubApiRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
16 changes: 6 additions & 10 deletions Modules/CippExtensions/Public/GitHub/Search-GitHub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ function Search-GitHub {
[CmdletBinding()]
Param (
[string[]]$Repository,
[string[]]$User,
[string]$User,
[string]$Org,
[string]$Path,
[string[]]$SearchTerm,
[string]$Language,
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 94b082c

Please sign in to comment.