diff --git a/README.md b/README.md index b54d251..718be2c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 19be62b..0f32607 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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, }, }, }; diff --git a/index.js b/index.js index 5a00b2b..9f404ee 100644 --- a/index.js +++ b/index.js @@ -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, }, }, };