Skip to content

Commit 667d8f5

Browse files
authored
- fixes issues activity automations (#3457)
1 parent 6627c32 commit 667d8f5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

scripts/close-no-recent.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
$inactivityDelay = [timespan]::FromDays([int]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_CLOSE_IN_DAYS))
2-
$oldIssues = gh issue list --label "$Env:NO_RECENT_ACTIVITY_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json
2+
$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 }
33
foreach($oldIssue in $oldIssues) {
44
$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
55
if($null -eq $lastComment) {
6-
$lastCommentDate = [datetime]::Parse($oldIssue.createdAt)
7-
6+
$lastCommentDate = [datetime]$null
87
} else {
9-
$lastCommentDate = [datetime]::Parse($lastComment.createdAt)
8+
$lastCommentDate = $lastComment.createdAt #powershell already parses the date for us with the json conversion
109
}
1110
$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
12-
$lastLabelEventDate = [datetime]::Parse($lastLabelEvent.created_at)
13-
if ($lastCommentDate -gt $lastLabelEventDate) {
11+
$lastLabelEventDate = $lastLabelEvent.created_at
12+
if ($null -ne $lastCommentDate -and $lastCommentDate -gt $lastLabelEventDate) {
1413
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"
15-
} elseif (($lastLabelEventDate - $lastCommentDate) -ge $inactivityDelay) {
14+
} elseif (([datetime]::UtcNow - $lastLabelEventDate) -ge $inactivityDelay) {
1615
gh issue close $oldIssue.number -r "not planned"
1716
}
1817
}

scripts/label-no-recent.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
$inactivityDelay = [timespan]::FromDays([int]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_IN_DAYS))
2-
$oldIssues = gh issue list --label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json
2+
$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 }
33
foreach($oldIssue in $oldIssues) {
44
$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
55
if($null -eq $lastComment) {
6-
$lastCommentDate = [datetime]::Parse($oldIssue.createdAt)
7-
6+
$lastCommentDate = [datetime]$null
87
} else {
9-
$lastCommentDate = [datetime]::Parse($lastComment.createdAt)
8+
$lastCommentDate = $lastComment.createdAt #powershell already parses the date for us with the json conversion
109
}
1110
$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
12-
$lastLabelEventDate = [datetime]::Parse($lastLabelEvent.created_at)
13-
if ($lastCommentDate -gt $lastLabelEventDate) {
11+
$lastLabelEventDate = $lastLabelEvent.created_at
12+
if ($null -ne $lastCommentDate -and $lastCommentDate -gt $lastLabelEventDate) {
1413
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"
15-
} elseif (($lastLabelEventDate -$lastCommentDate) -ge $inactivityDelay) {
14+
} elseif (([datetime]::UtcNow - $lastLabelEventDate) -ge $inactivityDelay) {
1615
gh issue edit $oldIssue.number --add-label "$Env:NO_RECENT_ACTIVITY_LABEL" --remove-label "$Env:NEEDS_ATTENTION_LABEL"
1716
gh issue comment $oldIssue.number -b "$Env:NO_RECENT_ACTIVITY_COMMENT"
1817
}

0 commit comments

Comments
 (0)