Skip to content

fix: prevent duplicate body template when PR body is modified#20

Open
SetupCoding wants to merge 1 commit intodevindford:mainfrom
SetupCoding:fix/duplicate-body-detection
Open

fix: prevent duplicate body template when PR body is modified#20
SetupCoding wants to merge 1 commit intodevindford:mainfrom
SetupCoding:fix/duplicate-body-detection

Conversation

@SetupCoding
Copy link
Copy Markdown

Summary

Fixes duplicate body template insertion when the PR body has been manually edited by a user.

Problem

The current duplicate detection uses startsWith() / endsWith() to check if the template is already present in the PR body. This only works if the template remains at the exact start or end of the body.

When a user edits the PR body — adding text before a prefixed template or after a suffixed template — the positional check fails and the action inserts the template again, creating duplicates on every subsequent trigger.

Example scenario (prefix mode):

  1. Action runs → prepends template to body ✅
  2. User edits PR body, adds text above the template
  3. Action re-runs → startsWith() check fails → template prepended again ❌ (duplicate)

Fix

Replace startsWith() / endsWith() with includes() so the duplicate check finds the template regardless of its position within the body.

  const updateBody = ({
-   prefix: !body.toLowerCase().startsWith(inputs.bodyTemplate.toLowerCase()),
-   suffix: !body.toLowerCase().endsWith(inputs.bodyTemplate.toLowerCase())
+   prefix: !body.toLowerCase().includes(inputs.bodyTemplate.toLowerCase()),
+   suffix: !body.toLowerCase().includes(inputs.bodyTemplate.toLowerCase())
  })[inputs.bodyUpdateAction] || false;

Additional changes

  • Updated action.yml runtime from node16 to node24 (Node.js 20 deprecation on June 2nd 2026)
  • Rebuilt dist/index.js with @vercel/ncc

Use includes() instead of startsWith()/endsWith() for duplicate
detection. The previous check only matched if the template was at
the exact start or end of the body. When a user edits the PR body
(adding text before or after the template), the check would fail
and the template would be inserted again, creating duplicates.

Also updates action runtime from node16 to node24.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant