Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pslintrules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# PSUseDeclaredVarsMoreThanAssignments doesn't currently work due to:
# https://github.com/PowerShell/PSScriptAnalyzer/issues/636
'PSUseDeclaredVarsMoreThanAssignments',
# `Write-Log` uses `Write-Host` currently.
# `Write-LogInfo` uses `Write-Host` currently.
'PSAvoidUsingWriteHost'
)
}
6 changes: 3 additions & 3 deletions action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Test-NestedBucket
Initialize-NeededConfiguration

git config --get user.email
Write-Log 'Importing all modules'
Write-LogInfo 'Importing all modules'
# Load all scoop's modules.
# Dot sourcing needs to be done on highest scope possible to propagate into lower scopes
Get-ChildItem (Join-Path $env:SCOOP_HOME 'lib') '*.ps1' | ForEach-Object { . $_.FullName }

Write-Log 'FULL EVENT' $EVENT_RAW
Write-LogInfo 'FULL EVENT' $GITHUB_EVENT_RAW

Invoke-Action

Write-Log 'Number of Github Requests' $env:GH_REQUEST_COUNTER
Write-LogInfo 'Number of Github Requests' $env:GH_REQUEST_COUNTER

if ($env:NON_ZERO_EXIT) { exit $NON_ZERO }
66 changes: 33 additions & 33 deletions src/Action/Issue.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function Test-Hash {
$outputH = @("Exception occurred: $($_.Exception.Message)", "$($_.ScriptStackTrace)")
}

Write-Log 'Output' $outputH
Write-LogInfo 'Output' $outputH

