Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch-PRTitles #96846

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
31a8b6e
First commit of PRWatcher
stephengillie Feb 15, 2023
c300b32
Add auth file, clean up file paths.
stephengillie Feb 15, 2023
4f4e204
Fix name in comments and revert Auth name.
stephengillie Feb 15, 2023
6870693
Check for version number as last item in title.
stephengillie Feb 16, 2023
a55f5d6
Remove unnecessary variable, move others to parameter, rename PRFile …
stephengillie Feb 16, 2023
7629515
Add documentation.
stephengillie Feb 16, 2023
b5654e2
Update documentation and code formatting and clearspace.
stephengillie Feb 20, 2023
cb4e9cb
Rename Search-Winget to Search-WingetManifest, for clarity.
stephengillie Feb 20, 2023
f2ad081
Bugfix for non-semantic versions. And removing unnecessary carryClip …
stephengillie Feb 20, 2023
d9dfc10
Rearrange code sections and add bugfix for "Automatic deletion" autoc…
stephengillie Feb 20, 2023
2700692
Add Chromatic option for different color schemes.
stephengillie Feb 20, 2023
9282f37
Clean up Write-Debug sections. (Just in case)
stephengillie Feb 20, 2023
5bdc1ef
Comment debugs. Also swap grey and cyan to retain cyan as a validColor.
stephengillie Feb 22, 2023
1fa5073
Update WinGet capitalization, and add some notes.
stephengillie Feb 27, 2023
47fed77
Add null check on prVerLoc to obviate a try/catch.
stephengillie Feb 27, 2023
2f64bff
Bugfix for null prVerLoc.
stephengillie Feb 27, 2023
9afac43
Bugfix for missing auth file.
stephengillie Feb 27, 2023
d5f9c4d
Apply suggestions from VSCode Powershell extension.
stephengillie Feb 27, 2023
5875184
Auth file updates. (Auth file is non-authoritative and only a suggest…
stephengillie Feb 28, 2023
848a303
Add automatic sandboxing function, to streamline review of new applic…
stephengillie Mar 7, 2023
bc6851a
Support for 6-digit PR numbers.
stephengillie Mar 20, 2023
654cff4
Add filtering to first Get-Clipboard call, and obviate a second by pa…
stephengillie Mar 20, 2023
4c3a66d
Add automatic hash removal for Create-Sandbox.
stephengillie Mar 20, 2023
ad377b3
Comparison bugfix.
stephengillie Mar 20, 2023
454f62d
Bugfix for filtered clip variable.
stephengillie Mar 20, 2023
03d8bc2
Merge branch 'microsoft:master' into WatchPackages
stephengillie Mar 23, 2023
30745cc
Merge branch 'microsoft:master' into WatchPackages
stephengillie Mar 24, 2023
6fefd64
Auth file updates. (Auth file is non-authoritative and should be used…
stephengillie Mar 24, 2023
1200fe2
#0.7.1 Caps keyword Function.
stephengillie Mar 24, 2023
82297b7
#0.7.2 Rename variable WinGetVersion to ManifestVersion.
stephengillie Mar 24, 2023
de3feec
#0.7.3 Remove commented debug lines.
stephengillie Mar 24, 2023
1e65355
#0.7.4 Bugfix for Auth match section.
stephengillie Mar 24, 2023
dd7d712
Auth file updates. (Auth file is non authoritative and should only be…
stephengillie Mar 27, 2023
60c35d3
Add blocker to Auth file for Accessibility Insights. Related: https:/…
stephengillie Mar 28, 2023
6010593
Upgrade SSMS from "should" to "must" per https://github.com/microsoft…
stephengillie Mar 28, 2023
138e60b
Auth file update. (Auth file is not authoritative and should be only …
stephengillie Apr 19, 2023
6eff34a
Change copy monitoring to select lines with a PR#, enabling full-page…
stephengillie Apr 19, 2023
6c326fd
Update underscore filtering to be underscore-version filtering.
stephengillie Apr 19, 2023
0e1ddb0
Move DotNet from 'should' to 'must' in Auth.csv (Auth file is non aut…
stephengillie Apr 28, 2023
384acce
Use Manual Validation pipeline instead of sandbox validation for new …
stephengillie Apr 28, 2023
867e374
Increase default Sandbox version.
stephengillie Apr 28, 2023
9b8a2a7
Swap valid and invalid colors (instead of using hardcode colors) when…
stephengillie May 5, 2023
84eeba5
Capitalize command name.
stephengillie May 5, 2023
ad89500
Add Cycle-VMs check for quicker closure of new package investigation …
stephengillie May 5, 2023
567bf25
Add more robust PackageIdentifier and PackageVersion detection.
stephengillie May 17, 2023
1b6cc6d
Add national color schemes.
stephengillie May 17, 2023
41e581f
Update "Gold" to PowerShell-friendly similar color "DarkYellow".
stephengillie May 18, 2023
cf1e3d6
Additional color name updates.
stephengillie May 18, 2023
aded202
Bugfix for improved version detection.
stephengillie May 19, 2023
1a529d7
Additional bugfix.
stephengillie May 19, 2023
0911f10
Retheme nation colors to better group colors with codepaths, and upda…
stephengillie May 22, 2023
d122b94
Convert RainbowRotate into Random (bug: 1st PR is Default colorset.)
stephengillie May 26, 2023
a0408f2
Improve PackageVersion finder robustness.
stephengillie May 26, 2023
f414f18
Move Cycle-VMs call into Run-StatusTracker, add ValidationComplete ch…
stephengillie May 26, 2023
ddfc069
Replacing errant DarkGrey with Powershell-friendly DarkGray.
stephengillie May 26, 2023
b045a30
Merge branch 'microsoft:master' into WatchPackages
stephengillie Jun 9, 2023
10cd8bc
Upgrade WinGet version in Create-Sandbox.
stephengillie Jun 28, 2023
75beae1
Make new version system of semantic type.
stephengillie Jun 28, 2023
cbfd8b9
Merge branch 'microsoft:master' into WatchPackages
stephengillie Jun 29, 2023
04bdf4a
Merge branch 'microsoft:master' into WatchPackages
stephengillie Jul 26, 2023
e9344a2
Merge branch 'master' into WatchPackages
stephengillie Aug 15, 2023
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
26 changes: 26 additions & 0 deletions Tools/Auth.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PackageIdentifier,Account,strictness
Dapr.CLI,dapr-bot,should
DoltHub.Dolt,coffeegoddd,should
File-New-Project.EarTrumpet,riverar,must
Ferdium.Ferdium,Alpharag,should
junegunn.fzf,junegunn,should
Keboola.KeboolaCLI,KeboolaAsCodeBot,should
Lenovo.SystemUpdate,philjorgensen,should
Microsoft.Azd,azure-sdk,should
Microsoft.AzureCLI,Microsoft,should
Microsoft.DotNet,dotnet-winget-bot,should
Microsoft.Git,Microsoft,should
Microsoft.PowerToys,Microsoft,must
Microsoft.PowerShell,Microsoft,must
Microsoft.WindowsTerminal,Microsoft,must
Microsoft.VisualStudio,Microsoft,must
Microsoft.VisualStudioCode,Microsoft,must
Neovim.Neovim.Nightly,nvim-winget,should
OleksisFraga.PythonLauncher,oleksis,should
Pulumi.Pulum,pulumi-bot,should
stnkl.EverythingToolbar,stnkl,should
the-sz.Bear,the-sz,should
thebookisclosed.ViVeTool,thebookisclosed,must
TopalaSoftwareSolutions.SIW,gtopala,should
WerWolv.ImHex,WerWolv,should
Visual Studio,Microsoft,must
193 changes: 193 additions & 0 deletions Tools/PRWatcher.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#Streamlines Winget-pkgs manifest PR moderator approval by watching the clipboard - copy a PR title to your clipboard, and Watch-PRTitles attempts to parse the PackageIdentifier and version number, gathers the version from Winget, and gives feedback in your Powershell console. Also outputs valid titles to a logging file. Freeing moderators to focus on approving and helping.


function Watch-PRTitles {
[CmdletBinding()]
param(
[switch]$noNew,
$LogFile = ".\PR.txt",
$authFile = ".\Auth.csv",
$oldclip = ""
)
while($true){
$timevar = (get-date -Format T) + ":"
$clip = Get-Clipboard;
$AuthList = gc $authFile | ConvertFrom-Csv
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
$carryClip = ""
$copyClip = $false

if (diff $clip $oldclip) {
$noRecord = $false
$title = $clip -split ": "

if ($title[1]) {
$title = $title[1] -split " "
}else {
$title = $title -split " "
}
#Split the title by spaces. Try extracting the version location as the next item after the word "version", and if that fails, use the 2nd to the last item, then 3rd to last, and 4th to last. For some reason almost everyone puts the version number as the last item, and GitHub appends the PR number.
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
try {
#Version is on the line before the line number, and this set indexes with 1 - but the following array indexes with 0, so the value is automatically transformed by the index mismatch.
$prVerLoc =($title | Select-String "version").linenumber
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
[System.Version]$prVersion = $title[$prVerLoc]
#Write-Debug 0 $title[$prVerLoc]
}catch {
try {
[System.Version]$prVersion = $title[-1]
}catch {
try {
[System.Version]$prVersion = $title[-2]
#Write-Debug 1 $title[-2]
}catch {
try {
[System.Version]$prVersion = $title[-3]
#Write-Debug 2 $title[-3]
}catch {
try {
[System.Version]$prVersion = $title[-4]
#Write-Debug 3 $title[-4]
}catch {
$prVersion = $title[-2]
#Write-Debug 4
}
}
}
}
}
#Store version number
if ($prVersion -eq "") {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
$prVersion = $carryClip
}

$validColor = "green"
$invalidColor = "red"
$cautionColor = "yellow"

#Get the PackageIdentifier out of the PR title, and alert if it matches the auth list.
$cleanOut = (Get-CleanClip);
$AuthMatch = $AuthList.PackageIdentifier -match ($cleanOut.split("[.]")[0]+"."+$cleanOut.split("[.]")[1])
if ($AuthMatch) {
$AuthListLine = $AuthList | where {$_.PackageIdentifier -match $AuthMatch}
$strictness = $AuthListLine.strictness | sort -Unique
$AuthAccount = $AuthListLine.account | sort -Unique
$strictColor = ""
if ($strictness -eq "must") {
$strictColor = $invalidColor
} else {
$strictColor = $cautionColor
}
Write-Host -nonewline " = = = = = = Submitter "
Write-Host -nonewline -f $strictColor "$strictness"
Write-Host -nonewline " match "
Write-Host -nonewline -f $strictColor "$AuthAccount"
Write-Host " = = = = = = "
}

$wingetOutput = Search-Winget $cleanOut

try {
$wgLine = ($wingetOutput | Select-String " $cleanOut ")
[System.Version]$wingetVersion = ($wgLine -replace "\s+"," " -split " ")[-2]
}catch {
$wingetVersion = ""
}

$titlejoin = ($title -join " ")
if (($titlejoin -match "Automatic deletion") -OR ($titlejoin -match "Remove")) {
$validColor = "red"
$invalidColor = "green"
$copyClip = $true
}

if ($cleanOut -eq "Added") {
Write-Host -f $invalidColor "$timevar Error reading package identifier"
$noRecord = $true
}elseif ($wingetOutput -eq "No package found matching input criteria.") {
if ($noNew -eq $true) {
$noRecord = $true
}
Write-Host -f $invalidColor $timevar ($cleanOut) $wingetOutput
}elseif ($prVersion -eq "") {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
$noRecord = $true
Write-Host -f $invalidColor "$timevar Error reading PR version"
}elseif ($wingetVersion -eq "Unknown") {
Write-Host -f $invalidColor "$timevar Error reading Winget version"
}elseif ($wingetVersion -eq "input") {
$noRecord = $true
Write-Host $wingetOutput
}elseif ($wingetVersion -eq $null) {
Write-Host $wingetOutput
}elseif ($wingetVersion -eq "add-watermark") {
$noRecord = $true
Write-Host -f $invalidColor "$timevar Error reading package identifier"
}elseif ($prVersion -gt $wingetVersion) {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
Write-Host -f $validColor "$timevar $cleanOut prVersion $prVersion is greater than wingetVersion $wingetVersion"
}elseif ($prVersion -lt $wingetVersion) {
$outMsg = "$timevar $cleanOut prVersion $prVersion is less than wingetVersion $wingetVersion"
Write-Host -f $invalidColor $outMsg
if ($copyClip) {
$outMsg | clip
}
}elseif ($prVersion -eq $wingetVersion) {
Write-Host -f $cautionColor "$timevar $cleanOut prVersion $prVersion is equal to wingetVersion $wingetVersion"
}else {
$wingetOutput
};
$oldclip = $clip
$carryClip = $prVersion
if ($noRecord -eq $false) {
if ($clip.length -le 128) {
$clip = $clip -join "" | where {$_ -match "[#][0-9]{5}"}
#Write-Host "Output $clip to $LogFile"
$clip | Out-File $LogFile -Append
} else {
Write-Host -f $cautionColor "$timevar Item length greater than 128 characters."
}
}
};
sleep 1
}
}

<#Bug: Non-semantic version numbers get garbled.
Example: https://github.com/microsoft/winget-pkgs/search?o=desc&q=chrisant996.Clink&s=committer-date&type=commits

$carryClip sections are an unfinished attempt to address this bug.
#>


#Utility functions
#Extract package name from clipboard contents
function Get-CleanClip {
[CmdletBinding()]
param(
$out = (Get-Clipboard)
)
$out = $out -replace "_"," "
$out = $out -join "" #removes accidental line breaks
#$DebugPreference = 'Continue'
$i = 0
Write-Debug "$i time: $out";$i++
$out = $out -replace "Add "
$out = $out -replace "Automatic deletion of "
$out = $out -replace "Automatic update of "
$out = $out -replace "Remove "
$out = $out -replace "Update "
Write-Debug "$i time: $out";$i++
if ($out.contains(": ")) {
$out = ($out -split ": ")[1]
}
Write-Debug "$i time: $out";$i++

$out = ($out -split " ")[0]
Write-Debug "$i time: $out";$i++
$out
}

#Minimize output for automation
function Search-Winget ($term) {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
$out = winget search $term --disable-interactivity
return $out
}


35 changes: 35 additions & 0 deletions doc/tools/PRWatcher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Using PRWatcher.ps1
PRWatcher includes Watch-PRTitles, to give information about pull requests (PRs) from watching their titles in your clipboard. Also includes utility programs Get-CleanClip and Search-Winget. To use, load the file contents into your PowerShell application through your desired means. (Copy/paste, Import-Module, include in Profile, et cetera.) Then run "Watch-PRTitles" and the script will monitor your clipboard, attempting to parse PackageIdentifiers and version numbers, and comparing these to Winget's public manifest.

# Utility Functions
Additionally included are utility functions:
- Get-CleanClip to extract the PackageIdentifier.
- Search-Winget, to streamline non-interactive Winget search.

These are library functions also used in other Manual Validation functions, as part of the philosophy of building a declarative layer to handle operations and build objects, and an imperative layer on top to orchestrate operations. These utility functions are in the declarative layer, while Watch-PRTitles is in the imperative layer.

## Winget repository on GitHub
This script is designed for use with the [Winget package repository](https://github.com/microsoft/winget-pkgs) on GitHub, specifically for PR approvers and working with package PRs in general.

## Features
- Logging of valid PR titles, filtering on PR # at the end.
- Default semantic versioning for more accurate versions. Failback to string-based versioning is planned to be working again soon.
- "Automatic removal" clipboard insertion of output, to paste as PR comment confirming that the newer version is already available through Winget.

# Command Line Arguments
PRWatcher provides additional arguments for more specific functionality.

`Watch-PRTitles [-noNew] [-authFile C:\path\to\Auth.csv] [-LogFile C:\path\to\Log.txt]`

## -noNew
This setting prevents logging the PR title if the package isn't already in the Winget public manifest. This allows for streamlining acceptance of existing package upgrades, so an approver can skip new packages for more thorough examination later.

## -authFile
Location of Auth.csv - defaults to current path location. This might become a built-in web location in future versions.

## -LogFIle
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
Location of logging file - defaults to "Log.txt" in current path location.