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

Request scripts part 2 (Status Checks) #851

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
659f135
Removed unneeded paranthesis from functions
AdmiringWorm Jun 25, 2020
181612a
Added helper functions for parsing version data on chocolatey
AdmiringWorm Jun 25, 2020
897da9c
Added helper function for getting maintainers on chocolatey.org
AdmiringWorm Jun 25, 2020
b718d62
Added helper for getting new package information
AdmiringWorm Jun 25, 2020
962a5ce
Added small helpers for reading/writing known users file
AdmiringWorm Jun 25, 2020
3b7974c
Added function to help creating status comments
AdmiringWorm Jun 25, 2020
8769a3b
Added ability to create initial status check information
AdmiringWorm Jun 25, 2020
df49ce1
Added new field to version data class
AdmiringWorm Jun 25, 2020
48486e9
Changed sorting of tracked version in comment
AdmiringWorm Jun 25, 2020
b0fe25f
Fixed invalid values used for updating issues
AdmiringWorm Jun 25, 2020
7279efe
Added ability to run status checks on issues
AdmiringWorm Jun 25, 2020
664fa20
Corrected encodings on scripts
AdmiringWorm Jun 25, 2020
f813cdc
Added vscode chocolatey styling :smile:
AdmiringWorm Jun 25, 2020
003fa84
Added ability to run status check
AdmiringWorm Jun 25, 2020
882be18
Change Issue status initialization to store package name on missing p…
AdmiringWorm Jun 25, 2020
ef8a5f6
Changed away from [array]::Empty
AdmiringWorm Jun 25, 2020
482c10c
Fixed labels not changing
AdmiringWorm Jun 25, 2020
c78dddf
Corrected changing to in progress label when assigning users
AdmiringWorm Jun 25, 2020
974b50f
Removed if statement for status update
AdmiringWorm Jun 25, 2020
4f028c5
Updated Update-IssueStatus.ps1
AdmiringWorm Jun 25, 2020
9ad5e16
Replace spaces with dashes for package names
AdmiringWorm Jun 25, 2020
4e667f9
fixed invalid name of github workflow
AdmiringWorm Jun 25, 2020
9d8bc17
Added missing shell
AdmiringWorm Jun 25, 2020
df46f7e
Corrected function name to call
AdmiringWorm Jun 25, 2020
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
20 changes: 20 additions & 0 deletions .github/workflows/handle-comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ jobs:
} else {
Test-NewIssue -issueNumber ${{ github.event.issue.number }} -repository "${{ github.event.repository.full_name }}"
}
shell: pwsh
statusrecheck:
if: ${{ (needs.comments.outputs.success == 'True' || startsWith(github.event.comment.body, '/status check')) && github.event.issue.state == 'open' }}
runs-on: ubuntu-latest
needs: comments
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/[email protected]
- name: Pull latest commits
run: git pull
- name: Run status check on Issue
run: |
Import-Module "${{ github.workspace }}\scripts\validation.psm1"
if ("${{ github.event.comment.body }}" -match "^/status check") {
Update-IssueStatus -issueNumber ${{ github.event.issue.number }} -repository "${{ github.event.repository.full_name }}" -commentUser "${{ github.event.sender.login }}"
} else {
Update-IssueStatus -issueNumber ${{ github.event.issue.number }} -repository "${{ github.event.repository.full_name }}"
}
shell: pwsh
24 changes: 24 additions & 0 deletions .github/workflows/labels-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Status Checks

on:
issues:
types: [labeled]

jobs:
init:
if: ${{ contains(github.event.issue.labels.*.name, format('{0}:{1}', 'Status', ' Available For Maintainer(s)')) }}
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/[email protected]
- name: Status Updating
run: |
Import-Module "${{ github.workspace }}/scripts/validation.psm1"
$arguments = @{
issueNumber = ${{ github.event.issue.number }}
repository = "${{ github.event.repository.full_name }}"
}
New-IssueStatus @arguments
shell: pwsh
23 changes: 23 additions & 0 deletions .github/workflows/user-assigned.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Status Checks

on:
issues:
types: [assigned, unassigned]

