Skip to content

Commit

Permalink
Invoke-UpdateCheck fixes (#252)
Browse files Browse the repository at this point in the history
* Fixes a regression [introduced by #242 unfortunately](17f6122#diff-34a614678760cc83c5a91ad95ae240e5R86) when I was reducing the lines in the module that exceeded 100 chars.

Specifically (note the `=Message` instead of the `-Message`):
https://github.com/microsoft/PowerShellForGitHub/blob/17f6122d7812ee4001ce4bdf630429e711e45f7b/UpdateCheck.ps1#L86

* Updates the web request to suppress the progress bar using `$ProgressPreference = 'SilentlyContinue'`

* Adds a `-Force` switch to force the update check to happen again to make future debugging scenarios easier.

Fixes #249
Fixes #250
  • Loading branch information
HowardWolosky authored Jun 28, 2020
1 parent eedfaa3 commit d32bd11
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions UpdateCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ function Invoke-UpdateCheck
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
.PARAMETER Force
For debugging purposes, using this switch will allow the check to occur more than the limit
of once per day. This _will not_ bypass the DisableUpdateCheck configuration value however.
.EXAMPLE
Invoke-UpdateCheck
.NOTES
Internal-only helper method.
#>
param()
[cmdletbinding()]
param([switch] $Force)

if (Get-GitHubConfiguration -Name DisableUpdateCheck)
{
Expand All @@ -44,6 +49,18 @@ function Invoke-UpdateCheck

$jobNameToday = "Invoke-UpdateCheck-" + (Get-Date -format 'yyyyMMdd')

if ($Force)
{
if ($null -ne $script:UpdateCheckJobName)
{
# We're going to clear out the existing job and try running it again.
$null = Receive-Job -Name $script:UpdateCheckJobName -AutoRemoveJob -Wait -ErrorAction SilentlyContinue -ErrorVariable errorInfo
}

$script:UpdateCheckJobName = $null
$script:HasLatestVersion = $null
}

# We only check once per day
if ($jobNameToday -eq $script:UpdateCheckJobName)
{
Expand Down Expand Up @@ -83,7 +100,7 @@ function Invoke-UpdateCheck
if ($script:HasLatestVersion)
{
$message = "[$moduleName] update check complete. Running latest version: $latestVersion"
Write-Log =Message $message -Level Verbose
Write-Log -Message $message -Level Verbose
}
elseif ($moduleVersion -gt $latestVersion)
{
Expand Down Expand Up @@ -132,6 +149,9 @@ function Invoke-UpdateCheck

try
{
# Disable Progress Bar in function scope during Invoke-WebRequest
$ProgressPreference = 'SilentlyContinue'

Invoke-WebRequest @params
}
catch
Expand Down

0 comments on commit d32bd11

Please sign in to comment.