Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
* release/0.3.0:
  (build) Updated to only collect files in build directory
  (build) Added codecov config
  (docs) Fixed incorrect github release link
  (docs) Fixed copy-paste error
  (GH-15) Allow users to disable escaping of redirected url
  (GH-18) Added ability to add alias whitelist
  (choco) Fixed incorrect urls used in nuspec file
  (docs) Updated release notes
  • Loading branch information
AdmiringWorm committed Jun 2, 2018
2 parents f4ff65d + cd20cd5 commit 0b07266
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ test_script:
Import-Module $env:USERPROFILE\CodeCovIo.psm1
.\test -CodeCoverage
artifacts:
- path: '**\*.nupkg'
- path: '**\*.7z'
- path: '.build\**\*.nupkg'
- path: '.build\**\*.7z'
notifications:
- provider: GitHubPullRequest
on_build_success: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ To install it, use one of the following methods:
- [![PowerShell Gallery](https://img.shields.io/powershellgallery/v/Wormies-AU-Helpers.svg?style=plastic)](https://www.powershellgallery.com/packages/Wormies-AU-Helpers): [`Install-Module wormies-au-helpers`]
- [![Chocolatey](https://img.shields.io/chocolatey/v/wormies-au-helpers.svg?style=plastic)](https://chocolatey.org/packages/wormies-au-helpers): [`choco install wormies-au-helpers`]
- [![MyGet](https://img.shields.io/myget/wormie-nugets/vpre/wormies-au-helpers.svg?style=plastic&label=MyGet)](https://www.myget.org/feed/wormie-nugets/package/nuget/wormies-au-helpers): [`choco install wormies-au-helpers --source https://www.myget.org/F/wormie-nugets --pre`]
- Download the 7z archive from the latest [![GitHub Release](https://img.shields.io/github/release/qubyte/rubidium.svg?style=plastic&label=GitHub%20Release)](https://com/WormieCorp/Wormies-AU-Helpers/releases/latest), or latest appveyor build [artifact](https://ci.appveyor.com/project/admiringworm/wormies-au-helpers/build/artifacts)
- Download the 7z archive from the latest [![GitHub Release](https://img.shields.io/github/release/WormieCorp/Wormies-AU-Helpers.svg?style=plastic&label=GitHub%20Release)](https://github.com/WormieCorp/Wormies-AU-Helpers/releases/latest), or latest appveyor build [artifact](https://ci.appveyor.com/project/admiringworm/wormies-au-helpers/build/artifacts)
5 changes: 3 additions & 2 deletions Wormies-AU-Helpers/private/Expand-AliasesInText.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
[string]$text,
[Parameter(Mandatory = $true)]
[hashtable]$aliases,
$ParserErrors = $null)
$ParserErrors = $null,
[string[]]$whitelist = @())

$tokens = [System.Management.Automation.PSParser]::Tokenize($text, [ref]$ParserErrors)
$commands = $tokens | Where-Object Type -eq "Command" | Sort-Object Start -Descending

foreach ($cmd in $commands) {
$key = $cmd.Content
if ($aliases.Contains($key)) {
if ($aliases.Contains($key) -and !$whitelist.Contains($key)) {
$alias = $aliases.$key
$old = $cmd.Content
$new = $alias.ResolvedCommandName
Expand Down
13 changes: 10 additions & 3 deletions Wormies-AU-Helpers/public/Expand-Aliases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
.PARAMETER Files
The files to expand aliases in.
.PARAMETER AliasWhitelist
Allows to add a array of whitelisted aliases that shouldn't be expanded.
(defaults to @('Get-UninstallRegistryKey'))
.EXAMPLE
Expand-Aliases -Text "rm file.txt; gi file.exe"
Expand Down Expand Up @@ -47,7 +51,10 @@ function Expand-Aliases () {
[Parameter(Mandatory = $false, ParameterSetName = 'directory')]
[string]$Filter = "*.ps1",
[Parameter(Mandatory = $true, ParameterSetName = 'files')]
[string[]]$Files
[string[]]$Files,
[Parameter(Mandatory = $false)]
[Alias('Whitelist')]
[string[]]$AliasWhitelist = @('Get-PackageParameters'; 'Get-UninstallRegistryKey') # We add some default due to later chocolatey version setting it as an alias
)

BEGIN {
Expand All @@ -70,14 +77,14 @@ function Expand-Aliases () {

foreach ($file in $allFiles) {
$oldText = Get-Content -Path $file.FullName -Raw
$text = Expand-AliasesInText -text $oldText -aliases $aliases -ParserErrors $ParserErrors
$text = Expand-AliasesInText -text $oldText -aliases $aliases -ParserErrors $ParserErrors -whitelist $AliasWhitelist
if ($oldText -cne $text) {
[System.IO.File]::WriteAllText($file.FullName, $text, [System.Text.Encoding]::UTF8)
}
}
}
else {
$text = Expand-AliasesInText -text $text -aliases $aliases -ParserErrors $ParserErrors
$text = Expand-AliasesInText -text $text -aliases $aliases -ParserErrors $ParserErrors -whitelist $AliasWhitelist
}
}

Expand Down
6 changes: 4 additions & 2 deletions Wormies-AU-Helpers/public/Get-RedirectedUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ function Get-RedirectedUrl {
param(
[Parameter(Mandatory = $true)]
[uri]$url,
[uri]$referer
[uri]$referer,
[Alias('DisableEscape','RawUrl')]
[switch]$NoEscape
)

$req = [System.Net.WebRequest]::CreateDefault($url)
Expand All @@ -36,7 +38,7 @@ function Get-RedirectedUrl {

if ($resp -and $resp.ResponseUri.OriginalString -ne $url) {
Write-Verbose "Found redirected url '$($resp.ResponseUri)"
if ( $($resp.ResponseUri.OriginalString) -match '\%\d+' ) {
if ($NoEscape -or $($resp.ResponseUri.OriginalString) -match '\%\d+' ) {
$result = $resp.ResponseUri.OriginalString
}
else {
Expand Down
2 changes: 0 additions & 2 deletions chocolatey/Build-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ $description = $au.package.metadata.summary + ".`n`n" + $features
$au.package.metadata.version = $version
$au.package.metadata.description = $description
$au.package.metadata.licenseUrl = "${repo}/blob/develop/LICENSE"
$au.package.metadata.projectUrl = $repo
$au.package.metadata.projectSourceUrl = $repo
$au.package.metadata.bugTrackerUrl = "${repo}/issues"
$au.package.metadata.docsUrl = "${repo}/wiki"
$au.package.metadata.packageSourceUrl = "${repo}/tree/develop/chocolatey"

if (Test-Path "$PSScriptRoot/CHANGELOG.md") {
Expand Down
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
notify:
gitter:
default:
url: secret:2OfQF7Mj7kKPY5mD3LKeyV9Ap4OB8Cvz1dTFwgzygQLzxtbuUHuWHOC6fKhzaa0RwEcjAKkClyF2GVasF6+Vj6p0jULn7au1GqbQpcmqBpZ8QVMWu97rHSeR9N0iDkyi
threshold: 1%
18 changes: 18 additions & 0 deletions docs/input/blog/new-release-0.2.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
Title: Bug Release 0.2.2
Published: 2018-05-05
Category: Release
Author: AdmiringWorm
---

# 0.2.2 Bug Release

As part of this release we had [15 commits](https://github.com/WormieCorp/Wormies-AU-Helpers/compare/0.2.1...0.2.2) which resulted in [1 issue](https://github.com/WormieCorp/Wormies-AU-Helpers/issues?milestone=7&state=closed) being closed.


__Bug__

- [__#17__](https://github.com/WormieCorp/Wormies-AU-Helpers/issues/17) Some uri escape to %2520 instead of %20

### Where to get it
You can download this release from [chocolatey](https://chocolatey.org/packages/wormies-au-helpers/0.2.2), or from the [PowerShell Gallery](https://www.powershellgallery.com/packages/Wormies-AU-Helpers/0.2.2)
2 changes: 1 addition & 1 deletion scripts/Create-GithubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $repoUser = $splits | Select-Object -Last 1 -Skip 2
$repoName = $splits | Select-Object -Last 1 -Skip 1
$args += " -o '$repoUser' -r '$repoName'"

$assets = Get-ChildItem $PSScriptRoot/.. -Include "*.7z", "*.nupkg" -Recurse | ForEach-Object FullName
$assets = Get-ChildItem $PSScriptRoot/../.build -Include "*.7z", "*.nupkg" -Recurse | ForEach-Object FullName

"Uploading the followings assets to $repoName for version $version"
$assets | ForEach-Object { " - " + (Split-Path -Leaf $_) }
Expand Down
17 changes: 17 additions & 0 deletions tests/public/Expand-Aliases.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,21 @@ Describe "Expand-Aliases" {

Get-Module chocolateyInstaller -All | Should -Not -Be $null
}

It "Should not expand aliases specified in whitelist array" {
$testText = 'gc "something"'
$expectedText = 'gc "something"'

Expand-Aliases -Text $testText -AliasWhitelist @('gc') | Should Be $expectedText

$testText = 'Get-UninstallRegistryKey "somekey"'
$expectedText = 'Get-UninstallRegistryKey "somekey"'

Expand-Aliases -Text $testText | Should Be $expectedText

$testText = $testText + '; gc "testing"'
$expectedText = $expectedText + '; Get-Content "testing"'

Expand-Aliases -Text $testText | Should Be $expectedText
}
}
4 changes: 4 additions & 0 deletions tests/public/Get-RedirectedUrl.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ Describe "Get-RedirectedUrl" {
Get-RedirectedUrl "https://electron.authy.com/download?channel=stable&arch=x64&platform=win32&version=latest&product=authy" | Should -Not -Match "\%2520"
Get-RedirectedUrl "https://www.dropbox.com/download?build=48.4.58&plat=win&type=full" | Should -Not -Match "\%2520"
}

It "Should not escape urls when user passes the 'NoEscape' switch" {
Get-RedirectedUrl "https://electron.authy.com/download?channel=stable&arch=x64&platform=win32&version=latest&product=authy" -NoEscape | Should -Not -Match '\%20'
}
}

0 comments on commit 0b07266

Please sign in to comment.