@@ -16,24 +16,26 @@ jobs:
16
16
- name : Checkout repository
17
17
uses : actions/checkout@v3
18
18
19
- - name : Setup Node.js
19
+
20
+ - name : Set up Node.js
20
21
uses : actions/setup-node@v3
21
22
with :
22
23
node-version : ' 20'
23
24
24
- - name : Install markdown-json
25
- run : npm install markdown-json
25
+ - name : Install dependencies
26
+ run : |
27
+ npm install marked dompurify jsdom
26
28
27
29
- name : Check if issue title contains [MUSIC]
28
30
uses : actions/github-script@v7
29
31
with :
30
32
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
+ }
37
39
38
40
- name : Stop if not a music issue
39
41
if : env.IS_MUSIC_ISSUE == 'false'
@@ -56,17 +58,39 @@ jobs:
56
58
- name : Display YouTube link check result
57
59
if : env.IS_MUSIC_ISSUE == 'true'
58
60
run : |
59
- echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
61
+ echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
60
62
61
63
- name : Escape issue body for JSON
62
64
if : env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
63
65
uses : actions/github-script@v7
64
66
with :
65
67
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);
70
94
71
95
- name : Extract and display YouTube ID if link is found
72
96
if : env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
@@ -91,10 +115,12 @@ jobs:
91
115
- name : Post comment to issue
92
116
if : env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
93
117
uses : actions/github-script@v7
118
+ env :
119
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
94
120
with :
95
121
script : |
96
122
const { GROQ_OUTPUT } = process.env;
97
- const octokit = github.getOctokit(core.getInput(' GITHUB_TOKEN') );
123
+ const octokit = github.getOctokit(process.env. GITHUB_TOKEN);
98
124
const issue_number = context.issue.number;
99
125
const repo = context.repo.repo;
100
126
const owner = context.repo.owner;
@@ -103,5 +129,5 @@ jobs:
103
129
owner,
104
130
repo,
105
131
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\`\`\``
107
133
});
0 commit comments