From 0c40d07bcd208a7ca9e72696482914b071b7fb49 Mon Sep 17 00:00:00 2001 From: Raymond LaRose Date: Fri, 25 Apr 2025 14:25:13 -0400 Subject: [PATCH] Remove Get-GiteaLFSFile function to streamline codebase; enhance clarity and maintainability. --- PS-GiteaUtilities/PS-GiteaUtilities.psm1 | 97 ------------------------ 1 file changed, 97 deletions(-) diff --git a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 index 6747365..a518878 100644 --- a/PS-GiteaUtilities/PS-GiteaUtilities.psm1 +++ b/PS-GiteaUtilities/PS-GiteaUtilities.psm1 @@ -305,103 +305,6 @@ Function Get-GiteaLFSConfiguration { } } -function Get-GiteaLFSFile { - [CmdletBinding()] - param( - [string]$giteaURL, - [Parameter(ValueFromPipelineByPropertyName)] - [string]$repoOwner, - [Parameter(ValueFromPipelineByPropertyName)] - [string]$repoName, - [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] - [Alias('FullName')] - [string[]]$Path, - [Parameter(ValueFromPipelineByPropertyName)] - [string]$branch = "main", - [string]$token - ) - - begin { - # Initialize results array - $results = @() - - # Use configuration if parameters aren't provided - if (-not $PSBoundParameters.ContainsKey('giteaURL') -or - -not $PSBoundParameters.ContainsKey('repoOwner') -or - -not $PSBoundParameters.ContainsKey('repoName') -or - -not $PSBoundParameters.ContainsKey('branch') -or - -not $PSBoundParameters.ContainsKey('token')) { - - $config = Get-GiteaConfiguration - if ($config) { - if (-not $PSBoundParameters.ContainsKey('giteaURL')) { $giteaURL = $config.giteaURL } - if (-not $PSBoundParameters.ContainsKey('repoOwner')) { $repoOwner = $config.defaultOwner } - if (-not $PSBoundParameters.ContainsKey('repoName')) { $repoName = $config.defaultRepo } - if (-not $PSBoundParameters.ContainsKey('branch')) { $branch = $config.defaultBranch } - if (-not $PSBoundParameters.ContainsKey('token')) { $token = $config.token } - } - } - - # Validate that we have all required parameters - $missingParams = @() - if (-not $giteaURL) { $missingParams += "giteaURL" } - if (-not $repoOwner) { $missingParams += "repoOwner" } - if (-not $repoName) { $missingParams += "repoName" } - if (-not $token) { $missingParams += "token" } - - if ($missingParams.Count -gt 0) { - throw "Missing required parameters: $($missingParams -join ', '). Either provide them directly or set them with Set-GiteaConfiguration." - } - - Write-Verbose "Parameters:" - Write-Verbose "giteaURL: $giteaURL" - Write-Verbose "repoOwner: $repoOwner" - Write-Verbose "repoName: $repoName" - Write-Verbose "Path: $Path" - Write-Verbose "token: $token" - - $headers = @{ - "Authorization" = "token $token" - "Accept" = "application/json" - } - } - - process { - $paths = $path - foreach ($path in $paths) { - Write-Verbose "Processing path: $path" - # Normalize the path format - replace backslashes with forward slashes and trim trailing slashes - $normalizedPath = $path -replace '\\', '/' -replace '/$', '' - $encodedPath = [System.Uri]::EscapeDataString($normalizedPath) - Write-Verbose "Normalized path: $normalizedPath" - Write-Verbose "Encoded path: $encodedPath" - $url = "$giteaURL" - $url += "/api/v1/repos" - $url += "/$repoOwner" - $url += "/$repoName" - $url += "/media" - # Only add the path component if it's not empty - if (-not [string]::IsNullOrWhiteSpace($normalizedPath)) { - $url += "/$encodedPath" - } - $url += "?ref=$branch" - Write-Verbose "URL: $url" - - try { - $response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers -ResponseHeadersVariable ResponseHeaders - - } - catch { - - } - } - } - - end { - return $ResponseHeaders - } - -} - Function Invoke-GiteaFileDownload { <# .SYNOPSIS