This commit is contained in:
176
dist/index.js
vendored
Normal file
176
dist/index.js
vendored
Normal file
@@ -0,0 +1,176 @@
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
/***/ 495:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = eval("require")("@actions/core");
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 99:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = eval("require")("@actions/github");
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __nccwpck_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ var threw = true;
|
||||
/******/ try {
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
|
||||
/******/ threw = false;
|
||||
/******/ } finally {
|
||||
/******/ if(threw) delete __webpack_module_cache__[moduleId];
|
||||
/******/ }
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/compat */
|
||||
/******/
|
||||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
|
||||
/******/
|
||||
/************************************************************************/
|
||||
var __webpack_exports__ = {};
|
||||
const core = __nccwpck_require__(495);
|
||||
const github = __nccwpck_require__(99);
|
||||
|
||||
const sanitizeTask = (text) => (text || '').replace(/@bot\b[:]?\s*/gi, '').trim();
|
||||
|
||||
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' };
|
||||
|
||||
if (githubToken) {
|
||||
headers.Authorization = `Bearer ${githubToken}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { headers });
|
||||
if (!response.ok) {
|
||||
core.warning(`Failed to fetch issue comments (${response.status}): ${response.statusText}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const comments = await response.json();
|
||||
if (!Array.isArray(comments) || comments.length === 0) return null;
|
||||
|
||||
return sanitizeTask(comments[0]?.body);
|
||||
} catch (error) {
|
||||
core.warning(`Error fetching issue comments: ${error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const apiUrl = core.getInput('api_url') || 'https://api.servc.io';
|
||||
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 payload = github.context.payload;
|
||||
const commentBody = payload?.comment?.body || '';
|
||||
const issueNumber = payload?.issue?.number;
|
||||
const repoName = payload?.repository?.full_name;
|
||||
const repoUrl = payload?.repository?.clone_url;
|
||||
const githubToken = process.env.GITHUB_TOKEN;
|
||||
|
||||
if (!commentBody) {
|
||||
core.setFailed('No comment body found in the event payload');
|
||||
return;
|
||||
}
|
||||
|
||||
const task =
|
||||
(await fetchFirstIssueComment(repoName, issueNumber, githubToken, serverUrl)) ||
|
||||
sanitizeTask(commentBody);
|
||||
|
||||
if (!task) {
|
||||
core.setFailed('Unable to determine the task to send to the agent');
|
||||
return;
|
||||
}
|
||||
|
||||
const requestPayload = {
|
||||
type: 'input',
|
||||
route: botRoute,
|
||||
argumentId: 'plain',
|
||||
force: true,
|
||||
instanceId: null,
|
||||
inputs: {
|
||||
method: 'run_task',
|
||||
inputs: {
|
||||
repo_name: repoName,
|
||||
repo_url: repoUrl,
|
||||
issue_number: String(issueNumber),
|
||||
task
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (debug) {
|
||||
core.info(`API URL: ${apiUrl}`);
|
||||
core.info(`Route: ${botRoute}`);
|
||||
core.info(`Server URL: ${serverUrl}`);
|
||||
core.info(`Using auth: ${Boolean(apiToken)}`);
|
||||
core.info(`Request payload: ${JSON.stringify(requestPayload)}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
if (apiToken) {
|
||||
headers.Apitoken = apiToken;
|
||||
}
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(requestPayload)
|
||||
});
|
||||
|
||||
const responseText = await response.text();
|
||||
|
||||
if (!response.ok) {
|
||||
core.setFailed(`Agent API request failed (${response.status}): ${responseText}`);
|
||||
return;
|
||||
}
|
||||
|
||||
core.info(`Agent response: ${responseText}`);
|
||||
} catch (error) {
|
||||
core.setFailed(`Error sending task to agent: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
module.exports = __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
||||
Reference in New Issue
Block a user