@@ -2,32 +2,64 @@ name: Append Learnings
22on :
33 pull_request :
44 types : [closed]
5+
56jobs :
67 append :
78 if : github.event.pull_request.merged == true
89 runs-on : ubuntu-latest
910 permissions :
1011 contents : write
1112 pull-requests : read
13+
1214 steps :
1315 - uses : actions/checkout@v4
14- - name : Extract learning from PR body
15- id : extract
16+
17+ - name : Build learnings entry from PR body
18+ id : build
1619 uses : actions/github-script@v7
1720 with :
1821 script : |
19- const body = context.payload.pull_request.body || "";
20- // Grab the section under "## What I Learned"
21- const match = body.match(/## What I Learned([\s\S]*?)(## |\Z)/);
22- const learned = match ? match[1].trim() : "";
23- core.setOutput("learned", learned);
24- - name : Update LEARNINGS.md
25- if : steps.extract.outputs.learned != ''
22+ // Helpers
23+ function section(name, body) {
24+ // Match "## Name:" OR "Name:" (case-insensitive), capture until blank line or end
25+ const re = new RegExp(`(?:^|\\n)##?\\s*${name}\\s*:\\s*([\\s\\S]*?)(?:\\n\\s*\\n|$)`, 'i');
26+ const m = body.match(re);
27+ return m ? m[1].trim() : '';
28+ }
29+ function mdClean(s) {
30+ // Normalize Windows newlines, trim trailing spaces
31+ return s.replace(/\r/g, '').trim();
32+ }
33+
34+ const pr = context.payload.pull_request;
35+ const body = pr.body || '';
36+
37+ const changeSummary = mdClean(section('Change Summary', body));
38+ const howItWorks = mdClean(section('How It Works', body));
39+ const notes = mdClean(section('Additional Notes', body));
40+
41+ // If everything is empty, do nothing
42+ if (!changeSummary && !howItWorks && !notes) {
43+ core.setOutput('should_update', 'false');
44+ return;
45+ }
46+
47+ const today = new Date().toISOString().slice(0,10); // YYYY-MM-DD
48+ const header = `## ${today} - PR #${pr.number}: ${pr.title}`;
49+
50+ let entry = `${header}\n\n`;
51+ if (changeSummary) entry += `**Change Summary**\n${changeSummary}\n\n`;
52+ if (howItWorks) entry += `**How It Works**\n${howItWorks}\n\n`;
53+ if (notes) entry += `**Additional Notes**\n${notes}\n\n`;
54+
55+ core.setOutput('should_update', 'true');
56+ core.setOutput('entry', entry);
57+
58+ - name : Append to LEARNINGS.md
59+ if : steps.build.outputs.should_update == 'true'
2660 run : |
27- echo "" >> LEARNINGS.md
28- echo "## $(date +'%Y-%m-%d') — PR #${{ github.event.pull_request.number }} ${GITHUB_REPOSITORY}" >> LEARNINGS.md
29- echo "${{ steps.extract.outputs.learned }}" >> LEARNINGS.md
30- echo "" >> LEARNINGS.md
61+ touch LEARNINGS.md
62+ printf "\n%s" "${{ steps.build.outputs.entry }}" >> LEARNINGS.md
3163 git config user.name "github-actions[bot]"
3264 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
3365 git add LEARNINGS.md
0 commit comments