From cb6e9bdaaac1cb69f89b01003c26569a10720c6b Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 6 Nov 2023 15:37:10 -0500 Subject: [PATCH 1/3] - adds a workflow to handle stale issues Signed-off-by: Vincent Biret --- .github/workflows/inactive-issues.yml | 34 +++++++++++++++++++++++++++ scripts/close-no-recent.ps1 | 18 ++++++++++++++ scripts/label-no-recent.ps1 | 19 +++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .github/workflows/inactive-issues.yml create mode 100644 scripts/close-no-recent.ps1 create mode 100644 scripts/label-no-recent.ps1 diff --git a/.github/workflows/inactive-issues.yml b/.github/workflows/inactive-issues.yml new file mode 100644 index 0000000000..1afed4337b --- /dev/null +++ b/.github/workflows/inactive-issues.yml @@ -0,0 +1,34 @@ +on: + issues: + types: labeled + workflow_dispatch: + schedule: + - cron: '*/5 * * * *' + +permissions: + issues: write + +name: Label and close issues with no recent activity + +env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NEEDS_ATTENTION_LABEL: "Needs attention" + NEEDS_AUTHOR_FEEDBACK_LABEL: "Needs author feedback" + NO_RECENT_ACTIVITY_LABEL: "No recent activity" + NO_RECENT_ACTIVITY_DURATION: "00:00:01" + NO_RECENT_ACTIVITY_DURATION_CLOSE: "00:00:01" + ORG_NAME: ${{ github.repository_owner }} + REPO_NAME: ${{ github.event.repository.name }} + NO_RECENT_ACTIVITY_COMMENT: "This issue has been labeled because there has been no recent activity. It will be closed if no further activity occurs within 1 day." + + +jobs: + run: + runs-on: ubuntu-latest + name: Label issues with no recent activity + steps: + - uses: actions/checkout@v4 + - run: scripts/label-no-recent.ps1 + shell: pwsh + - run: scripts/close-no-recent.ps1 + shell: pwsh diff --git a/scripts/close-no-recent.ps1 b/scripts/close-no-recent.ps1 new file mode 100644 index 0000000000..77ec4a7327 --- /dev/null +++ b/scripts/close-no-recent.ps1 @@ -0,0 +1,18 @@ +$inactivityDelay = [timespan]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_CLOSE) +$oldIssues = gh issue list --label "$Env:NO_RECENT_ACTIVITY_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json +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) + + } else { + $lastCommentDate = [datetime]::Parse($lastComment.createdAt) + } + $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) { + 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 (($lastCommentDate - $lastLabelEventDate) -le $inactivityDelay) { + gh issue close $oldIssue.number -r "not planned" + } +} \ No newline at end of file diff --git a/scripts/label-no-recent.ps1 b/scripts/label-no-recent.ps1 new file mode 100644 index 0000000000..35d1c89b86 --- /dev/null +++ b/scripts/label-no-recent.ps1 @@ -0,0 +1,19 @@ +$inactivityDelay = [timespan]::Parse($Env:NO_RECENT_ACTIVITY_DURATION) +$oldIssues = gh issue list --label "$Env:NEEDS_AUTHOR_FEEDBACK_LABEL" --state open --limit 100 --json number,author,createdAt | ConvertFrom-Json +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) + + } else { + $lastCommentDate = [datetime]::Parse($lastComment.createdAt) + } + $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) { + 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 (($lastCommentDate - $lastLabelEventDate) -le $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" + } +} \ No newline at end of file From 9a86ad3bce3c3149c17864c2e04b4d94ccbcc677 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 9 Nov 2023 14:09:09 -0500 Subject: [PATCH 2/3] - updates inactivity message and delays --- .github/workflows/inactive-issues.yml | 6 +++--- scripts/close-no-recent.ps1 | 2 +- scripts/label-no-recent.ps1 | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/inactive-issues.yml b/.github/workflows/inactive-issues.yml index 1afed4337b..597b7e876a 100644 --- a/.github/workflows/inactive-issues.yml +++ b/.github/workflows/inactive-issues.yml @@ -15,11 +15,11 @@ env: NEEDS_ATTENTION_LABEL: "Needs attention" NEEDS_AUTHOR_FEEDBACK_LABEL: "Needs author feedback" NO_RECENT_ACTIVITY_LABEL: "No recent activity" - NO_RECENT_ACTIVITY_DURATION: "00:00:01" - NO_RECENT_ACTIVITY_DURATION_CLOSE: "00:00:01" + NO_RECENT_ACTIVITY_DURATION_IN_DAYS: 7 + NO_RECENT_ACTIVITY_DURATION_CLOSE_IN_DAYS: 28 ORG_NAME: ${{ github.repository_owner }} REPO_NAME: ${{ github.event.repository.name }} - NO_RECENT_ACTIVITY_COMMENT: "This issue has been labeled because there has been no recent activity. It will be closed if no further activity occurs within 1 day." + NO_RECENT_ACTIVITY_COMMENT: "This issue has been labeled with `No recent activity` because there has been no recent activity. It will be closed if no further activity occurs within 28 days. Please re-open this issue or open a new one after this delay if you need to." jobs: diff --git a/scripts/close-no-recent.ps1 b/scripts/close-no-recent.ps1 index 77ec4a7327..4923e5a7d5 100644 --- a/scripts/close-no-recent.ps1 +++ b/scripts/close-no-recent.ps1 @@ -1,4 +1,4 @@ -$inactivityDelay = [timespan]::Parse($Env:NO_RECENT_ACTIVITY_DURATION_CLOSE) +$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 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 diff --git a/scripts/label-no-recent.ps1 b/scripts/label-no-recent.ps1 index 35d1c89b86..3cb696060c 100644 --- a/scripts/label-no-recent.ps1 +++ b/scripts/label-no-recent.ps1 @@ -1,4 +1,4 @@ -$inactivityDelay = [timespan]::Parse($Env:NO_RECENT_ACTIVITY_DURATION) +$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 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 From 3536a5e106d38a449754bd5b31caa431fb28205f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 9 Nov 2023 14:18:08 -0500 Subject: [PATCH 3/3] - adds missing permission to read the content Signed-off-by: Vincent Biret --- .github/workflows/inactive-issues.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/inactive-issues.yml b/.github/workflows/inactive-issues.yml index 597b7e876a..6f1b64d47a 100644 --- a/.github/workflows/inactive-issues.yml +++ b/.github/workflows/inactive-issues.yml @@ -7,6 +7,7 @@ on: permissions: issues: write + contents: read name: Label and close issues with no recent activity