Skip to content

Commit

Permalink
- fixes issues activity automations (#3457)
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Nov 30, 2023
1 parent 6627c32 commit 667d8f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions scripts/close-no-recent.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
$inactivityDelay = [timespan]::FromDays([int]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_CLOSE_IN_DAYS))
$oldIssues = gh issue list --label "$Env:NO_RECENT_ACTIVITY_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json
$oldIssues = gh issue list --label "$Env:NO_RECENT_ACTIVITY_LABEL" --state open --limit 100 --json number,author,createdAt,labels | ConvertFrom-Json | Where-Object {$_.labels.name -notcontains $Env:NEEDS_ATTENTION_LABEL }
foreach($oldIssue in $oldIssues) {
$lastComment = gh issue view $oldIssue.number --json comments | ConvertFrom-Json | Select-Object -ExpandProperty comments | Where-Object {$_.author.login -eq $oldIssue.author.login} | Select-Object -Last 1
if($null -eq $lastComment) {
$lastCommentDate = [datetime]::Parse($oldIssue.createdAt)

$lastCommentDate = [datetime]$null
} else {
$lastCommentDate = [datetime]::Parse($lastComment.createdAt)
$lastCommentDate = $lastComment.createdAt #powershell already parses the date for us with the json conversion
}
$lastLabelEvent = gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/repos/$($Env:ORG_NAME)/$($Env:REPO_NAME)/issues/$($oldIssue.number)/events?per_page=100" | ConvertFrom-Json | Where-Object {$_.event -eq "labeled" -and $_.label.name -eq "$Env:NO_RECENT_ACTIVITY_LABEL"} | Select-Object -Last 1
$lastLabelEventDate = [datetime]::Parse($lastLabelEvent.created_at)
if ($lastCommentDate -gt $lastLabelEventDate) {
$lastLabelEventDate = $lastLabelEvent.created_at
if ($null -ne $lastCommentDate -and $lastCommentDate -gt $lastLabelEventDate) {
gh issue edit $oldIssue.number --remove-label "$Env:NO_RECENT_ACTIVITY_LABEL" --remove-label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --add-label "$Env:NEEDS_ATTENTION_LABEL"
} elseif (($lastLabelEventDate - $lastCommentDate) -ge $inactivityDelay) {
} elseif (([datetime]::UtcNow - $lastLabelEventDate) -ge $inactivityDelay) {
gh issue close $oldIssue.number -r "not planned"
}
}
13 changes: 6 additions & 7 deletions scripts/label-no-recent.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
$inactivityDelay = [timespan]::FromDays([int]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_IN_DAYS))
$oldIssues = gh issue list --label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json
$oldIssues = gh issue list --label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --state open --limit 100 --json number,author,createdAt,labels | ConvertFrom-Json | Where-Object {$_.labels.name -notcontains $Env:NO_RECENT_ACTIVITY_LABEL }
foreach($oldIssue in $oldIssues) {
$lastComment = gh issue view $oldIssue.number --json comments | ConvertFrom-Json | Select-Object -ExpandProperty comments | Where-Object {$_.author.login -eq $oldIssue.author.login} | Select-Object -Last 1
if($null -eq $lastComment) {
$lastCommentDate = [datetime]::Parse($oldIssue.createdAt)

$lastCommentDate = [datetime]$null
} else {
$lastCommentDate = [datetime]::Parse($lastComment.createdAt)
$lastCommentDate = $lastComment.createdAt #powershell already parses the date for us with the json conversion
}
$lastLabelEvent = gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/repos/$($Env:ORG_NAME)/$($Env:REPO_NAME)/issues/$($oldIssue.number)/events?per_page=100" | ConvertFrom-Json | Where-Object {$_.event -eq "labeled" -and $_.label.name -eq "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL"} | Select-Object -Last 1
$lastLabelEventDate = [datetime]::Parse($lastLabelEvent.created_at)
if ($lastCommentDate -gt $lastLabelEventDate) {
$lastLabelEventDate = $lastLabelEvent.created_at
if ($null -ne $lastCommentDate -and $lastCommentDate -gt $lastLabelEventDate) {
gh issue edit $oldIssue.number --remove-label "$Env:NO_RECENT_ACTIVITY_LABEL" --remove-label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --add-label "$Env:NEEDS_ATTENTION_LABEL"
} elseif (($lastLabelEventDate -$lastCommentDate) -ge $inactivityDelay) {
} elseif (([datetime]::UtcNow - $lastLabelEventDate) -ge $inactivityDelay) {
gh issue edit $oldIssue.number --add-label "$Env:NO_RECENT_ACTIVITY_LABEL" --remove-label "$Env:NEEDS_ATTENTION_LABEL"
gh issue comment $oldIssue.number -b "$Env:NO_RECENT_ACTIVITY_COMMENT"
}
Expand Down

0 comments on commit 667d8f5

Please sign in to comment.