@@ -29,11 +29,28 @@ inputs:
2929 required : false
3030 default : " standard"
3131
32+ custom-template :
33+ description : " Custom markdown template. Supports placeholders: {{summary}}, {{files}}, {{changes}}, {{file_count}}"
34+ required : false
35+
36+ custom-template-file :
37+ description : " Path to a file in the repo containing a custom markdown template"
38+ required : false
39+
40+ generate-changelog :
41+ description : " When true, generates changelog entries from merged PRs. Requires pull_request event types: [closed]"
42+ required : false
43+ default : " false"
44+
3245outputs :
3346 description :
3447 description : " The generated PR description"
3548 value : ${{ steps.generate.outputs.description }}
3649
50+ changelog-entry :
51+ description : " Generated changelog entry (only set when generate-changelog is true and PR is merged)"
52+ value : ${{ steps.changelog.outputs.changelog_entry }}
53+
3754runs :
3855 using : " composite"
3956 steps :
@@ -218,7 +235,53 @@ runs:
218235 CHANGES_SECTION="${CHANGES_SECTION}"$'\n'
219236 fi
220237
221- if [ "$STYLE" = "minimal" ]; then
238+ # --- Custom template support ---
239+ CUSTOM_TEMPLATE_SET=false
240+
241+ if [ -n "${{ inputs.custom-template }}" ]; then
242+ cat > /tmp/custom_template.txt << 'DOCUCRAFT_EOF'
243+ ${{ inputs.custom-template }}
244+ DOCUCRAFT_EOF
245+ CUSTOM_TEMPLATE_SET=true
246+ elif [ -n "${{ inputs.custom-template-file }}" ]; then
247+ TMPL_FILE="$GITHUB_WORKSPACE/${{ inputs.custom-template-file }}"
248+ if [ -f "$TMPL_FILE" ]; then
249+ cp "$TMPL_FILE" /tmp/custom_template.txt
250+ CUSTOM_TEMPLATE_SET=true
251+ else
252+ echo "::warning title=DocuCraft::Custom template file not found : ${{ inputs.custom-template-file }}"
253+ fi
254+ fi
255+
256+ if [ "$CUSTOM_TEMPLATE_SET" = true ] && [ -s /tmp/custom_template.txt ]; then
257+ FILES_LIST=$(cat /tmp/pr_files.txt 2>/dev/null || echo "None")
258+
259+ echo "$FILES_LIST" > /tmp/template_files.txt
260+ echo "$CHANGES_SECTION" > /tmp/template_changes.txt
261+
262+ cp /tmp/custom_template.txt /tmp/template_work.txt
263+
264+ sed -i "s|{{summary}}|$SUMMARY|g" /tmp/template_work.txt
265+ sed -i "s|{{file_count}}|$FILE_COUNT|g" /tmp/template_work.txt
266+
267+ cat > /tmp/sed_files.sed << 'SEDEOF'
268+ /{{files}}/{
269+ r /tmp/template_files.txt
270+ d
271+ }
272+ SEDEOF
273+ cat > /tmp/sed_changes.sed << 'SEDEOF'
274+ /{{changes}}/{
275+ r /tmp/template_changes.txt
276+ d
277+ }
278+ SEDEOF
279+
280+ sed -i -f /tmp/sed_files.sed /tmp/template_work.txt
281+ sed -i -f /tmp/sed_changes.sed /tmp/template_work.txt
282+
283+ DESCRIPTION=$(cat /tmp/template_work.txt)
284+ elif [ "$STYLE" = "minimal" ]; then
222285 DESCRIPTION=$(cat <<DESC_EOF
223286# # Summary
224287
@@ -325,16 +388,54 @@ PROMPT_EOF
325388 echo "$DESCRIPTION" >> $GITHUB_OUTPUT
326389 echo "EOF" >> $GITHUB_OUTPUT
327390
391+ - name : Generate changelog entry
392+ id : changelog
393+ shell : bash
394+ if : ${{ inputs.generate-changelog == 'true' && github.event.action == 'closed' }}
395+ env :
396+ GH_TOKEN : ${{ inputs.github-token }}
397+ run : |
398+ PR_NUMBER="${{ github.event.pull_request.number }}"
399+ PR_TITLE="${{ github.event.pull_request.title }}"
400+ MERGED="${{ github.event.pull_request.merged }}"
401+
402+ if [ "$MERGED" = "true" ]; then
403+ DATE=$(date +%Y-%m-%d)
404+ PR_LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '[.labels[].name] | join(", ")' 2>/dev/null || echo "")
405+ MERGE_COMMIT="${{ github.event.pull_request.merge_commit_sha }}"
406+
407+ CHANGELOG=$(cat <<CHLOG_EOF
408+ # ## [#$PR_NUMBER] - $DATE
409+ $PR_TITLE
410+
411+ **Labels:** ${PR_LABELS:-none}
412+
413+ **Merge Commit:** $MERGE_COMMIT
414+
415+ **Files:**
416+ $(cat /tmp/pr_files.txt 2>/dev/null | sed 's/^/- /')
417+
418+ ---
419+ CHLOG_EOF
420+ )
421+ echo "changelog_entry<<EOF" >> $GITHUB_OUTPUT
422+ echo "$CHANGELOG" >> $GITHUB_OUTPUT
423+ echo "EOF" >> $GITHUB_OUTPUT
424+ else
425+ echo "PR # $PR_NUMBER was closed but not merged. Skipping changelog."
426+ fi
427+
328428 - name : Update PR body
329429 shell : bash
330430 env :
331431 GH_TOKEN : ${{ inputs.github-token }}
332432 run : |
333433 PR_NUMBER="${{ steps.diff.outputs.pr_number }}"
434+ PR_STATE="${{ github.event.pull_request.state }}"
334435 DESCRIPTION="${{ steps.generate.outputs.description }}"
335436 if [ -z "$DESCRIPTION" ]; then
336437 DESCRIPTION="${{ steps.generate-ai.outputs.description }}"
337438 fi
338- if [ -n "$DESCRIPTION" ]; then
439+ if [ "$PR_STATE" = "open" ] && [ -n "$DESCRIPTION" ]; then
339440 echo "$DESCRIPTION" | gh pr review $PR_NUMBER --body-file - 2>&1 || true
340441 fi
0 commit comments