@@ -125,34 +125,54 @@ jobs:
125125
126126 ## Steps
127127
128- 1. First, check for existing override labels:
128+ 1. First, check for existing override labels AND existing severity labels :
129129 ```
130130 gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name'
131131 ```
132+ Note which `severity-*` label (if any) is currently applied. This is
133+ the "previous severity".
132134
133135 2. If an override label exists (severity-override-*), use that level and skip classification.
134136
135- 3. Get the list of changed files:
137+ 3. Check for existing bot comments. Look for the HTML marker `<!-- pr-severity-bot -->`:
138+ ```
139+ gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[].body' | grep -c 'pr-severity-bot' || true
140+ ```
141+ This tells you whether the bot has commented before.
142+
143+ 4. Get the list of changed files:
136144 ```
137145 gh pr view ${{ github.event.pull_request.number }} --json files,additions,deletions
138146 ```
139147
140- 4. Classify each file and determine overall severity.
148+ 5. Classify each file and determine the new overall severity.
149+
150+ 6. **Decide whether to comment.** Only post a comment if EITHER:
151+ - The bot has NOT commented before (no existing comment with `<!-- pr-severity-bot -->`), OR
152+ - The newly determined severity is DIFFERENT from the previous severity label.
141153
142- 5. Remove any existing severity-* labels (not override labels):
154+ If the bot already commented AND the severity has NOT changed, just
155+ stop here — do NOT post another comment. Still update the label if
156+ needed (step 7-8), but skip the comment.
157+
158+ 7. Remove any existing severity-* labels (not override labels):
143159 ```
144160 gh pr edit ${{ github.event.pull_request.number }} --remove-label "severity-critical" 2>/dev/null || true
145161 gh pr edit ${{ github.event.pull_request.number }} --remove-label "severity-high" 2>/dev/null || true
146162 gh pr edit ${{ github.event.pull_request.number }} --remove-label "severity-medium" 2>/dev/null || true
147163 gh pr edit ${{ github.event.pull_request.number }} --remove-label "severity-low" 2>/dev/null || true
148164 ```
149165
150- 6 . Apply the new severity label:
166+ 8 . Apply the new severity label:
151167 ```
152168 gh pr edit ${{ github.event.pull_request.number }} --add-label "severity-<level>"
153169 ```
154170
155- 7. Post a comment with your analysis. Use this format:
171+ 9. If you determined in step 6 that a comment should be posted, post it
172+ with your analysis. Use this format:
173+
174+ If this is a severity CHANGE (previous label existed but differs),
175+ prepend: `> ⚠️ Severity changed: **<OLD>** → **<NEW>** (files changed since last classification)`
156176
157177 ```markdown
158178 ## <emoji> PR Severity: **<LEVEL>**
@@ -178,11 +198,14 @@ jobs:
178198 <!-- pr-severity-bot -->
179199 ```
180200
181- 8 . Post the comment using `gh pr comment`:
201+ 10 . Post the comment using `gh pr comment`:
182202 ```
183203 gh pr comment ${{ github.event.pull_request.number }} --body "YOUR_COMMENT_HERE"
184204 ```
185205
206+ 11. If you decided in step 6 to SKIP commenting, do NOT post any comment.
207+ Just ensure the label is correct and exit.
208+
186209 ## Emoji Mapping
187210 - critical: 🔴
188211 - high: 🟠
0 commit comments