Skip to content

Commit

Permalink
v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Jun 4, 2022
1 parent e2aef7e commit 43dc636
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 711 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log for PSReleaseTools

## v1.12.0

+ Exported public functions to individual files.
+ Fixed `A parameter cannot be found that matches parameter name 'source'` bug in `Save-PSReleaseAsset`. Renamed the `DL` private function to `_DownloadAsset`.

## v1.11.0

+ Modified private function `getCode` to get latest release sorting on the published date.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2021 JDH Information Technology Solutions, Inc.
Copyright (c) 2017-2022 JDH Information Technology Solutions, Inc.


Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
Binary file modified PSReleaseTools.psd1
Binary file not shown.
6 changes: 4 additions & 2 deletions PSReleaseTools.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#load functions
. $PSScriptRoot\functions\private.ps1
. $PSScriptRoot\functions\public.ps1
Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 |
ForEach-Object {
. $_.fullname
}

#configure TLS settings for GitHub
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Expand Down
76 changes: 76 additions & 0 deletions functions/Get-PSIssue.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Function Get-PSIssue {
[cmdletbinding()]
[outputtype("GitHubIssue")]
Param(
[Parameter(HelpMessage = "Display issues updated since this time.")]
[datetime]$Since,
[Parameter(HelpMessage = "Specify a comma separated list of labels to filter with. If you select multiple labels, the issue must have all of them.")]
[string[]]$Label,
[Parameter(HelpMessage = "The number of results to return.")]
[ValidateSet(25, 50, 75, 100, 150, 200)]
[int]$Count = 25

)
Begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)"

#number of results per page is 25 so calculate how many pages are needed.
[int]$m = $count / 25
if ($m -ne 1) {
[int]$PageCount = $m + 1
}
else {
[int]$PageCount = 1
}

Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Getting $pageCount page(s)."
$uri = "https://api.github.com/repos/PowerShell/PowerShell/issues?&state=open&sort=updated&direction=desc&per_page=25"

$header = @{ accept = "application/vnd.github.v3+json" }

if ($since) {
$dt = "{0:u}" -f $since
$uri += "&since=$dt"
}

if ($Label) {
$Labelstring = $Label -join ","
$uri += "&labels=$Labelstring"
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Filtering for labels $Labelstring"
}

$irm = @{
uri = $uri
headers = $header
DisableKeepAlive = $True
UseBasicParsing = $True
}

$results = [System.Collections.Generic.List[object]]::new()
#set a flag to indicate we should keep getting pages
$run = $True
} #begin
Process {

1..$pageCount | ForEach-Object {
if ($run) {
$irm.uri = "$uri&page=$_"
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting recent PowerShell issues: $($irm.uri)"
#filter out pull requests
$r = (Invoke-RestMethod @irm).ForEach({ $_ | NewGHIssue })
if ($r.title) {
$results.AddRange($r)
}
else {
Write-Warning "No matching issues found."
$run = $False
}
} #if $run
} #foreach page
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Returned $($results.count) matching issues"
$results
} #process
End {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)"
} #end
}
37 changes: 37 additions & 0 deletions functions/Get-PSIssueLabel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Function Get-PSIssueLabel {
[cmdletbinding()]
Param(
[Parameter(HelpMessage = "Specify a label name. You can use wildcards.")]
[string]$Name
)
Write-Verbose "Starting $($myinvocation.mycommand)"

$Label = [System.Collections.Generic.list[object]]::new()

$header = @{ accept = "application/vnd.github.v3+json" }
$irm = @{
uri = ""
headers = $header
DisableKeepAlive = $true
UseBasicParsing = $True
}
$page = 0
do {
Write-Verbose "Processing Page $page"
$page++
$irm.uri = "https://api.github.com/repos/powershell/powershell/labels?per_page=50&page=$Page"
Write-Verbose $irm.uri
$r = Invoke-RestMethod @irm
$Label.Addrange( $r.ForEach( { $_ | Select-Object -Property Name, Description }))
} until ($r.count -eq 0 -or $page -ge 4)

Write-Verbose "Found $($Label.count) labels"
if ($Name) {
Write-Verbose "Filtering for $Name"
($label).where( { $_.name -like $Name })
}
else {
$Label
}$p
Write-Verbose "Ending $($myinvocation.mycommand)"
}
123 changes: 123 additions & 0 deletions functions/Get-PSReleaseAsset.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
function Get-PSReleaseAsset {

[CmdletBinding()]
[OutputType("PSCustomObject")]
param(
[Parameter(HelpMessage = "Limit results to a given platform. The default is all platforms.")]
[ValidateSet("Rhel", "Raspbian", "Ubuntu", "Debian", "Windows", "AppImage", "Arm", "MacOS", "Alpine", "FXDependent", "CentOS", "Linux")]
[string[]]$Family,
[ValidateSet('deb', 'gz', 'msi', 'pkg', 'rpm', 'zip', 'msix')]
[Parameter(HelpMessage = "Limit results to a given format. The default is all formats.")]
[string[]]$Format,
[Alias("x64")]
[switch]$Only64Bit,
[Parameter(HelpMessage = "Get the latest preview release.")]
[switch]$Preview,
[Parameter(HelpMessage = "Only get LTS release-related assets.")]
[switch]$LTS
)

begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)"
} #begin

