Skip to content

Commit

Permalink
Merge pull request #74 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 11, 2025
2 parents ec60bee + 22bd356 commit c01f876
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CommunityRepos.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Owner": "CyberDrain",
"Visibility": "public",
"WriteAccess": false,
"DefaultBranch": "main",
"RepoPermissions": {
"admin": false,
"maintain": false,
Expand All @@ -25,6 +26,7 @@
"Owner": "j0eyv",
"Visibility": "public",
"WriteAccess": false,
"DefaultBranch": "main",
"RepoPermissions": {
"admin": false,
"maintain": false,
Expand All @@ -42,6 +44,7 @@
"Owner": "SkipToTheEndpoint",
"Visibility": "public",
"WriteAccess": false,
"DefaultBranch": "main",
"RepoPermissions": {
"admin": false,
"maintain": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ function Invoke-ExecCommunityRepo {
'Add' {
$Repo = Invoke-GitHubApiRequest -Path "repositories/$($Id)"
$RepoEntity = @{
PartitionKey = 'CommunityRepos'
RowKey = [string]$Repo.id
Name = [string]$Repo.name
Description = [string]$Repo.description
URL = [string]$Repo.html_url
FullName = [string]$Repo.full_name
Owner = [string]$Repo.owner.login
Visibility = [string]$Repo.visibility
WriteAccess = [bool]$Repo.permissions.push
Permissions = [string]($Repo.permissions | ConvertTo-Json -Compress)
PartitionKey = 'CommunityRepos'
RowKey = [string]$Repo.id
Name = [string]$Repo.name
Description = [string]$Repo.description
URL = [string]$Repo.html_url
FullName = [string]$Repo.full_name
Owner = [string]$Repo.owner.login
Visibility = [string]$Repo.visibility
WriteAccess = [bool]$Repo.permissions.push
DefaultBranch = [string]$Repo.default_branch
Permissions = [string]($Repo.permissions | ConvertTo-Json -Compress)
}

Add-CIPPAzDataTableEntity @Table -Entity $RepoEntity -Force | Out-Null
Expand All @@ -46,17 +47,18 @@ function Invoke-ExecCommunityRepo {
if ($RepoEntity) {
$Repo = Invoke-GitHubApiRequest -Path "repositories/$($Id)"
$Update = @{
PartitionKey = 'CommunityRepos'
RowKey = [string]$Repo.id
Name = [string]$Repo.name
Description = [string]$Repo.description
URL = [string]$Repo.html_url
FullName = [string]$Repo.full_name
Owner = [string]$Repo.owner.login
Visibility = [string]$Repo.visibility
WriteAccess = [bool]$Repo.permissions.push
Permissions = [string]($Repo.permissions | ConvertTo-Json -Compress)
ETag = $RepoEntity.ETag
PartitionKey = 'CommunityRepos'
RowKey = [string]$Repo.id
Name = [string]$Repo.name
Description = [string]$Repo.description
URL = [string]$Repo.html_url
FullName = [string]$Repo.full_name
Owner = [string]$Repo.owner.login
Visibility = [string]$Repo.visibility
WriteAccess = [bool]$Repo.permissions.push
DefaultBranch = [string]$Repo.default_branch
Permissions = [string]($Repo.permissions | ConvertTo-Json -Compress)
ETag = $RepoEntity.ETag
}

Update-CIPPAzDataTableEntity @Table -Entity $Update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ function Invoke-ExecGitHubAction {
param($Request, $TriggerMetadata)

$Action = $Request.Query.Action ?? $Request.Body.Action
$SplatParams = ($Request.Query ?? $Request.Body) | Select-Object -ExcludeProperty Action, TenantFilter | ConvertTo-Json | ConvertFrom-Json -AsHashtable

if ($Request.Query.Action) {
$Parameters = $Request.Query
} else {
$Parameters = $Request.Body
}

$SplatParams = $Parameters | Select-Object -ExcludeProperty Action, TenantFilter | ConvertTo-Json | ConvertFrom-Json -AsHashtable

#Write-Information ($SplatParams | ConvertTo-Json)

switch ($Action) {
'Search' {
$Results = (Search-GitHub @SplatParams).items
$SearchResults = Search-GitHub @SplatParams
$Results = @($SearchResults.items)
$Metadata = $SearchResults | Select-Object -Property total_count, incomplete_results
}
'GetFileContents' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ function Invoke-ListCommunityRepos {
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)
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
DefaultBranch = $Repo.DefaultBranch
Permissions = [string]($Repo.RepoPermissions | ConvertTo-Json)
}
Add-CIPPAzDataTableEntity @Table -Entity $Entity
$DefaultsMissing = $true
Expand All @@ -52,6 +53,7 @@ function Invoke-ListCommunityRepos {
Owner = $_.Owner
Visibility = $_.Visibility
WriteAccess = $_.WriteAccess
DefaultBranch = $_.DefaultBranch
RepoPermissions = $_.Permissions | ConvertFrom-Json
}
}
Expand Down
16 changes: 11 additions & 5 deletions Modules/CippExtensions/Public/GitHub/Get-GitHubFileContents.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
function Get-GitHubFileContents {
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName = $true)]
$Url
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
$FullName,

[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
$Path,

[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
$Branch
)

process {
[uri]$Uri = $Url
$Path = $Uri.PathAndQuery.TrimStart('/')
$File = Invoke-GitHubApiRequest -Path "$Path" -Method GET
$Path = "repos/$($FullName)/contents/$($Path)?ref=$($Branch)"
#Write-Information $Path
$File = Invoke-GitHubApiRequest -Path $Path -Method GET

return [PSCustomObject]@{
name = $File.name
Expand Down

0 comments on commit c01f876

Please sign in to comment.