Skip to content

Commit d49e921

Browse files
fix(workflows): improve attempt comments and fix PR body parsing
- Only post attempt comment if PR was actually created (not on failures) - Make approach section more technical (imports, plot function, params) - Fix shell escaping for PR body in bot-auto-merge.yml (use gh pr view)
1 parent 1d68eb0 commit d49e921

2 files changed

Lines changed: 60 additions & 37 deletions

File tree

.github/workflows/bot-auto-merge.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ jobs:
6666
env:
6767
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6868
run: |
69-
PR_BODY="${{ github.event.pull_request.body }}"
69+
PR_NUM="${{ github.event.pull_request.number }}"
70+
PR_BODY=$(gh pr view "$PR_NUM" --json body -q '.body' 2>/dev/null || echo "")
7071
SUB_ISSUE=$(echo "$PR_BODY" | grep -oP '\*\*Sub-Issue:\*\* #\K\d+' | head -1 || echo "")
7172
echo "number=$SUB_ISSUE" >> $GITHUB_OUTPUT
7273
@@ -147,7 +148,8 @@ jobs:
147148
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148149
run: |
149150
BRANCH="${{ github.event.pull_request.head.ref }}"
150-
PR_BODY="${{ github.event.pull_request.body }}"
151+
PR_NUM="${{ github.event.pull_request.number }}"
152+
PR_BODY=$(gh pr view "$PR_NUM" --json body -q '.body' 2>/dev/null || echo "")
151153
152154
# Format: auto/{spec-id}/{library}
153155
SPEC_ID=$(echo "$BRANCH" | cut -d'/' -f2)

