fix: escape backticks and special chars in commit message for GitHub Action (#1928)

The `issue-closed-comment` workflow fails when commit messages contain
backticks because they're interpolated directly into JS template
strings, breaking syntax.

### Changes
- Escape backslashes, backticks, and `${` sequences before setting the
commit message output
- Order matters: backslashes first to avoid interfering with subsequent
escaping

```javascript
// Before: raw message breaks template string if it contains backticks
core.setOutput('commit_message', commit.message);

// After: properly escaped for safe interpolation
const escapedMessage = commit.message.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
core.setOutput('commit_message', escapedMessage);
```

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> the github action which comments on issue closure fails when the
commit message contains ` since these are js strings. Make sure to
escape them.


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for
you](https://github.com/go-vikunja/vikunja/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kolaente <13721712+kolaente@users.noreply.github.com>
This commit is contained in:
Copilot
2025-12-04 09:38:24 +00:00
committed by GitHub
parent 7cf2a6886e
commit 30104fb749

View File

@@ -53,7 +53,9 @@ jobs:
core.setOutput('closed_by_commit', 'true'); core.setOutput('closed_by_commit', 'true');
core.setOutput('commit_sha', commitId); core.setOutput('commit_sha', commitId);
core.setOutput('commit_message', commit.message); // Escape backslashes, backticks and ${ to prevent breaking JS template strings
const escapedMessage = commit.message.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
core.setOutput('commit_message', escapedMessage);
core.setOutput('commit_url', closedEvent.commit_url); core.setOutput('commit_url', closedEvent.commit_url);
} else { } else {
console.log(` Issue #${issueNumber} was closed manually (not by commit)`); console.log(` Issue #${issueNumber} was closed manually (not by commit)`);