-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (174 loc) · 8.85 KB
/
i-music-process.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Process Music Issues
on:
issues:
types: [opened]
permissions:
issues: write
contents: read
jobs:
process_issue:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: |
npm install marked dompurify jsdom axios
- name: Check if issue title contains [MUSIC]
uses: actions/github-script@v7
with:
script: |
const issueTitle = context.payload.issue.title;
if (issueTitle.includes("[MUSIC]")) {
core.exportVariable('IS_MUSIC_ISSUE', 'true');
} else {
core.exportVariable('IS_MUSIC_ISSUE', 'false');
}
- name: Stop if not a music issue
if: env.IS_MUSIC_ISSUE == 'false'
run: echo "Not a music issue. Skipping further steps."
- name: Check for YouTube link in issue body
if: env.IS_MUSIC_ISSUE == 'true'
uses: actions/github-script@v7
with:
script: |
const issueBody = context.payload.issue.body;
const youtubeLink = issueBody.match(/https:\/\/www.youtube.com\/watch\?v=([\w-]+)/);
if (youtubeLink) {
core.exportVariable('HAS_YOUTUBE_LINK', 'true');
core.exportVariable('YOUTUBE_ID', youtubeLink[1]);
} else {
core.exportVariable('HAS_YOUTUBE_LINK', 'false');
}
- name: Display YouTube link check result
if: env.IS_MUSIC_ISSUE == 'true'
run: |
echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
- name: Escape issue body for JSON
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
uses: actions/github-script@v7
with:
script: |
const marked = require('marked');
const DOMPurify = require('dompurify')(new (require('jsdom').JSDOM)().window);
const { JSDOM } = require('jsdom');
function markdownToJsonSafeString(markdownContent) {
// Convert markdown to HTML
const htmlContent = marked.parse(markdownContent);
// Sanitize the HTML content
const sanitizedHtmlContent = DOMPurify.sanitize(htmlContent);
// Use jsdom to create a temporary DOM element to extract text content from sanitized HTML
const dom = new JSDOM(sanitizedHtmlContent);
const textContent = dom.window.document.body.textContent || '';
// Ensure the text content is JSON-safe
const jsonSafeString = JSON.stringify(textContent);
return jsonSafeString;
}
const issueBody = context.payload.issue.body;
const escapedIssueBody = markdownToJsonSafeString(issueBody);
core.exportVariable('ESCAPED_ISSUE_BODY', escapedIssueBody);
- name: Extract and display YouTube ID if link is found
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
uses: actions/github-script@v7
with:
script: |
const { YOUTUBE_ID, ESCAPED_ISSUE_BODY } = process.env;
const system = `Imagine three different data experts are answering this task. All experts will write down their steps of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realizes they're wrong at any point then they leave. Remember the goal is to complete all of the steps provided and generate the final command. \n\n Please read the provided text, extract the required information, sanitize the title, and fill it into the specified command format. The title should only contain numbers, letters, spaces, hyphens, and characters (, ), ., and -. Your task is to complete a finalized kbve.sh shell command with the extracted information. If you can not complete the command, go back and process the input data again. \n\n Hint: Titles may contain multiple words separated by quotes and hyphens. These words are often the band name and followed by the song. **Example:**\n\`\`\`\n\n**Fill out the Form**\n\nYouTube Link: https://www.youtube.com/watch?v=<yt_id>\nTitle: <title> \nGenre: <genre>\n\nPick only one of the different genres!\ndnb, chillstep, lofihiphop, nujazz, electroswing, edm, rock, japrock\n\n\n\`\`\`\n\n**Output:**\n\n\`\`\`bash\n./kbve.sh -nx kbve.com:music --args=\\\"--file=<genre>--title='<title>' --ytid=<yt_id>\\\"\"\n\nHere is the template for the command:\n\`\`\`\n./kbve.sh -nx kbve.com:music --args=\\\"--file=[insert file/genre here] --title='[insert sanitized title here]' --ytid=[insert YouTube ID here]\\\"\n\nEnsure to:\n1. Extract the \`File/Genre\`, \`Title\`, and \`YouTube ID\` from the text.\n2. Sanitize the \`Title\` to only include numbers, letters, spaces, hyphens, quotes, periods, the characters () . and -. Please do not replace spaces with any other characters and keep the spaces in the sanitized title.\n3. Only acceptable genres/file are dnb, chillstep, lofihiphop, nujazz, electroswing, edm, rock, japrock\n4. Fill in the command template with the extracted and sanitized values.\n\n**Your Task:**\nPlease parse the provided text below and generate the command. You must follow all the steps that are stated and make sure to wrap the kbve.sh command in bash code block. \n\n`;
const message = ESCAPED_ISSUE_BODY;
const payload = JSON.stringify({
system,
message,
model: "mixtral-8x7b-32768"
});
const axios = require('axios');
const response = await axios.post('https://rust.kbve.com/api/v1/call_groq', payload, {
headers: {
'Content-Type': 'application/json'
}
});
core.exportVariable('GROQ_OUTPUT', response.data);
- name: Post debug comment to issue
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { GROQ_OUTPUT } = process.env;
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `Here is the JSON processed information:\n\n\`\`\`json\n${GROQ_OUTPUT}\n\`\`\``
});
- name: Post shell command to issue
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { GROQ_OUTPUT } = process.env;
const output = JSON.parse(GROQ_OUTPUT);
const messageContent = output.choices[0].message.content;
const shellCommandMatch = messageContent.match(/```bash\n([\s\S]*?)\n```/);
const shellCommand = shellCommandMatch ? shellCommandMatch[1] : 'No shell command found';
if (shellCommandMatch) {
core.exportVariable('HAS_SHELL_COMMAND', 'true');
}
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `Here is the message:\n${messageContent}\nHere is the shell command extracted from the message:\n\n\`\`\`bash\n${shellCommand}\n\`\`\``
});
- name: Update issue labels and comment
if: env.HAS_SHELL_COMMAND == 'true'
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { GITHUB_TOKEN } = process.env;
const issue_number = context.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
// Get current labels
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number,
});
// Remove label "0" if it exists
if (labels.some(label => label.name === '0')) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: '0'
});
}
// Add label "1"
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ['1']
});
// Add a comment
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: "The shell command has been identified and labels have been updated."
});