Skip to content

Commit c78d5b2

Browse files
committed
Added preimplemented stale GitHub action
1 parent 2474f90 commit c78d5b2

File tree

2 files changed

+26
-50
lines changed

2 files changed

+26
-50
lines changed
Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,38 @@
1-
# This workflow add "stale" label to issues that have "stat:awaiting-response" for more than 60 days meaning that since we don't have enough information we may potentially close such issue
1+
# This workflow utilises an existing implementation (https://github.com/actions/stale) that performs the following actions:
2+
# 1) Adds "stale" label to issues that have "stat:awaiting-response" for more than 30 days meaning that since we don't have enough information we may potentially close such issue
3+
# 2) Closes issues that have been marked as "stale" for more than 30 days
24

3-
name: Mark Stale Issues
5+
# This affects only Issues but at some point we may also consider rules for PRs
6+
7+
name: Mark and Close Stale Issues
48

59
on:
610
workflow_dispatch:
711
schedule:
812
- cron: '0 0 * * *' # Runs daily at midnight
913

10-
env:
11-
AWAITING-RESPONSE_LABEL: stat:awaiting-response
12-
STALE_LABEL: stale
13-
DAYS_BEFORE_STALE: 60 # 2 months
14-
1514
jobs:
16-
mark_stale:
17-
name: Check and Mark Stale Issues
18-
if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }}
15+
stale:
1916
runs-on: ubuntu-latest
2017
permissions:
2118
issues: write
22-
19+
2320
steps:
24-
- name: Get Issues with Awaiting Response
25-
id: get_issues
26-
run: |
27-
# Get all open issues with awaiting-response label
28-
ISSUES=$(gh issue list --label "${{ env.AWAITING-RESPONSE_LABEL }}" --json number,labels,updatedAt --jq '.[]')
29-
30-
echo "ISSUES=$ISSUES" >> $GITHUB_ENV
31-
32-
- name: Process Issues
33-
run: |
34-
current_time=$(date +%s)
35-
36-
echo "$ISSUES" | while read -r issue; do
37-
# Extract issue details
38-
number=$(echo "$issue" | jq -r .number)
39-
updated_at=$(echo "$issue" | jq -r .updatedAt)
40-
has_stale=$(echo "$issue" | jq -r '.labels[].name | select(. == "stale")' || echo "")
41-
42-
# Convert updated_at to timestamp
43-
updated_time=$(date -d "$updated_at" +%s)
44-
45-
# Calculate days difference
46-
days_diff=$(( (current_time - updated_time) / 86400 ))
47-
48-
# Check if issue should be marked stale
49-
if [[ $days_diff -ge ${{ env.DAYS_BEFORE_STALE }} && -z "$has_stale" ]]; then
50-
echo "Marking issue #$number as stale"
51-
gh issue edit "$number" --add-label "${{ env.STALE_LABEL }}" \
52-
--body-file <(
53-
echo "This issue has been automatically marked as stale because it has been awaiting response for over 2 months without any activity."
54-
echo ""
55-
echo "Please update the issue with any new information or it may be closed in the future."
56-
)
57-
fi
58-
done
59-
env:
60-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
GH_REPO: ${{ github.repository }}
21+
- uses: actions/stale@v9
22+
with:
23+
# Only mark issues (not PRs) as stale
24+
only-issue-labels: 'stat:awaiting-response'
25+
days-before-stale: 30
26+
days-before-close: 30
27+
stale-issue-label: 'Stale'
28+
stale-issue-message: >
29+
This issue has been automatically marked as stale because it has been awaiting
30+
response for over 30 days without any activity.
6231
32+
Please update the issue with any new information or it may be closed in 30 days.
33+
close-issue-message: >
34+
This issue has been automatically closed because it has been stale for 30 days
35+
without any activity. Feel free to reopen if you have new information to add.
36+
# Prevent the action from marking/closing PRs
37+
days-before-pr-stale: -1
38+
days-before-pr-close: -1

.github/workflows/remove-labels-on-issue-close.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
EXISTING_LABELS: ${{ toJson(github.event.issue.labels.*.name) }}
3333

3434
- name: Remove labels
35-
if: env.HAS_LABELS == 'true'
35+
if: ${{ env.REMOVE_LABELS != '' }}
3636
run: gh issue edit "$NUMBER" --remove-label "$REMOVE_LABELS"
3737
env:
3838
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)