fix: upgrade issues bot to use agent graph
All checks were successful
Dependabot Auto-Merge / dependabot (pull_request) Has been skipped
COMMIT LINT / commitlint (pull_request) Successful in 26s
Dependabot Auto-Merge / devopsbot (pull_request) Has been skipped
Dependabot Auto-Merge / rennovatebot (pull_request) Has been skipped
Unit Tests / unittest (pull_request) Successful in 3s
All checks were successful
Dependabot Auto-Merge / dependabot (pull_request) Has been skipped
COMMIT LINT / commitlint (pull_request) Successful in 26s
Dependabot Auto-Merge / devopsbot (pull_request) Has been skipped
Dependabot Auto-Merge / rennovatebot (pull_request) Has been skipped
Unit Tests / unittest (pull_request) Successful in 3s
This commit is contained in:
@@ -3,14 +3,14 @@ description: 'Sends a coding automation task to coding bot'
|
|||||||
inputs:
|
inputs:
|
||||||
api_url:
|
api_url:
|
||||||
description: 'api url'
|
description: 'api url'
|
||||||
default: 'http://agents-automation-api.agents:3000'
|
default: 'http://agents-api.servc-nonprod:3000'
|
||||||
required: false
|
required: false
|
||||||
api_token:
|
api_token:
|
||||||
description: 'API token for authentication'
|
description: 'API token for authentication'
|
||||||
default: ''
|
default: ''
|
||||||
required: false
|
required: false
|
||||||
bot_route:
|
bot_route:
|
||||||
default: 'codebot'
|
default: 'agent-bot'
|
||||||
required: false
|
required: false
|
||||||
debug:
|
debug:
|
||||||
description: 'Enable debug mode'
|
description: 'Enable debug mode'
|
||||||
|
|||||||
1057
dist/index.js
vendored
1057
dist/index.js
vendored
File diff suppressed because one or more lines are too long
79
index.js
79
index.js
@@ -1,13 +1,19 @@
|
|||||||
const core = require('@actions/core');
|
const core = require("@actions/core");
|
||||||
const github = require('@actions/github');
|
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;
|
if (!repoFullName || !issueNumber) return null;
|
||||||
|
|
||||||
const url = `${serverUrl}/api/v1/repos/${repoFullName}/issues/${issueNumber}/comments?limit=1`;
|
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) {
|
if (githubToken) {
|
||||||
headers.Authorization = `Bearer ${githubToken}`;
|
headers.Authorization = `Bearer ${githubToken}`;
|
||||||
@@ -16,7 +22,9 @@ async function fetchFirstIssueComment(repoFullName, issueNumber, githubToken, se
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(url, { headers });
|
const response = await fetch(url, { headers });
|
||||||
if (!response.ok) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,14 +39,19 @@ async function fetchFirstIssueComment(repoFullName, issueNumber, githubToken, se
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const apiUrl = core.getInput('api_url') || 'http://agents-automation-api.agents:3000';
|
const apiUrl =
|
||||||
const apiToken = core.getInput('api_token');
|
core.getInput("api_url") || "http://agents-api.servc-nonprod:3000";
|
||||||
const botRoute = core.getInput('bot_route') || 'codebot';
|
const apiToken = core.getInput("api_token");
|
||||||
const debug = (core.getInput('debug') || 'false').toLowerCase() === 'true';
|
const botRoute = core.getInput("bot_route") || "agent-bot";
|
||||||
const serverUrl = (process.env.GITHUB_SERVER_URL || github.context.serverUrl || 'https://git.yusufali.ca').replace(/\/$/, '');
|
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 payload = github.context.payload;
|
||||||
const commentBody = payload?.comment?.body || '';
|
const commentBody = payload?.comment?.body || "";
|
||||||
const issueNumber = payload?.issue?.number;
|
const issueNumber = payload?.issue?.number;
|
||||||
const repoName = payload?.repository?.full_name;
|
const repoName = payload?.repository?.full_name;
|
||||||
const repoUrl = payload?.repository?.clone_url;
|
const repoUrl = payload?.repository?.clone_url;
|
||||||
@@ -46,42 +59,48 @@ async function run() {
|
|||||||
|
|
||||||
if (!commentBody) {
|
if (!commentBody) {
|
||||||
if (!debug) {
|
if (!debug) {
|
||||||
core.setFailed('No comment body found in the event payload');
|
core.setFailed("No comment body found in the event payload");
|
||||||
return;
|
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 =
|
let task =
|
||||||
(await fetchFirstIssueComment(repoName, issueNumber, githubToken, serverUrl)) ||
|
(await fetchFirstIssueComment(
|
||||||
sanitizeTask(commentBody);
|
repoName,
|
||||||
|
issueNumber,
|
||||||
|
githubToken,
|
||||||
|
serverUrl,
|
||||||
|
)) || sanitizeTask(commentBody);
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
if (!debug) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('Unable to determine the task, using debug placeholder');
|
core.info("Unable to determine the task, using debug placeholder");
|
||||||
task = '[debug] empty task';
|
task = "[debug] empty task";
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestPayload = {
|
const requestPayload = {
|
||||||
type: 'input',
|
type: "input",
|
||||||
route: botRoute,
|
route: botRoute,
|
||||||
argumentId: 'plain',
|
argumentId: "plain",
|
||||||
force: true,
|
force: true,
|
||||||
instanceId: null,
|
instanceId: null,
|
||||||
inputs: {
|
inputs: {
|
||||||
method: 'run_task',
|
method: "start",
|
||||||
inputs: {
|
inputs: {
|
||||||
repo_name: repoName,
|
repo_name: repoName,
|
||||||
repo_url: repoUrl,
|
repo_url: repoUrl,
|
||||||
issue_number: String(issueNumber),
|
issue_number: String(issueNumber),
|
||||||
task
|
task,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -94,7 +113,7 @@ async function run() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json'
|
"Content-Type": "application/json",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (apiToken) {
|
if (apiToken) {
|
||||||
@@ -102,15 +121,17 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(requestPayload)
|
body: JSON.stringify(requestPayload),
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseText = await response.text();
|
const responseText = await response.text();
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
core.setFailed(`Agent API request failed (${response.status}): ${responseText}`);
|
core.setFailed(
|
||||||
|
`Agent API request failed (${response.status}): ${responseText}`,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user