Skip to content

🩹 [Patch]: Update functions to take array pipeline input#6

Merged
Marius Storhaug (MariusStorhaug) merged 5 commits intomainfrom
copilot/fix-5
May 28, 2025
Merged

🩹 [Patch]: Update functions to take array pipeline input#6
Marius Storhaug (MariusStorhaug) merged 5 commits intomainfrom
copilot/fix-5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2025

This PR updates both conversion functions (ConvertTo-Base64 and ConvertFrom-Base64) to accept arrays as input, both directly and through the pipeline. These changes enable more flexible usage of the functions in PowerShell workflows that involve processing multiple values.

Changes:

  • Changed both functions from filter to function to better handle array inputs
  • Updated parameter types from [string] to [string[]] to accept arrays
  • Added process blocks with foreach loops to handle each input item
  • Updated function documentation to include examples with array inputs
  • Added tests to verify array handling capabilities:
    • Tests for direct parameter array inputs
    • Tests for pipeline array inputs

Examples:

# Before: Only worked with single strings
"Hello World" | ConvertTo-Base64  # Works
@("Hello", "World") | ConvertTo-Base64  # Would only output first value

# After: Works with both single strings and arrays
"Hello World" | ConvertTo-Base64  # Still works
@("Hello", "World") | ConvertTo-Base64  # Now returns both values converted
# Output:
# SGVsbG8=
# V29ybGQ=

Fixes #5.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copilot AI changed the title [WIP] 🩹 [Patch]: Update functions to take pipeline input 🩹 [Patch]: Update functions to take array pipeline input May 27, 2025
@MariusStorhaug
Copy link
Copy Markdown
Member

Please fix the linter issues:

  RuleName                            Severity     ScriptName Line  Message
  --------                            --------     ---------- ----  -------
  PSAvoidTrailingWhitespace           Information  Base64.Tes 18    Line has trai
                                                   ts.ps1           ling whitespa
                                                                    ce
  PSAvoidTrailingWhitespace           Information  Base64.Tes 41    Line has trai
                                                   ts.ps1           ling whitespa
                                                                    ce
                                                                    

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2025

Please fix the linter issues:

  RuleName                            Severity     ScriptName Line  Message

...

I've fixed the trailing whitespace issues in the Base64.Tests.ps1 file. The changes have been committed in 7621f82.

@MariusStorhaug
Copy link
Copy Markdown
Member

Lets also add:

  • a test that stores multiple stings in a variable and pipes the variable to the functions.
  • a test that loads content from a file and pipes the content to the functions.

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2025

Lets also add:

  • a test that stores multiple stings in a variable and pipes the variable to the functions.
  • a test that loads content from a file and pipes the content to the functions.

I've added the tests you requested in 5115fc6:

  1. Tests for storing multiple strings in variables and piping them to both functions
  2. Tests for loading content from files and piping to both functions

I also created a small test runner script (Run-Tests.ps1) that makes it easier to execute the tests by correctly importing the required functions.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.powershellgallery.com
    • Triggering command: pwsh -Command Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck; Invoke-ScriptAnalyzer -Path ./tests/Base64.Tests.ps1 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@MariusStorhaug
Copy link
Copy Markdown
Member

Move the code that is in tests/Run-Tests.ps1 to a BeforeAll block in the tests.

Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 28, 2025

Move the code that is in tests/Run-Tests.ps1 to a BeforeAll block in the tests.

I've moved the code from Run-Tests.ps1 to a BeforeAll block in the test file as requested. This keeps all the test setup code in one place and eliminates the need for a separate runner script. The BeforeAll block now imports the functions and sets up the test files. I also fixed the trailing whitespace issues that were detected by the linter. Changes are in commit de305c6.

@MariusStorhaug Marius Storhaug (MariusStorhaug) marked this pull request as ready for review May 28, 2025 00:54
Copilot AI review requested due to automatic review settings May 28, 2025 00:54
@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit 901c93f into main May 28, 2025
34 checks passed
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the copilot/fix-5 branch May 28, 2025 00:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the Base64 conversion functions to support array inputs and pipeline scenarios, and adds corresponding tests.

  • Changed both ConvertTo-Base64 and ConvertFrom-Base64 from filters to full functions and updated their String/Base64String parameters to accept string arrays.
  • Introduced process blocks with foreach loops to emit one result per input element.
  • Expanded documentation examples for array usage and added tests covering direct, pipeline, variable, and file-based inputs.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Base64.Tests.ps1 Added a BeforeAll setup, hard‐coded test files, and array handling tests for both functions
src/functions/public/ConvertTo-Base64.ps1 Converted to a function, changed [string] $String to [string[]], and wrapped logic in a process loop
src/functions/public/ConvertFrom-Base64.ps1 Converted to a function, changed [string] $Base64String to [string[]], and wrapped logic in a process loop
Comments suppressed due to low confidence (4)

src/functions/public/ConvertTo-Base64.ps1:50

  • [nitpick] The parameter name 'String' is generic and shadows the built-in String type. Consider renaming it to 'InputObject' or 'Strings' for clarity.
[string[]] $String,

src/functions/public/ConvertTo-Base64.ps1:2

  • Help documentation is missing .PARAMETER blocks for the 'String' and 'Encoding' parameters. Adding these will improve automatic help and clarity.
<#

src/functions/public/ConvertFrom-Base64.ps1:51

  • [nitpick] The parameter name 'Base64String' suggests a single value but accepts an array. Rename it to 'Base64Strings' or use 'InputObject' to reflect its array capability.
[string[]] $Base64String,

src/functions/public/ConvertFrom-Base64.ps1:2

  • The function help lacks .PARAMETER entries for 'Base64String' and 'Encoding'. Including these sections will enhance generated help and maintain consistency.
<#

@github-actions
Copy link
Copy Markdown

Module Base64 - 2.0.2 published to the PowerShell Gallery.

@github-actions
Copy link
Copy Markdown

GitHub release for Base64 v2.0.2 has been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🩹 [Patch]: Update functions to take pipeline input

3 participants