process {
try {
if ($Preview) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting preview assets"
$data = GetData -Preview -ErrorAction Stop
}
else {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting normal assets"
$data = GetData -ErrorAction Stop
}
#parse out file names and hashes
#updated pattern 10 March 2020 to capture LTS assets
[regex]$rx = "(?<file>[p|P]ower[s|S]hell((-preview)|(-lts))?[-|_]\d.*)\s+-\s+(?<hash>\w+)"
# pre GA pattern
#"(?<file>[p|P]ower[s|S]hell(-preview)?[-|_]\d.*)\s+-\s+(?<hash>\w+)"
# original regex pattern
#"(?<file>[p|P]ower[s|S]hell[-|_]\d.*)\s+-\s+(?<hash>\w+)"
$r = $rx.Matches($data.body)
$r | ForEach-Object -Begin {
$h = @{ }
} -Process {
#if there is a duplicate entry, assume it is part of a Note
$f = $_.Groups["file"].Value.Trim()
$v = $_.Groups["hash"].Value.Trim()
if (-not ($h.ContainsKey($f))) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $f [$v]"
$h.Add($f, $v )
}
else {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Ignoring duplicate asset: $f [$v]"
}
}

Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Found $($data.assets.count) downloads"

$assets = $data.assets |
Select-Object @{Name = "FileName"; Expression = { $_.Name } },
@{Name = "Family"; Expression = {
switch -regex ($_.name) {
"Win-x\d{2}" { "Windows" ; break }
"arm\d{2}.zip" { "Arm" ; break }
"Ubuntu" { "Ubuntu"; break }
"osx" { "MacOS"; break }
"debian" { "Debian"; break }
"appimage" { "AppImage"; break }
"rhel" { "Rhel"; break }
"linux-arm" { "Raspbian"; break }
"alpine" { "Alpine" ; break }
"fxdepend" { "FXDependent"; break }
"centos" { "CentOS"; break }
"linux-x64" { "Linux" ; break }
}
}
},
@{Name = "Format"; Expression = {
$_.name.Split(".")[-1]
}
},
@{Name = "SizeMB"; Expression = { $_.size / 1MB -as [int32] } },
@{Name = "Hash"; Expression = { $h.Item($_.name) } },
@{Name = "Created"; Expression = { $_.created_at -as [datetime] } },
@{Name = "Updated"; Expression = { $_.updated_at -as [datetime] } },
@{Name = "URL"; Expression = { $_.browser_download_Url } },
@{Name = "DownloadCount"; Expression = { $_.download_count } }

if ($Family) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Filtering by family"
$assets = $assets.where( { $_.family -match $($family -join "|") })
}
if ($Only64Bit) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Filtering for 64bit"
$assets = ($assets).where( { $_.filename -match "(x|amd)64" })
}

if ($Format) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Filtering for format"
$assets = $assets.where( { $_.format -match $("^$format$" -join "|") })
}

If ($LTS) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Filtering for LTS assets"
$assets = $assets.where( { $_.filename -match "LTS" })
}
#write the results to the pipeline
if ($assets.filename) {
$assets
}
else {
Write-Warning "Get-PSReleaseAsset Failed to find any release assets using the specified criteria."
}
} #Try
catch {
throw $_
}
} #process

end {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)"
} #end
}
45 changes: 45 additions & 0 deletions functions/Get-PSReleaseCurrent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function Get-PSReleaseCurrent {
[CmdletBinding()]
[OutputType("PSReleaseStatus")]
param(
[Parameter(HelpMessage = "Get the latest preview release")]
[switch]$Preview
)

begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting: $($MyInvocation.MyCommand)"
} #begin

process {

$data = GetData @PSBoundParameters

#get the local version from the GitCommitID on v6 platforms
#or PSVersion table for everything else
if ($PSVersionTable.ContainsKey("GitCommitID")) {
$local = $PSVersionTable.GitCommitID
}
else {
$Local = $PSVersionTable.PSVersion
}

if ($data.tag_name) {
#create a custom object. This object has a custom format file.
[pscustomobject]@{
PSTypeName = "PSReleaseStatus"
Name = $data.name
Version = $data.tag_name
Released = $($data.published_at -as [datetime])
LocalVersion = $local
URL = $data.html_url
Draft = If ($data.draft -eq 'True') {$True} else {$false}
Prerelease = If ($data.prerelease -eq 'True') { $True } else { $false }
}
}
} #process

end {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending: $($MyInvocation.MyCommand)"
} #end

}
Loading

0 comments on commit 43dc636

Please sign in to comment.