Skip to content

Commit 07f9e10

Browse files
authored
Update i-music-process.yml
1 parent b3e8cf4 commit 07f9e10

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

.github/workflows/i-music-process.yml

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19-
- name: Setup Node.js
19+
20+
- name: Set up Node.js
2021
uses: actions/setup-node@v3
2122
with:
2223
node-version: '20'
2324

24-
- name: Install markdown-json
25-
run: npm install markdown-json
25+
- name: Install dependencies
26+
run: |
27+
npm install marked dompurify jsdom
2628
2729
- name: Check if issue title contains [MUSIC]
2830
uses: actions/github-script@v7
2931
with:
3032
script: |
31-
const issueTitle = context.payload.issue.title;
32-
if (issueTitle.includes("[MUSIC]")) {
33-
core.exportVariable('IS_MUSIC_ISSUE', 'true');
34-
} else {
35-
core.exportVariable('IS_MUSIC_ISSUE', 'false');
36-
}
33+
const issueTitle = context.payload.issue.title;
34+
if (issueTitle.includes("[MUSIC]")) {
35+
core.exportVariable('IS_MUSIC_ISSUE', 'true');
36+
} else {
37+
core.exportVariable('IS_MUSIC_ISSUE', 'false');
38+
}
3739
3840
- name: Stop if not a music issue
3941
if: env.IS_MUSIC_ISSUE == 'false'
@@ -56,17 +58,39 @@ jobs:
5658
- name: Display YouTube link check result
5759
if: env.IS_MUSIC_ISSUE == 'true'
5860
run: |
59-
echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
61+
echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
6062
6163
- name: Escape issue body for JSON
6264
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
6365
uses: actions/github-script@v7
6466
with:
6567
script: |
66-
const markdownJson = require('markdown-json');
67-
const issueBody = context.payload.issue.body;
68-
const escapedIssueBody = markdownJson.parse(issueBody);
69-
core.exportVariable('ESCAPED_ISSUE_BODY', JSON.stringify(escapedIssueBody));
68+
const core = require('@actions/core');
69+
const github = require('@actions/github');
70+
const marked = require('marked');
71+
const DOMPurify = require('dompurify')(new (require('jsdom').JSDOM)().window);
72+
const { JSDOM } = require('jsdom');
73+
74+
function markdownToJsonSafeString(markdownContent) {
75+
// Convert markdown to HTML
76+
const htmlContent = marked.parse(markdownContent);
77+
78+
// Sanitize the HTML content
79+
const sanitizedHtmlContent = DOMPurify.sanitize(htmlContent);
80+
81+
// Use jsdom to create a temporary DOM element to extract text content from sanitized HTML
82+
const dom = new JSDOM(sanitizedHtmlContent);
83+
const textContent = dom.window.document.body.textContent || '';
84+
85+
// Ensure the text content is JSON-safe
86+
const jsonSafeString = JSON.stringify(textContent);
87+
88+
return jsonSafeString;
89+
}
90+
91+
const issueBody = github.context.payload.issue.body;
92+
const escapedIssueBody = markdownToJsonSafeString(issueBody);
93+
core.exportVariable('ESCAPED_ISSUE_BODY', escapedIssueBody);
7094

7195
- name: Extract and display YouTube ID if link is found
7296
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
@@ -91,10 +115,12 @@ jobs:
91115
- name: Post comment to issue
92116
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
93117
uses: actions/github-script@v7
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94120
with:
95121
script: |
96122
const { GROQ_OUTPUT } = process.env;
97-
const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN'));
123+
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
98124
const issue_number = context.issue.number;
99125
const repo = context.repo.repo;
100126
const owner = context.repo.owner;
@@ -103,5 +129,5 @@ jobs:
103129
owner,
104130
repo,
105131
issue_number,
106-
body: `Here is the processed information:\n\n\`\`\`bash\n${GROQ_OUTPUT}\n\`\`\``
132+
body: `Here is the JSON processed information:\n\n\`\`\`json\n${GROQ_OUTPUT}\n\`\`\``
107133
});

0 commit comments

Comments
 (0)