diff --git a/.github/workflows/auto-fill-pr.yml b/.github/workflows/auto-fill-pr.yml index d5e69e0..e8351bb 100644 --- a/.github/workflows/auto-fill-pr.yml +++ b/.github/workflows/auto-fill-pr.yml @@ -25,6 +25,10 @@ jobs: id: ticket run: | BRANCH="${{ github.head_ref }}" + if [ -z "$BRANCH" ]; then + BRANCH="${{ github.ref }}" + BRANCH="${BRANCH#refs/heads/}" + fi if [[ "$BRANCH" =~ ([Ii][Mm]-[0-9]+) ]]; then TICKET="${BASH_REMATCH[1]^^}" echo "ticket=$TICKET" >> $GITHUB_OUTPUT @@ -226,8 +230,8 @@ jobs: const existingBody = pr.body || ''; // Helper to check if a section is empty (only has comment placeholder) - const isSectionEmpty = (body, sectionHeader, nextHeader) => { - const sectionRegex = new RegExp(`## ${sectionHeader}\\s*([\\s\\S]*?)(?=## ${nextHeader}|$)`, 'i'); + const isSectionEmpty = (body, sectionHeader) => { + const sectionRegex = new RegExp(`## ${sectionHeader}\\s*([\\s\\S]*?)(?=\\n## |$)`, 'i'); const match = body.match(sectionRegex); if (!match) return true; const content = match[1].trim(); @@ -237,7 +241,7 @@ jobs: // Helper to check if any checkbox is checked in Type of Change const hasCheckedType = (body) => { - const typeSection = body.match(/## Type of Change[\s\S]*?(?=## |$)/i); + const typeSection = body.match(/## Type of Change[\s\S]*?(?=\n## |$)/i); if (!typeSection) return false; return /\[x\]/i.test(typeSection[0]); }; @@ -248,10 +252,10 @@ jobs: const fileCount = parseInt(fs.readFileSync('/tmp/file_count.txt', 'utf8').trim()); // Determine what to fill - const fillDescription = isSectionEmpty(existingBody, 'Description', 'Ticket'); - const fillTicket = isSectionEmpty(existingBody, 'Ticket', 'Type of Change'); + const fillDescription = isSectionEmpty(existingBody, 'Description'); + const fillTicket = isSectionEmpty(existingBody, 'Ticket'); const fillType = !hasCheckedType(existingBody) && changeType !== 'unknown'; - const fillTesting = isSectionEmpty(existingBody, 'Testing Done', 'Checklist'); + const fillTesting = isSectionEmpty(existingBody, 'Testing Done'); // Get description (Claude or fallback) let description; @@ -330,7 +334,7 @@ jobs: // Add footer if we changed anything const madeChanges = fillDescription || (fillTicket && ticketSection) || fillType || (fillTesting && testing); if (madeChanges && !newBody.includes('Auto-generated by Claude') && !newBody.includes('Auto-filled')) { - const footer = claudeSuccess ? '\n---\n_✨ Auto-generated by Claude_' : '\n---\n_📝 Auto-filled_'; + const footer = claudeSuccess ? '\n\n---\n_✨ Auto-generated by Claude_' : '\n\n---\n_📝 Auto-filled_'; newBody = newBody.trim() + footer; }