Merge pull request 'fix: first needs to be issue body' (#4) from f into main
All checks were successful
Markdown Embedder / agent-embed-markdown (push) Successful in 3s

Reviewed-on: #4
This commit is contained in:
2026-01-10 05:32:10 +00:00
3 changed files with 72 additions and 8 deletions

View File

@@ -4,8 +4,8 @@ Sends issue comment text to an embeddings API so issue discussions can be stored
## How it works
- Reads issue comments via the GitHub API.
- Builds a request payload using the first comment for `embed_text` and the latest comment for `store_text`.
- Reads issue body and comments via the GitHub API.
- Builds a request payload using the issue body for `embed_text` and the latest comment for `store_text`.
- POSTs the payload to the configured API URL with optional token auth.
## Inputs

38
dist/index.js vendored
View File

@@ -32900,6 +32900,35 @@ async function issueComments() {
}
}
async function issueBody() {
if (!repoFullName || !issueNumber) return null;
const url = `${serverUrl}/api/v1/repos/${repoFullName}/issues/${issueNumber}`;
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 body (${response.status}): ${response.statusText}`,
);
return null;
}
const issue = await response.json();
if (!issue?.body) return null;
return String(issue.body);
} catch (error) {
core.warning(`Error fetching issue body: ${error}`);
return null;
}
}
const headers = {
"Content-Type": "application/json",
};
@@ -32920,7 +32949,7 @@ async function run() {
);
}
const comments = await issueComments();
const [body, comments] = await Promise.all([issueBody(), issueComments()]);
if (!comments || comments.length < 1) {
if (!debug) {
core.setFailed("Unable to determine the task to send to the agent");
@@ -32931,6 +32960,9 @@ async function run() {
task = "[debug] empty task";
}
const embedText = body ? body.trim() : String(comments[0]).trim();
const storeText = String(comments[comments.length - 1]).trim();
const requestPayload = {
type: "input",
route,
@@ -32942,8 +32974,8 @@ async function run() {
inputs: {
segment_id,
document_id,
embed_text: String(comments[0]).trim(),
store_text: String(comments[comments.length - 1]).trim(),
embed_text: embedText,
store_text: storeText,
},
},
};

View File

@@ -68,6 +68,35 @@ async function issueComments() {
}
}
async function issueBody() {
if (!repoFullName || !issueNumber) return null;
const url = `${serverUrl}/api/v1/repos/${repoFullName}/issues/${issueNumber}`;
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 body (${response.status}): ${response.statusText}`,
);
return null;
}
const issue = await response.json();
if (!issue?.body) return null;
return String(issue.body);
} catch (error) {
core.warning(`Error fetching issue body: ${error}`);
return null;
}
}
const headers = {
"Content-Type": "application/json",
};
@@ -88,7 +117,7 @@ async function run() {
);
}
const comments = await issueComments();
const [body, comments] = await Promise.all([issueBody(), issueComments()]);
if (!comments || comments.length < 1) {
if (!debug) {
core.setFailed("Unable to determine the task to send to the agent");
@@ -99,6 +128,9 @@ async function run() {
task = "[debug] empty task";
}
const embedText = body ? body.trim() : String(comments[0]).trim();
const storeText = String(comments[comments.length - 1]).trim();
const requestPayload = {
type: "input",
route,
@@ -110,8 +142,8 @@ async function run() {
inputs: {
segment_id,
document_id,
embed_text: String(comments[0]).trim(),
store_text: String(comments[comments.length - 1]).trim(),
embed_text: embedText,
store_text: storeText,
},
},
};