Skip to content

Commit f3992b6

Browse files
committed
feat(examples): implement native staleness check to save AI resources
1 parent 1cdeb18 commit f3992b6

File tree

3 files changed

+80
-28
lines changed

3 files changed

+80
-28
lines changed

examples/workflows/issue-cleanup/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ This document describes a workflow to batch-process and clean up older open issu
66

77
The Issue Cleanup workflow is designed to automate the triage of stale issues by using the Gemini CLI to:
88

9-
1. **Check for Staleness and Vagueness**: Identifies issues with insufficient information. If a request for more information has gone unanswered for over a week, it closes the issue. If it's a new vague issue, it asks the reporter for specific details.
10-
2. **Check Code Validity**: Determines if an issue is still relevant against the current codebase. If the issue has already been resolved implicitly, it will close the issue with an explanation.
11-
3. **Find Duplicates**: Checks if the issue has a more recent duplicate. If a duplicate exists, it closes the issue and links to the duplicate.
12-
4. **Summarize for Triage**: If an issue is still valid and unique, it provides a summary comment based on customizable instructions (e.g., categorizing it as `Maintainer-only` or `Help-wanted`). If no custom instructions are provided, it falls back to a standard triage summary (identifying the core problem, impact, and next steps).
9+
1. **Check for Staleness (Native)**: Identifies if an issue has been waiting for reporter feedback for over 7 days. If so, it closes the issue directly via a native bash script to save AI resources.
10+
2. **Check for Vagueness (AI)**: If an issue is not stale but lacks sufficient information (e.g., reproduction steps), the agent asks the reporter for specific details and stops.
11+
3. **Check Code Validity (AI)**: Determines if an issue is still relevant against the current codebase. If the issue has already been resolved implicitly, it will close the issue with an explanation.
12+
4. **Find Duplicates (AI)**: Checks if the issue has a more recent duplicate. If a duplicate exists, it closes the issue and links to the duplicate.
13+
5. **Summarize for Triage (AI)**: If an issue is still valid and unique, it provides a summary comment based on customizable instructions (e.g., categorizing it as `Maintainer-only` or `Help-wanted`). If no custom instructions are provided, it falls back to a standard triage summary.
1314

1415
## Usage
1516

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
description = "Analyzes and cleans up older issues by checking code validity, duplicates, and providing a triage summary."
22
prompt = """
3+
## Primary Directive
4+
You are an automated triage bot. Your ONLY purpose is to execute the issue triage task below for Issue #!{echo $ISSUE_NUMBER} in `!{echo $REPOSITORY}`.
5+
**DO NOT** investigate the current workspace, `.github/` folder, `package.json`, or any local documentation.
6+
**DO NOT** explain your plan or the workflow to the user.
7+
**MANDATORY FIRST ACTION**: You MUST immediately run `git clone https://github.com/!{echo $REPOSITORY}.git target-repo` and then proceed directly to Step 1.
8+
39
## Role
4-
You are an automated triage bot for the `!{echo $REPOSITORY}` repository. Your job is to process Issue #!{echo $ISSUE_NUMBER} as efficiently as possible.
10+
You are an expert AI triage assistant for the `!{echo $REPOSITORY}` repository.
511
612
## Critical Constraints
7-
1. **NO META-ANALYSIS**: DO NOT read local files in the repository you are running in (like `package.json`, `README.md`, or `.github/`). Only read files within the `target-repo/` folder you clone in Step 1.
8-
2. **STALENESS FIRST**: If an information request to the reporter is older than 7 days, CLOSE the issue immediately and STOP. Do not investigate the code.
9-
3. **MANDATORY SERIAL START**: In your very first turn, you MUST execute exactly these three tools:
10-
- `git clone https://github.com/!{echo $REPOSITORY}.git target-repo`
11-
- `gh issue view !{echo $ISSUE_NUMBER} --repo !{echo $REPOSITORY} --json author,comments,updatedAt`
12-
- `date`
13+
1. **No Workspace Meta-Analysis**: Do not read local files that are not part of the target repository you cloned.
14+
2. **Efficiency**: Use `grep_search` and `read_file` quickly. If you cannot definitively prove an issue is invalid within 5 turns, move to Step 3 and categorize as `Maintainer-only`.
15+
3. **Tool Usage**: Use `gh` for all GitHub interactions and `git` for cloning. Use `target-repo/` as the root for all code searches.
1316
14-
## Task Lifecycle
17+
## Task
18+
Perform these checks for Issue #!{echo $ISSUE_NUMBER}:
1519
16-
### Step 1: Staleness & Vagueness Check
17-
- Examine the `gh issue view` output.
18-
- **Vagueness**: If the issue is too vague (no logs, no repro steps), @mention the reporter asking for specific details. STOP.
19-
- **Staleness**: If a maintainer or bot previously asked for information and it has been more than 7 days (check against `date`) and the reporter has NOT replied:
20-
- `gh issue close !{echo $ISSUE_NUMBER} --comment "Closing because it has been over a week since we requested more information and we haven't received a response. Feel free to reopen if you can provide the requested details." --repo !{echo $REPOSITORY}`
20+
### Step 1: Check for Vagueness
21+
- Use `gh issue view !{echo $ISSUE_NUMBER} --repo !{echo $REPOSITORY} --json title,body,author,comments` to read the issue.
22+
- If the issue description is too vague to be actionable (e.g., missing reproduction steps, environment, or clear goal) and no one has asked for more information yet:
23+
- Ask the reporter: `gh issue comment !{echo $ISSUE_NUMBER} --body "@<reporter_username>, thank you for the report! Could you please provide more specific details (e.g., reproduction steps, expected behavior, and environment)? Closing this as vague if no response is received in a week." --repo !{echo $REPOSITORY}`
2124
- STOP execution.
22-
- If not stale or vague, proceed to Step 2.
25+
- If the issue is clear or the reporter has provided the requested info, proceed to Step 2.
2326
24-
### Step 2: Code Validity Check
25-
- Search `target-repo/` to see if the bug still exists or the feature is already implemented.
26-
- If fixed: `gh issue close !{echo $ISSUE_NUMBER} --comment "Closing because this appears to have been fixed in the latest codebase." --repo !{echo $REPOSITORY}`. STOP.
27+
### Step 2: Check Code Validity
28+
- Search the `target-repo/` directory to see if the issue is still relevant.
29+
- If definitively NO LONGER VALID:
30+
- Close it: `gh issue close !{echo $ISSUE_NUMBER} --comment "Closing because this appears to have been fixed in the latest codebase. <explanation>" --repo !{echo $REPOSITORY}`
31+
- STOP execution.
2732
28-
### Step 3: Duplicate Check
29-
- Search for duplicates using `gh issue list`.
30-
- If found: `gh issue close !{echo $ISSUE_NUMBER} --reason "not planned" --comment "Closing as duplicate of #<duplicate_number>." --repo !{echo $REPOSITORY}`. STOP.
33+
### Step 3: Check for Duplicates
34+
- Search for duplicates: `gh issue list --search "<keywords>" --repo !{echo $REPOSITORY} --state all`
35+
- If a clear duplicate is found:
36+
- Close it: `gh issue close !{echo $ISSUE_NUMBER} --reason "not planned" --comment "Closing as duplicate of #<duplicate_number>." --repo !{echo $REPOSITORY}`
37+
- STOP execution.
3138
32-
### Step 4: Triage Summary
33-
- If unique and valid, provide a summary comment using these instructions:
39+
### Step 4: Provide Triage Summary
40+
- If unique and valid, provide a summary comment based on these instructions:
3441
```
3542
!{echo $CUSTOM_INSTRUCTIONS}
3643
```
37-
- Action: `gh issue comment !{echo $ISSUE_NUMBER} --body "### Triage Summary\n\n<your summary>" --repo !{echo $REPOSITORY}`
38-
- STOP.
44+
- Fallback (if instructions empty): Provide a standard summary of problem, impact, and next steps.
45+
- Comment: `gh issue comment !{echo $ISSUE_NUMBER} --body "### Triage Summary\n\n<your summary>" --repo !{echo $REPOSITORY}`
46+
- STOP execution.
3947
"""

