Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions .github/workflows/append-learnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,44 @@ jobs:
uses: actions/github-script@v7
with:
script: |
// Helpers
// Extract a markdown section by heading name.
// Accepts variations like:
// ## Additional Notes:
// ## Additional Notes (optional):
// ## How It Works:
// Terminates at the next markdown heading (## ...) or EOF.
function section(name, body) {
// Match "## Name:" OR "Name:" (case-insensitive), capture until blank line or end
const re = new RegExp(`(?:^|\\n)##?\\s*${name}\\s*:\\s*([\\s\\S]*?)(?:\\n\\s*\\n|$)`, 'i');
const re = new RegExp(
String.raw`(?:^|\n)#{1,6}\s*` + // heading start
name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + // escaped name
String.raw`(?:\s*\(.*?\))?\s*:\s*` + // optional (parenthetical):
String.raw`([\s\S]*?)` + // capture body lazily
String.raw`(?=\n#{1,6}\s|$)`, // until next heading or end
'i'
);
const m = body.match(re);
return m ? m[1].trim() : '';
}
function mdClean(s) {
// Normalize Windows newlines, trim trailing spaces
return s.replace(/\r/g, '').trim();
return m ? m[1].replace(/\r/g, '').trim() : '';
}

const pr = context.payload.pull_request;
const pr = context.payload.pull_request;
const body = pr.body || '';

const changeSummary = mdClean(section('Change Summary', body));
const howItWorks = mdClean(section('How It Works', body));
const notes = mdClean(section('Additional Notes', body));
const changeSummary = section('Change Summary', body);
const howItWorks = section('How It Works', body);
const notes = section('Additional Notes', body); // will match "(optional)" too

// If everything is empty, do nothing
if (!changeSummary && !howItWorks && !notes) {
core.setOutput('should_update', 'false');
return;
}

const today = new Date().toISOString().slice(0,10); // YYYY-MM-DD
const today = new Date().toISOString().slice(0,10); // YYYY-MM-DD
const header = `## ${today} - PR #${pr.number}: ${pr.title}`;

let entry = `${header}\n\n`;
if (changeSummary) entry += `**Change Summary:** ${changeSummary}\n\n`;
if (howItWorks) entry += `**How It Works:** ${howItWorks}\n\n`;
if (notes) entry += `**Additional Notes:** ${notes}\n\n`;
if (howItWorks) entry += `**How It Works:** ${howItWorks}\n\n`;
if (notes) entry += `**Additional Notes:** ${notes}\n\n`;

core.setOutput('should_update', 'true');
core.setOutput('entry', entry);
Expand Down