Summarizer and Interactor in GitHub Actions π #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: sum+inter workflow | |
run-name: Summarizer and Interactor in GitHub Actions π | |
on: [issue_comment] | |
jobs: | |
issue_commented: | |
name: Issue comment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
run: npm install axios | |
- name: Commenting on the issue | |
id: comment | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const axios = require('axios'); | |
const commentBody = context.payload.comment.body; | |
const prefix = 'TriagerX'; | |
if (commentBody.startsWith(prefix)) { | |
let restCommentBody = commentBody.replace(prefix, '').trim(); | |
let action = '' | |
let model = '' | |
if (commentBody.includes('/summarize')){ | |
restCommentBody = restCommentBody.replace('/summarize', '').trim(); | |
action = 'summarize' | |
} else if (commentBody.includes('/interact')){ | |
restCommentBody = restCommentBody.replace('/interact', '').trim(); | |
action = 'interact' | |
} | |
if (commentBody.includes('-chatgpt')){ | |
restCommentBody = restCommentBody.replace('-chatgpt', '').trim(); | |
model = 'chatgpt' | |
} else if (commentBody.includes('-gemini')){ | |
restCommentBody = restCommentBody.replace('-gemini', '').trim(); | |
model = 'gemini' | |
} | |
let input = { | |
"issueData": {}, | |
"commentsData" : [], | |
"model" : model, | |
"action" : action, | |
"userComment" : restCommentBody | |
} | |
// TriagerX /summarize -chatgpt https://github.com/eclipse-openj9/openj9/issues/19576 | |
// TriagerX /interact -gemini How are you? | |
let issueUrl = commentBody.includes('https') ? restCommentBody.trim() : context.payload.issue.html_url; | |
let issueNumber = issueUrl.split('/').pop(); | |
let issueOwner = issueUrl.split('/')[3]; | |
let issueRepo = issueUrl.split('/')[4]; | |
console.log(issueUrl); | |
console.log(issueNumber); | |
console.log(issueOwner); | |
console.log(issueRepo); | |
const { data: issueData } = await github.issues.get({ | |
issue_number: issueNumber, | |
owner: issueOwner, | |
repo: issueRepo | |
}); | |
input['issueData'] = issueData; | |
if (action == 'interact') { | |
const commentsUrl = issueData.comments_url; | |
const { data: commentsData } = await github.request(commentsUrl); | |
input['commentsData'] = commentsData; | |
console.log("COMMENTSDATA:", commentsData) | |
} | |
input['commentsData'] = [ | |
{ | |
"user": { | |
"login": "abc" | |
}, | |
"body": "new text" | |
}, | |
{ | |
"user": { | |
"login": "cba" | |
}, | |
"body": "example text" | |
} | |
] | |
const apiUrl = 'https://jolly-rock-6ec1c558f46f43d1b565a4283867da28.azurewebsites.net/process'; | |
const response = await axios.post(apiUrl, JSON.stringify(input), { | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}); | |
let newCommentBody = response.data['response']; | |
console.log('newCommentBody: ', newCommentBody) | |
await github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: newCommentBody | |
}); | |
} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |