Skip to content

Commit 6d9ad49

Browse files
authored
Update i-music-process.yml
1 parent ad10fd9 commit 6d9ad49

File tree

1 file changed

+74
-20
lines changed

1 file changed

+74
-20
lines changed

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

+74-20
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,91 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19+
- name: Setup Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '14'
23+
24+
- name: Install markdown-json
25+
run: npm install markdown-json
26+
1927
- name: Check if issue title contains [MUSIC]
20-
run: ./scripts/check_title.sh "${{ github.event.issue.title }}"
28+
uses: actions/github-script@v7
29+
with:
30+
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+
}
2137
2238
- name: Stop if not a music issue
23-
if: env.is_music_issue == 'false'
39+
if: env.IS_MUSIC_ISSUE == 'false'
2440
run: echo "Not a music issue. Skipping further steps."
2541

2642
- name: Check for YouTube link in issue body
27-
if: env.is_music_issue == 'true'
28-
run: ./scripts/check_youtube.sh "${{ github.event.issue.body }}"
43+
if: env.IS_MUSIC_ISSUE == 'true'
44+
uses: actions/github-script@v7
45+
with:
46+
script: |
47+
const issueBody = context.payload.issue.body;
48+
const youtubeLink = issueBody.match(/https:\/\/www.youtube.com\/watch\?v=([\w-]+)/);
49+
if (youtubeLink) {
50+
core.exportVariable('HAS_YOUTUBE_LINK', 'true');
51+
core.exportVariable('YOUTUBE_ID', youtubeLink[1]);
52+
} else {
53+
core.exportVariable('HAS_YOUTUBE_LINK', 'false');
54+
}
2955
3056
- name: Display YouTube link check result
31-
if: env.is_music_issue == 'true'
32-
run: echo "Contains YouTube link: ${{ env.has_youtube_link }}"
57+
if: env.IS_MUSIC_ISSUE == 'true'
58+
run: echo "Contains YouTube link: ${{ env.HAS_YOUTUBE_LINK }}"
3359

3460
- name: Escape issue body for JSON
35-
if: env.has_youtube_link == 'true' && env.is_music_issue == 'true'
36-
run: ./scripts/escape_issue_body.sh "${{ github.event.issue.body }}"
61+
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
62+
uses: actions/github-script@v7
63+
with:
64+
script: |
65+
const markdownJson = require('markdown-json');
66+
const issueBody = context.payload.issue.body;
67+
const escapedIssueBody = markdownJson.parse(issueBody);
68+
core.exportVariable('ESCAPED_ISSUE_BODY', JSON.stringify(escapedIssueBody));
3769
3870
- name: Extract and display YouTube ID if link is found
39-
if: env.has_youtube_link == 'true' && env.is_music_issue == 'true'
40-
run: ./scripts/send_payload.sh "${{ env.youtube_id }}" "${{ env.escaped_issue_body }}"
71+
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
72+
uses: actions/github-script@v7
73+
with:
74+
script: |
75+
const { YOUTUBE_ID, ESCAPED_ISSUE_BODY } = process.env;
76+
const message = `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, and the characters () . and -.\n\n**Input:**\n\`\`\`\n\n**Fill out the Form**\n\nYouTube Link: https://www.youtube.com/watch?v=${YOUTUBE_ID}\nTitle: Hippie Sabotage - The Best of Chill Music (Mix)\nGenre: lofihiphop\n\n## Human\n\nFor supported genres, please visit [Music](https://kbve.com/music/)\nPick only one of the different genres!\ndnb, chillstep, lofihiphop, nujazz, electroswing, edm, rock\n\n\n\`\`\`\n\n**Output:**\n\n\`\`\`bash\n./kbve.sh -nx kbve.com:music --args=\\\"--file=lofihiphop --title='Hippie Sabotage - The Best of Chill Music (Mix)' --ytid=${YOUTUBE_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, and the characters () . and -.\n3. Only acceptable genres/file are dnb, chillstep, lofihiphop, nujazz, electroswing, edm, rock\n4. Fill in the command template with the extracted and sanitized values.\n\n**Example Input:**\n\`\`\`text\nFile/Genre: jazz\nTitle: Louis Armstrong - What a Wonderful World (Jazz Remix)\nYouTube ID: abc12345\`\`\`\n\n**Example Output:**\n\`\`\`bash\n./kbve.sh -nx kbve.com:music --args=\\\"--file=jazz --title='Louis Armstrong - What a Wonderful World (Jazz Remix)' --ytid=abc12345\\\"\"\n\n**Your Task:**\nPlease parse the provided text below and generate the command.\n\n**Input:**\n${ESCAPED_ISSUE_BODY}\n\n**Output:**\n\`\`\`bash\n\`\`\``
77+
const payload = JSON.stringify({
78+
message,
79+
model: "llama3-8b-8192"
80+
});
81+
82+
const axios = require('axios');
83+
const response = await axios.post('https://rust.kbve.com/api/v1/call_groq', payload, {
84+
headers: {
85+
'Content-Type': 'application/json'
86+
}
87+
});
88+
core.exportVariable('GROQ_OUTPUT', response.data);
4189
4290
- name: Post comment to issue
43-
if: env.has_youtube_link == 'true' && env.is_music_issue == 'true'
44-
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
GROQ_OUTPUT: ${{ env.groq_output }}
47-
run: |
48-
COMMENT_BODY_SANITIZED=$(echo "$GROQ_OUTPUT" | sed 's/"/\\"/g')
49-
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
50-
-H "Content-Type: application/json" \
51-
-d "{\"body\": \"Here is the processed information:\\n\\n\`\`\`bash\\n$COMMENT_BODY_SANITIZED\\n\`\`\`\"}" \
52-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments"
91+
if: env.HAS_YOUTUBE_LINK == 'true' && env.IS_MUSIC_ISSUE == 'true'
92+
uses: actions/github-script@v7
93+
with:
94+
script: |
95+
const { GROQ_OUTPUT } = process.env;
96+
const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN'));
97+
const issue_number = context.issue.number;
98+
const repo = context.repo.repo;
99+
const owner = context.repo.owner;
100+
101+
await octokit.rest.issues.createComment({
102+
owner,
103+
repo,
104+
issue_number,
105+
body: `Here is the processed information:\n\n\`\`\`bash\n${GROQ_OUTPUT}\n\`\`\``
106+
});

0 commit comments

Comments
 (0)