.github/workflows/gen-library-impl.yml

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ jobs:
192192
fi
193193
194194
- name: Update sub-issue with attempt details
195-
if: always()
195+
if: steps.pr.outputs.pr_exists == 'true'
196196
env:
197197
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
198198
run: |
@@ -213,63 +213,84 @@ jobs:
213213
214214
# Create attempt documentation comment
215215
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
216-
PR_LINK=$([[ -n "$PR_NUMBER" ]] && echo "#$PR_NUMBER" || echo "Not created")
217216
218-
# Extract approach from code (docstring + key comments)
217+
# Extract technical approach from code
219218
python3 << PYEOF
220219
import re
221220
222221
code = '''$CODE'''
223222
224-
# Extract approach bullet points
225223
approach_lines = []
226224
227-
# 1. Get module docstring (first line after triple quotes)
228-
docstring_match = re.search(r'^"""(.*?)"""', code, re.DOTALL)
229-
if docstring_match:
230-
doc = docstring_match.group(1).strip()
231-
# Get first meaningful line (title/description)
232-
for line in doc.split('\n'):
233-
line = line.strip()
234-
if line and not line.startswith('Library:'):
235-
approach_lines.append(f"- {line}")
236-
break
237-
238-
# 2. Extract structural comments as approach steps
239-
for line in code.split('\n'):
240-
line = line.strip()
241-
# Look for section comments like "# Create figure", "# Plot data"
242-
if line.startswith('# ') and not line.startswith('# Input') and not line.startswith('# Sample'):
243-
comment = line[2:].strip()
244-
if comment and len(comment) > 3 and comment[0].isupper():
245-
approach_lines.append(f"- {comment}")
246-
247-
# 3. Extract key imports
225+
# 1. Extract all imports (full import lines)
248226
imports = []
249227
for line in code.split('\n'):
250228
if line.startswith('import ') or line.startswith('from '):
251-
if 'matplotlib' in line or 'seaborn' in line or 'plotly' in line or 'bokeh' in line or 'altair' in line or 'plotnine' in line or 'pygal' in line or 'highcharts' in line:
252-
imports.append(line.split()[1].split('.')[0])
229+
# Skip typing imports
230+
if 'typing' not in line and 'TYPE_CHECKING' not in line:
231+
imports.append(line.strip())
253232
254233
if imports:
255-
approach_lines.insert(0, f"- Using: {', '.join(set(imports))}")
234+
approach_lines.append(f"**Imports:** \`{', '.join(imports[:3])}\`")
235+
236+
# 2. Find main plot function call (e.g., ax.plot, sns.lineplot, px.line)
237+
plot_patterns = [
238+
(r'ax\.(plot|scatter|bar|hist|boxplot|violinplot|heatmap|imshow)\s*\(', 'matplotlib'),
239+
(r'plt\.(plot|scatter|bar|hist)\s*\(', 'matplotlib'),
240+
(r'sns\.(lineplot|scatterplot|barplot|histplot|boxplot|violinplot|heatmap|regplot)\s*\(', 'seaborn'),
241+
(r'px\.(line|scatter|bar|histogram|box|violin|imshow|density_heatmap)\s*\(', 'plotly'),
242+
(r'go\.(Scatter|Bar|Heatmap|Box|Violin)\s*\(', 'plotly'),
243+
(r'figure\.(line|circle|scatter|vbar|hbar|quad|rect)\s*\(', 'bokeh'),
244+
(r'alt\.(Chart|LayerChart)\s*\(', 'altair'),
245+
(r'(ggplot|geom_line|geom_point|geom_bar|geom_histogram|geom_boxplot)\s*\(', 'plotnine'),
246+
(r'pygal\.(Line|Bar|Pie|XY|Histogram|Box|Dot)\s*\(', 'pygal'),
247+
(r'(LineSeries|BarSeries|ScatterSeries|PieSeries)\s*\(', 'highcharts'),
248+
]
249+
250+
for pattern, lib in plot_patterns:
251+
match = re.search(pattern, code)
252+
if match:
253+
approach_lines.append(f"**Plot function:** \`{match.group(0).rstrip('(')}\`")
254+
break
255+
256+
# 3. Extract create_plot function signature
257+
func_match = re.search(r'def create_plot\((.*?)\)\s*->', code, re.DOTALL)
258+
if func_match:
259+
params = func_match.group(1).strip()
260+
# Get first 3 params
261+
param_list = [p.strip().split(':')[0].strip() for p in params.split(',')[:4]]
262+
approach_lines.append(f"**Parameters:** \`{', '.join(param_list)}\`")
263+
264+
# 4. Extract key styling/config (figsize, style, etc.)
265+
style_patterns = [
266+
(r"figsize\s*=\s*\(([^)]+)\)", "figsize"),
267+
(r"style\s*=\s*['\"]([^'\"]+)['\"]", "style"),
268+
(r"template\s*=\s*['\"]([^'\"]+)['\"]", "template"),
269+
(r"color\s*=\s*['\"]([^'\"]+)['\"]", "color"),
270+
]
271+
272+
styles = []
273+
for pattern, name in style_patterns:
274+
match = re.search(pattern, code)
275+
if match:
276+
styles.append(f"{name}={match.group(1)}")
256277
257-
# Limit to 6 bullet points
258-
approach_lines = approach_lines[:6]
278+
if styles:
279+
approach_lines.append(f"**Config:** {', '.join(styles[:3])}")
259280
260281
if not approach_lines:
261-
approach_lines = ["- See PR for implementation details"]
282+
approach_lines = ["See PR for implementation details"]
262283
263-
approach_text = '\n'.join(approach_lines)
284+
approach_text = '\n'.join(f"- {line}" for line in approach_lines)
264285
265286
lines = [
266-
f"## Attempt $ATTEMPT/3 - $TIMESTAMP",
287+
f"## Attempt $ATTEMPT/3",
267288
"",
268-
"### Approach",
289+
"### Technical Approach",
269290
approach_text,
270291
"",
271292
"### Status",
272-
f"- **PR:** $PR_LINK",
293+
f"- **PR:** #$PR_NUMBER",
273294
f"- **File:** \`$PLOT_FILE\`",
274295
f"- **Workflow:** [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})",
275296
"",

0 commit comments

Comments
 (0)