jobs:
update:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/[email protected]
- name: Status Initialization
run: |
Import-Module "${{ github.workspace }}/scripts/validation.psm1"
$arguments = @{
issueNumber = ${{ github.event.issue.number }}
repository = "${{ github.event.repository.full_name }}"
}
Update-IssueStatus @arguments
shell: pwsh
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${file}"
}
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#aacdec",
"activityBar.activeBorder": "#884B2E",
"activityBar.foreground": "#242c5c",
"activityBar.inactiveForeground": "#242c5c",
"activityBarBadge.background": "#884B2E",
"activityBarBadge.foreground": "#e7e7e7",
"titleBar.activeBackground": "#80b5e3",
"titleBar.inactiveBackground": "#80b5e3",
"titleBar.activeForeground": "#242c5c",
"titleBar.inactiveForeground": "#242c5c",
"statusBar.background": "#884B2E",
"statusBarItem.hoverBackground": "#6F3215",
"statusBar.foreground": "#FDCEA5",

}
}
2 changes: 1 addition & 1 deletion scripts/private/Format-Checkboxes.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Format-Checkboxes() {
function Format-Checkboxes {
param (
[Parameter(Mandatory = $true)]
[IssueData]$issueData,
Expand Down
2 changes: 1 addition & 1 deletion scripts/private/Format-Url.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.OUTPUTS
The formatted Url
#>
function Format-Url() {
function Format-Url {
param(
[Parameter(Mandatory = $true)]
[string]$url,
Expand Down
68 changes: 68 additions & 0 deletions scripts/private/Update-StatusComment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function Update-StatusComment {
param(
[Parameter(Mandatory = $true, ParameterSetName = "issue")]
[int]$issueNumber,
[Parameter(Mandatory = $true, ParameterSetName = "comment")]
[int]$commentId,
[Parameter(Mandatory = $true)]
[string]$packageName,
[Parameter(Mandatory = $true)]
[string]$repository,

[PackageData[]]$statusData = $null,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments = $null
)

$comment = "This comment is used to track the current status of this request.`n<!-- START PACKAGE LIST -->"

if ($statusData -and $statusData.Count -gt 0) {
$statusData | ForEach-Object {
if ($_.name -match ' ') {
$_.name = ($_.name -replace ' ', '-').ToLowerInvariant()
}
$lowestStatusVersion = $_.versions | Sort-Object {
if ($_.status -eq 'waiting') {
0
}
elseif ($_.status -eq 'submitted') {
1
}
elseif ($_.status -eq 'approved' -or $_.status -eq 'exempted') {
2
}
else {
3
}
}
$lowestStatusVersion = $_.versions | Select-Object -First 1
if ($lowestStatusVersion) {
$comment = "$comment`n- [$($_.name)]($($lowestStatusVersion.url)) (Status: $($lowestStatusVersion.status), Listed: $($lowestStatusVersion.listed), Is New: $($lowestStatusVersion.isNew), Version: $($lowestStatusVersion.version))"
}
else {
$comment = "$comment`n- **$($_.name)** (Status: Missing)"
}
}
}
else {
$comment = "$comment`n- **$packageName** (Status: Missing)"
}

$comment = "$comment`n<!-- END PACKAGE LIST -->`n<!-- START STATUS DATA`n" `
+ ([Newtonsoft.Json.JsonConvert]::SerializeObject($statusData, [Newtonsoft.Json.Formatting]::Indented)) `
+ "`nEND STATUS DATA -->"

$arguments = @{
repository = $repository
commentBody = $comment
}
if ($commentId) {
$arguments["commentId"] = $commentId
}
else {
$arguments["issueNumber"] = $issueNumber
}

Submit-Comment @arguments
}
2 changes: 1 addition & 1 deletion scripts/private/api/Invoke-Api.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.OUTPUTS
The result of the request.
#>
function Invoke-Api() {
function Invoke-Api {
[OutputType([hashtable])]
param(
[Parameter(Mandatory = $true)]
Expand Down
5 changes: 4 additions & 1 deletion scripts/private/api/comments/Add-Comment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ function Add-Comment {
[Parameter(Mandatory = $true)]
[string]$commentBody,

[string]$githubToken = $env:GITHUB_TOKEN
[string]$githubToken = $env:GITHUB_TOKEN,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments
)

$apiUrls = Get-ApiUrls
Expand Down
7 changes: 5 additions & 2 deletions scripts/private/api/comments/Get-Comment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Only the first match of the comment is returned
when content matching is used.
#>
function Get-Comment() {
function Get-Comment {
[OutputType([CommentData])]
param(
[Parameter(Mandatory = $true, ParameterSetName = "known comment")]
Expand All @@ -32,7 +32,10 @@ function Get-Comment() {
[Parameter(Mandatory = $true)]
[string]$repository,

[string]$githubToken = $env:GITHUB_TOKEN
[string]$githubToken = $env:GITHUB_TOKEN,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments
)

$apiUrls = Get-ApiUrls
Expand Down
2 changes: 1 addition & 1 deletion scripts/private/api/comments/Remove-Comment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.OUTPUTS
$null
#>
function Remove-Comment() {
function Remove-Comment {
[OutputType($null)]
param(
[Parameter(Mandatory = $true)]
Expand Down
5 changes: 4 additions & 1 deletion scripts/private/api/comments/Update-Comment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function Update-Comment {
[Parameter(Mandatory = $true)]
[string]$commentBody,

[string]$githubToken = $env:GITHUB_TOKEN
[string]$githubToken = $env:GITHUB_TOKEN,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments
)

$apiUrls = Get-ApiUrls
Expand Down
7 changes: 5 additions & 2 deletions scripts/private/api/issues/Get-Issue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.OUTPUTS
The found issue data
#>
function Get-Issue() {
function Get-Issue {
[OutputType([IssueData])]
param(
[Parameter(Mandatory = $true, ParameterSetName = "number")]
Expand All @@ -23,7 +23,10 @@ function Get-Issue() {
[Parameter(Mandatory = $true, ParameterSetName = "number")]
[string]$repository,

[string]$githubToken = $env:GITHUB_TOKEN
[string]$githubToken = $env:GITHUB_TOKEN,

[Parameter(ValueFromRemainingArguments = $true)]
[Object[]] $ignoredArguments
)

if ($issueUrl) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/private/api/issues/Update-Issue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.OUTPUTS
Returns the updated issue data
#>
function Update-Issue() {
function Update-Issue {
[OutputType([IssueData])]
param(
[Parameter(Mandatory = $true, ParameterSetName = "number")]
Expand Down Expand Up @@ -65,14 +65,14 @@ function Update-Issue() {
if ($description) {
$content['body'] = $description
}
if ($assignees) {
if ($null -ne $assignees) {
$content['assignees'] = $assignees
}
if ($labels) {
$content['labels'] = $labels
}
if ($state -ne 'None' -and $state -ne $existingIssue.state) {
$content['state'] = $state
$content["state"] = $state.ToString().ToLowerInvariant()
}

$response = Invoke-Api -url $existingIssue.url -parameters @{ number = $issueNumber } -method "PATCH" -content $content -githubToken $githubToken
Expand Down
2 changes: 1 addition & 1 deletion scripts/private/api/permissions/Get-Permission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.OUTPUTS
Returns the available permissions for the user
#>
function Get-Permission() {
function Get-Permission {
[OutputType([PermissionData])]
param(
[Parameter(Mandatory = $true)]
Expand Down
2 changes: 1 addition & 1 deletion scripts/private/api/repository/Get-RepositoryData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.OUTPUTS
The gathered repository data information
#>
function Get-RepositoryData() {
function Get-RepositoryData {
[OutputType([RepositoryData])]
param(
[Parameter(Mandatory = $true, ParameterSetName = "repo+owner")]
Expand Down
49 changes: 49 additions & 0 deletions scripts/private/chocolatey/Get-NewMaintainers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function Get-NewMaintainers {
param (
[Parameter(Mandatory = $true, ParameterSetName = "name")]
[string]$packageName,
[Parameter(Mandatory = $true, ParameterSetName = "page")]
[Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject]$packagePage,
[MaintainerData[]]$existingMaintainers = $null
)

$isUpdate = $PSCmdlet.MyInvocation.InvocationName -eq "Get-UpdatedMaintainers"

$maintainers = [System.Collections.Generic.List[MaintainerData]]::new()

if (!$packagePage) {
try {
$packagePage = Invoke-WebRequest -Uri "https://chocolatey.org/packages/${packageName}" -UseBasicParsing
}
catch {
return $maintainers
}
}

[array]$currentMaintainers = $packagePage.Links | `
? { $_.href -match "\/profiles/[a-z0-9_\.-]+$" } | `
% { $_.href -split "\/" | Select-Object -Last 1 } | `
select -Unique

foreach ($maintainer in $currentMaintainers) {
$foundMaintainer = $existingMaintainers | ? username -eq $maintainer

if (!$foundMaintainer) {
$newMaintainer = [MaintainerData]::new()
$newMaintainer.username = $maintainer
$newMaintainer.url = [uri]::new("https://chocolatey.org/profiles/$maintainer")
$newMaintainer.status = if ($isUpdate) { "added" } else { "initial" }
$maintainers.Add($newMaintainer)
}
else {
if (!$foundMaintainers.status) {
$foundMaintainer.status = "initial"
}
$maintainers.Add($foundMaintainer)
}
}

return $maintainers
}

Set-Alias -Name Get-UpdatedMaintainers -Value Get-NewMaintainers
Loading