fix: handle backticks in issue bodies when converting to discussions
Consolidate issue fetching and discussion creation into single step to avoid template literal injection issues. Issue data now stays in JavaScript context instead of being passed through GitHub Actions template interpolation, preventing syntax errors when issue bodies contain backticks or other special characters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,11 +24,12 @@ jobs:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Get issue details
|
||||
id: issue
|
||||
- name: Get issue details and create discussion
|
||||
id: discussion
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
// Get issue details
|
||||
let issue;
|
||||
if (context.eventName === 'workflow_dispatch') {
|
||||
const { data } = await github.rest.issues.get({
|
||||
@@ -41,28 +42,10 @@ jobs:
|
||||
issue = context.payload.issue;
|
||||
}
|
||||
|
||||
// Store issue details for next steps
|
||||
core.setOutput('number', issue.number);
|
||||
core.setOutput('title', issue.title);
|
||||
core.setOutput('body', issue.body || 'No description provided.');
|
||||
core.setOutput('author', issue.user.login);
|
||||
core.setOutput('url', issue.html_url);
|
||||
|
||||
console.log(`Processing issue #${issue.number}: ${issue.title}`);
|
||||
|
||||
- name: Create discussion
|
||||
id: discussion
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const issueNumber = '${{ steps.issue.outputs.number }}';
|
||||
const issueTitle = `${{ steps.issue.outputs.title }}`;
|
||||
const issueBody = `${{ steps.issue.outputs.body }}`;
|
||||
const issueAuthor = '${{ steps.issue.outputs.author }}';
|
||||
const issueUrl = '${{ steps.issue.outputs.url }}';
|
||||
|
||||
// Format the discussion body with a reference to the original issue
|
||||
const discussionBody = `> Originally posted as issue #${issueNumber} by @${issueAuthor}\n> ${issueUrl}\n\n${issueBody}`;
|
||||
const discussionBody = `> Originally posted as issue #${issue.number} by @${issue.user.login}\n> ${issue.html_url}\n\n${issue.body || 'No description provided.'}`;
|
||||
|
||||
const mutation = `
|
||||
mutation($repositoryId: ID!, $categoryId: ID!, $title: String!, $body: String!) {
|
||||
@@ -83,7 +66,7 @@ jobs:
|
||||
const variables = {
|
||||
repositoryId: 'R_kgDOPng1Jw',
|
||||
categoryId: 'DIC_kwDOPng1J84Cw86z',
|
||||
title: issueTitle,
|
||||
title: issue.title,
|
||||
body: discussionBody
|
||||
};
|
||||
|
||||
@@ -94,9 +77,10 @@ jobs:
|
||||
|
||||
core.setOutput('url', discussionUrl);
|
||||
core.setOutput('number', discussionNumber);
|
||||
core.setOutput('issue_number', issue.number);
|
||||
|
||||
console.log(`Created discussion #${discussionNumber}: ${discussionUrl}`);
|
||||
return discussionUrl;
|
||||
return { discussionUrl, discussionNumber, issueNumber: issue.number };
|
||||
} catch (error) {
|
||||
core.setFailed(`Failed to create discussion: ${error.message}`);
|
||||
throw error;
|
||||
@@ -106,7 +90,7 @@ jobs:
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const issueNumber = '${{ steps.issue.outputs.number }}';
|
||||
const issueNumber = ${{ steps.discussion.outputs.issue_number }};
|
||||
const discussionUrl = '${{ steps.discussion.outputs.url }}';
|
||||
|
||||
const comment = `This feature request has been moved to [Discussions](${discussionUrl}) to keep bug reports separate from feature ideas.\n\nPlease continue the conversation there - we'd love to hear your thoughts!`;
|
||||
@@ -124,7 +108,7 @@ jobs:
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const issueNumber = '${{ steps.issue.outputs.number }}';
|
||||
const issueNumber = ${{ steps.discussion.outputs.issue_number }};
|
||||
|
||||
// Close the issue
|
||||
await github.rest.issues.update({
|
||||
|
||||
Reference in New Issue
Block a user