diff --git a/src/content-script/site-adapters/gitlab/index.mjs b/src/content-script/site-adapters/gitlab/index.mjs index 25c6727..8b71a1b 100644 --- a/src/content-script/site-adapters/gitlab/index.mjs +++ b/src/content-script/site-adapters/gitlab/index.mjs @@ -18,14 +18,24 @@ const getPatchData = async (patchUrl) => { export default { inputQuery: async () => { try { - const patchUrl = await getPatchUrl() - const patchData = await getPatchData(patchUrl) - if (!patchData) return + if (location.pathname.includes('/blob')) { + const fileData = await limitedFetch(location.href.replace('/blob/', '/raw/'), 1024 * 40) + if (!fileData) return - return await cropText( - `Analyze the contents of a git commit,provide a suitable commit message,and summarize the contents of the commit.` + - `The patch contents of this commit are as follows:\n${patchData}`, - ) + return await cropText( + `Analyze the following file content and explain it. Use markdown syntax to make your answer more readable, such as code blocks, bold, list:` + + `\n\`\`\`\n${fileData}\n\`\`\``, + ) + } else { + const patchUrl = await getPatchUrl() + const patchData = await getPatchData(patchUrl) + if (!patchData) return + + return await cropText( + `Analyze the contents of a git commit,provide a suitable commit message,and summarize the contents of the commit.` + + `The patch contents of this commit are as follows:\n${patchData}`, + ) + } } catch (e) { console.log(e) }