fix: upgrade issues bot to use agent graph #5

Merged
drgroot merged 1 commits from f into main 2026-01-02 03:49:59 +00:00
3 changed files with 591 additions and 549 deletions
Showing only changes of commit c1de36a15a - Show all commits

View File

@@ -3,14 +3,14 @@ description: 'Sends a coding automation task to coding bot'
inputs:
api_url:
description: 'api url'
default: 'http://agents-automation-api.agents:3000'
default: 'http://agents-api.servc-nonprod:3000'
required: false
api_token:
description: 'API token for authentication'
default: ''
required: false
bot_route:
default: 'codebot'
default: 'agent-bot'
required: false
debug:
description: 'Enable debug mode'

1057
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,13 +1,19 @@
const core = require('@actions/core');
const github = require('@actions/github');
const core = require("@actions/core");
const github = require("@actions/github");
const sanitizeTask = (text) => (text || '').replace(/@bot\b[:]?\s*/gi, '').trim();
const sanitizeTask = (text) =>
(text || "").replace(/@bot\b[:]?\s*/gi, "").trim();
async function fetchFirstIssueComment(repoFullName, issueNumber, githubToken, serverUrl) {
async function fetchFirstIssueComment(
repoFullName,
issueNumber,
githubToken,
serverUrl,
) {
if (!repoFullName || !issueNumber) return null;
const url = `${serverUrl}/api/v1/repos/${repoFullName}/issues/${issueNumber}/comments?limit=1`;
const headers = { Accept: 'application/vnd.github+json' };
const headers = { Accept: "application/vnd.github+json" };
if (githubToken) {
headers.Authorization = `Bearer ${githubToken}`;
@@ -16,7 +22,9 @@ async function fetchFirstIssueComment(repoFullName, issueNumber, githubToken, se
try {
const response = await fetch(url, { headers });
if (!response.ok) {
core.warning(`Failed to fetch issue comments (${response.status}): ${response.statusText}`);
core.warning(
`Failed to fetch issue comments (${response.status}): ${response.statusText}`,
);
return null;
}
@@ -31,14 +39,19 @@ async function fetchFirstIssueComment(repoFullName, issueNumber, githubToken, se
}
async function run() {
const apiUrl = core.getInput('api_url') || 'http://agents-automation-api.agents:3000';
const apiToken = core.getInput('api_token');
const botRoute = core.getInput('bot_route') || 'codebot';
const debug = (core.getInput('debug') || 'false').toLowerCase() === 'true';
const serverUrl = (process.env.GITHUB_SERVER_URL || github.context.serverUrl || 'https://git.yusufali.ca').replace(/\/$/, '');
const apiUrl =
core.getInput("api_url") || "http://agents-api.servc-nonprod:3000";
const apiToken = core.getInput("api_token");
const botRoute = core.getInput("bot_route") || "agent-bot";
const debug = (core.getInput("debug") || "false").toLowerCase() === "true";
const serverUrl = (
process.env.GITHUB_SERVER_URL ||
github.context.serverUrl ||
"https://git.yusufali.ca"
).replace(/\/$/, "");
const payload = github.context.payload;
const commentBody = payload?.comment?.body || '';
const commentBody = payload?.comment?.body || "";
const issueNumber = payload?.issue?.number;
const repoName = payload?.repository?.full_name;
const repoUrl = payload?.repository?.clone_url;
@@ -46,42 +59,48 @@ async function run() {
if (!commentBody) {
if (!debug) {
core.setFailed('No comment body found in the event payload');
core.setFailed("No comment body found in the event payload");
return;
}
core.info('No comment body found in the event payload, continuing because debug is enabled');
core.info(
"No comment body found in the event payload, continuing because debug is enabled",
);
}
let task =
(await fetchFirstIssueComment(repoName, issueNumber, githubToken, serverUrl)) ||
sanitizeTask(commentBody);
(await fetchFirstIssueComment(
repoName,
issueNumber,
githubToken,
serverUrl,
)) || sanitizeTask(commentBody);
if (!task) {
if (!debug) {
core.setFailed('Unable to determine the task to send to the agent');
core.setFailed("Unable to determine the task to send to the agent");
return;
}
core.info('Unable to determine the task, using debug placeholder');
task = '[debug] empty task';
core.info("Unable to determine the task, using debug placeholder");
task = "[debug] empty task";
}
const requestPayload = {
type: 'input',
type: "input",
route: botRoute,
argumentId: 'plain',
argumentId: "plain",
force: true,
instanceId: null,
inputs: {
method: 'run_task',
method: "start",
inputs: {
repo_name: repoName,
repo_url: repoUrl,
issue_number: String(issueNumber),
task
}
}
task,
},
},
};
if (debug) {
@@ -94,7 +113,7 @@ async function run() {
try {
const headers = {
'Content-Type': 'application/json'
"Content-Type": "application/json",
};
if (apiToken) {
@@ -102,15 +121,17 @@ async function run() {
}
const response = await fetch(apiUrl, {
method: 'POST',
method: "POST",
headers,
body: JSON.stringify(requestPayload)
body: JSON.stringify(requestPayload),
});
const responseText = await response.text();
if (!response.ok) {
core.setFailed(`Agent API request failed (${response.status}): ${responseText}`);
core.setFailed(
`Agent API request failed (${response.status}): ${responseText}`,
);
return;
}