examples/workflows/issue-cleanup/gemini-issue-cleanup.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,50 @@ jobs:
6464
- name: 'Checkout Current Repository'
6565
uses: 'actions/checkout@v4'
6666

67+
- name: 'Check for Staleness'
68+
id: 'check_staleness'
69+
env:
70+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN || github.token }}'
71+
ISSUE_NUMBER: '${{ matrix.issue_number }}'
72+
REPOSITORY: '${{ github.repository }}'
73+
run: |-
74+
echo "=== GET ISSUE DATA ==="
75+
ISSUE_JSON=$(gh issue view "${ISSUE_NUMBER}" --repo "${REPOSITORY}" --json author,comments)
76+
77+
REPORTER=$(echo "${ISSUE_JSON}" | jq -r '.author.login')
78+
echo "Reporter is: ${REPORTER}"
79+
80+
# Find the last comment by someone other than the reporter
81+
LAST_MAINTAINER_COMMENT_DATE=$(echo "${ISSUE_JSON}" | jq -r '
82+
.comments | reverse | map(select(.author.login != "'"${REPORTER}"'" and .author.login != "github-actions" and .author.login != "app/github-actions")) | .[0]?.updatedAt // "null"
83+
')
84+
85+
if [ "${LAST_MAINTAINER_COMMENT_DATE}" != "null" ] && [ -n "${LAST_MAINTAINER_COMMENT_DATE}" ]; then
86+
echo "Last maintainer comment date: ${LAST_MAINTAINER_COMMENT_DATE}"
87+
88+
# Check if reporter replied AFTER this date
89+
REPORTER_REPLIED=$(echo "${ISSUE_JSON}" | jq -r '
90+
.comments | map(select(.author.login == "'"${REPORTER}"'" and .updatedAt > "'"${LAST_MAINTAINER_COMMENT_DATE}"'")) | length > 0
91+
')
92+
93+
if [ "${REPORTER_REPLIED}" = "false" ]; then
94+
# Calculate days ago
95+
DAYS_AGO=$(( ($(date +%s) - $(date -d "${LAST_MAINTAINER_COMMENT_DATE}" +%s)) / 86400 ))
96+
echo "It has been ${DAYS_AGO} days since maintainer asked for info."
97+
98+
if [ "${DAYS_AGO}" -gt 7 ]; then
99+
echo "=== STALE ISSUE DETECTED. CLOSING NOW. ==="
100+
gh issue close "${ISSUE_NUMBER}" --comment "Closing because it has been over a week since we requested more information and we haven't received a response. Feel free to reopen if you can provide the requested details." --repo "${REPOSITORY}"
101+
echo "continue_ai=false" >> "${GITHUB_OUTPUT}"
102+
exit 0
103+
fi
104+
fi
105+
fi
106+
107+
echo "continue_ai=true" >> "${GITHUB_OUTPUT}"
108+
67109
- name: 'Run Gemini Issue Cleanup'
110+
if: steps.check_staleness.outputs.continue_ai == 'true'
68111
uses: 'google-github-actions/run-gemini-cli@v0' # Replace with actual version when deploying
69112
env:
70113
ISSUE_NUMBER: '${{ matrix.issue_number }}'

0 commit comments

Comments
 (0)