Skip to content

Summarizer and Interactor in GitHub Actions #69

Summarizer and Interactor in GitHub Actions

Summarizer and Interactor in GitHub Actions #69

Workflow file for this run

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 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'
}
if (action == '' || model == '') {
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 }}