if (($outputH[-2] -like 'OK') -and ($outputH[-1] -like 'Writing*')) {
Write-Log 'Cannot reproduce.'
Write-LogInfo 'Cannot reproduce.'

Add-Comment -ID $IssueID -AppendLogLink -Message @(
'Cannot reproduce.'
Expand All @@ -49,7 +49,7 @@ function Test-Hash {
Remove-Label -ID $IssueID -Label 'hash-fix-needed'
Close-Issue -ID $IssueID
} elseif ($outputH[-1] -notlike 'Writing*') {
Write-Log 'Automatic hash verification encountered some problems.'
Write-LogInfo 'Automatic hash verification encountered some problems.'

Add-Label -ID $IssueID -Label 'help wanted'

Expand All @@ -73,7 +73,7 @@ function Test-Hash {

Add-Comment -ID $IssueID -Message $message -AppendLogLink
} else {
Write-Log 'Hash mismatch confirmed.'
Write-LogInfo 'Hash mismatch confirmed.'

$masterBranch = ((Invoke-GithubRequest "repos/$REPOSITORY").Content | ConvertFrom-Json).default_branch
$message = @('You are right. Thank you for reporting.')
Expand All @@ -85,7 +85,7 @@ function Test-Hash {

# There is alreay PR for
if ($prs.Count -gt 0) {
Write-Log 'PR - Update description'
Write-LogInfo 'PR - Update description'

# Only take latest updated
$pr = $prs | Select-Object -First 1
Expand All @@ -95,45 +95,45 @@ function Test-Hash {
$message += ''
$message += "There is already a pull request which takes care of this issue. (#$prID)"

Write-Log 'PR ID' $prID
Write-LogInfo 'PR ID' $prID
# Update PR description
Invoke-GithubRequest "repos/$REPOSITORY/pulls/$prID" -Method Patch -Body @{ 'body' = (@("- Closes #$IssueID", $pr.body) -join "`r`n") }
Add-Label -ID $IssueID -Label 'duplicate'
} else {
Write-Log 'Git Status:'
Write-LogInfo 'Git Status:'
Invoke-Git -GitArgs @('status', '--porcelain')

Invoke-Git -GitArgs @('add', $gci.FullName)
Invoke-Git -GitArgs @('commit', '-m', "$titleToBePosted (Closes #$IssueID)")

# Try direct push
try {
Write-Log 'Commiting fix directly'
Write-LogInfo 'Commiting fix directly'
Invoke-Git -GitArgs @('push')
} catch {
Write-Log 'Direct push failed. Probably protected branch. Will try to create PR instead.'
Write-LogInfo 'Direct push failed. Probably protected branch. Will try to create PR instead.'

$branch = "$manifestNameAsInBucket-hash-fix-$(Get-Random -Maximum 258258258)"
Write-Log 'Branch' $branch
Write-LogInfo 'Branch' $branch

Invoke-Git -GitArgs @('checkout', '-B', $branch)
# Amend commit with new message
Invoke-Git -GitArgs @('commit', '--amend', '-m', "$titleToBePosted")

# Try create branch and PR
try {
Write-Log 'Creating branch'
Write-LogInfo 'Creating branch'
Invoke-Git -GitArgs @('push', 'origin', $branch)
} catch {
Write-Log 'Create branch failed. Please check workflow permissions.'
Write-LogInfo 'Create branch failed. Please check workflow permissions.'
Add-Comment -ID $IssueID -AppendLogLink -Message @(
'Hash mismatch confirmed, but the bot could not publish the fix currently.'
)
return
}

try {
Write-Log 'Creating PR'
Write-LogInfo 'Creating PR'

# Create new PR
Invoke-GithubRequest -Query "repos/$REPOSITORY/pulls" -Method Post -Body @{
Expand All @@ -143,12 +143,12 @@ function Test-Hash {
'body' = "- Closes #$IssueID"
}
} catch {
Write-Log 'Create PR failed. Please check workflow permissions.'
Write-LogInfo 'Create PR failed. Please check workflow permissions.'
# Try to delete branch if PR creation failed
try {
Invoke-Git -GitArgs @('push', 'origin', '--delete', $branch)
} catch {
Write-Log 'Failed to delete branch. Please check workflow permissions.'
Write-LogInfo 'Failed to delete branch. Please check workflow permissions.'
}
Add-Comment -ID $IssueID -AppendLogLink -Message @(
'Hash mismatch confirmed, but the bot could not publish the fix currently.'
Expand All @@ -174,7 +174,7 @@ function Test-Downloading {
$broken_urls = $outputH -match '>' -replace '.*?>', '-'

if (!$broken_urls) {
Write-Log 'Cannot reproduce'
Write-LogInfo 'Cannot reproduce'

Add-Comment -ID $IssueID -AppendLogLink -Message @(
'Cannot reproduce.'
Expand All @@ -192,7 +192,7 @@ function Test-Downloading {
Remove-Label -ID $IssueID -Label 'manifest-fix-needed'
Close-Issue -ID $IssueID
} else {
Write-Log 'Broken URLs' $broken_urls
Write-LogInfo 'Broken URLs' $broken_urls

Add-Comment -ID $IssueID -AppendLogLink -Message (@(
'You are right. Thank you for reporting.',
Expand All @@ -204,21 +204,21 @@ function Test-Downloading {
}

function Initialize-Issue {
Write-Log 'Issue initialized'
Write-LogInfo 'Issue initialized'

if (-not (($EVENT.action -eq 'opened') -or ($EVENT.action -eq 'labeled'))) {
Write-Log "Only actions 'opened' and 'labeled' are supported"
if (-not (($GITHUB_EVENT.action -eq 'opened') -or ($GITHUB_EVENT.action -eq 'labeled'))) {
Write-LogInfo "Only actions 'opened' and 'labeled' are supported"
return
}

$title = $EVENT.issue.title
$id = $EVENT.issue.number
$label = $EVENT.issue.labels.name
$body = $EVENT.issue.body
$title = $GITHUB_EVENT.issue.title
$id = $GITHUB_EVENT.issue.number
$label = $GITHUB_EVENT.issue.labels.name
$body = $GITHUB_EVENT.issue.body

# Only labeled action with verify label should continue
if (($EVENT.action -eq 'labeled') -and ($label -notcontains 'verify')) {
Write-Log 'Labeled action contains wrong label'
if (($GITHUB_EVENT.action -eq 'labeled') -and ($label -notcontains 'verify')) {
Write-LogInfo 'Labeled action contains wrong label'
return
}

Expand All @@ -227,7 +227,7 @@ function Initialize-Issue {
($null -eq $problematicVersion) -or
($null -eq $problem)
) {
Write-Log 'Not compatible issue title'
Write-LogInfo 'Not compatible issue title'
return
}

Expand Down Expand Up @@ -255,22 +255,22 @@ function Initialize-Issue {

switch -Regex ($problem) {
'hash check' {
Write-Log 'Detected issue type' 'Hash check failed.'
Write-LogInfo 'Detected issue type' 'Hash check failed.'
Test-Hash $problematicName $id
}
'download.*failed' {
Write-Log 'Detected issue type' 'Download failed.'
Write-LogInfo 'Detected issue type' 'Download failed.'
Test-Downloading $problematicName $id
}
'(decompress|extract).*error' {
Write-Log 'Detected issue type' 'Decompression/Extraction error.'
Show-ExtractionHelpTips $problematicName $id $body
Write-LogInfo 'Detected issue type' 'Decompression/Extraction error.'
Show-ExtractionHelpDoc -IssueID $id -IssueBody $body
}
default { Write-Log 'Unsupported issue type' $problem }
default { Write-LogInfo 'Unsupported issue type' $problem }
}

Remove-Label -ID $id -Label 'verify'
Write-Log 'Issue finished'
Write-LogInfo 'Issue finished'
}

Export-ModuleMember -Function Initialize-Issue
30 changes: 15 additions & 15 deletions src/Action/Issue/Extraction.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function Test-ExtractDir {
$urls = @(url $manifest_o $arch)
$extract_dirs = @(extract_dir $manifest_o $arch)

Write-Log $urls
Write-Log $extract_dirs
Write-LogInfo $urls
Write-LogInfo $extract_dirs

for ($i = 0; $i -lt $urls.Count; ++$i) {
$url = $urls[$i]
$dir = $extract_dirs[$i]
Invoke-CachedDownload $Manifest $version $url $null $manifest_o.cookie $true

$cached = cache_path $Manifest $version $url | Resolve-Path | Select-Object -ExpandProperty Path
Write-Log "FILEPATH $url, ${arch}: $cached"
Write-LogInfo "FILEPATH $url, ${arch}: $cached"

$full_output = @(7z l $cached | awk '{ print $3, $6 }' | grep '^D')
$output = @(7z l $cached -ir!"$dir" | awk '{ print $3, $6 }' | grep '^D')
Expand All @@ -38,27 +38,27 @@ function Test-ExtractDir {

# There are no files and folders like
if ($files -eq 0 -and (!$folders -or $folders -eq 0)) {
Write-Log "No $dir in $url"
Write-LogInfo "No $dir in $url"

$failed = $true
$message += New-DetailsCommentString -Summary "Content of $arch $url" -Content $full_output
Write-Log "$dir, $arch, $url FAILED"
Write-LogInfo "$dir, $arch, $url FAILED"
} else {
Write-Log "Cannot reproduce $arch $url"
Write-LogInfo "Cannot reproduce $arch $url"

Write-Log "$arch ${url}:"
Write-Log $full_output
Write-Log "$dir, $arch, $url OK"
Write-LogInfo "$arch ${url}:"
Write-LogInfo $full_output
Write-LogInfo "$dir, $arch, $url OK"
}
}
}

if ($failed) {
Write-Log 'Failed' $failed
Write-LogInfo 'Failed' $failed
$message = 'You are right. Can reproduce', '', $message
Add-Label -ID $IssueID -Label 'verified', 'manifest-fix-needed', 'help wanted'
} else {
Write-Log 'Everything all right' $failed
Write-LogInfo 'Everything all right' $failed
$message = @(
'Cannot reproduce. Are you sure your scoop is updated?'
"Try to run ``scoop update; scoop uninstall $Manifest; scoop install $Manifest``"
Expand All @@ -70,11 +70,11 @@ function Test-ExtractDir {
Add-Comment -ID $IssueID -Message $message -AppendLogLink
}

function Show-ExtractionHelpTips {
function Show-ExtractionHelpDoc {
param (
[Parameter(Mandatory = $true)]
[String] $App,
[Int] $IssueID,
[Parameter(Mandatory = $true)]
[string] $IssueBody
)

Expand Down Expand Up @@ -155,7 +155,7 @@ function Show-ExtractionHelpTips {
'dark' { $tipContent += $tips['dark']; $tipContent += '' }
default {
$tips.Values | ForEach-Object {
$tipContent += $_;
$tipContent += $_
$tipContent += ''
}
}
Expand All @@ -166,4 +166,4 @@ function Show-ExtractionHelpTips {
Add-Comment -ID $IssueID -Message $message
}

Export-ModuleMember -Function Test-ExtractDir, Show-ExtractionHelpTips
Export-ModuleMember -Function Test-ExtractDir, Show-ExtractionHelpDoc
Loading
Loading