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: summarization and interaction 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'; | |
async function run() { | |
if (commentBody.startsWith(prefix)) { | |
let restCommentBody = commentBody.replace(prefix, '').trim(); | |
let actions = ['recommend', 'summarize', 'interact']; | |
let models = ['triagerx', 'chatgpt', 'gemini']; | |
let action = null; | |
let model = null; | |
actions.forEach(keyword => { | |
if (!action && restCommentBody.includes(`/${keyword}`)) { | |
restCommentBody = restCommentBody.replace(`/${keyword}`, '').trim(); | |
action = keyword; | |
} | |
}); | |
models.forEach(keyword => { | |
if (!model && restCommentBody.includes(`-${keyword}`)) { | |
restCommentBody = restCommentBody.replace(`-${keyword}`, '').trim(); | |
model = keyword; | |
} | |
}); | |
if (action == null || model == null) { | |
console.log("Action or model is missing."); | |
return; | |
} | |
// 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]; | |
const { data: issueData } = await github.issues.get({ | |
issue_number: issueNumber, | |
owner: issueOwner, | |
repo: issueRepo | |
}); | |
let input = { | |
"issueData": issueData, | |
"commentsData" : [], | |
"model" : model, | |
"action" : action, | |
"userComment" : restCommentBody | |
} | |
if (action == 'interact') { | |
const commentsUrl = issueData.comments_url; | |
const { data: commentsData } = await github.request(commentsUrl); | |
input['commentsData'] = commentsData; | |
} | |
const apiUrl = 'https://tigersdemo.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 | |
}); | |
} | |
} | |
run(); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |