Skip to content

Commit

Permalink
feat: git patch summary for gitlab commit
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 12, 2023
1 parent b751f7e commit ba99239
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/content-script/site-adapters/gitlab/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { cropText } from '../../../utils/crop-text.mjs'
import { limitedFetch } from '../../../utils/limited-fetch.mjs'

const getPatchUrl = async () => {
const patchUrl = location.origin + location.pathname + '.patch'
const response = await fetch(patchUrl, { method: 'HEAD' })
if (response.ok) return patchUrl
return ''
}

const getPatchData = async (patchUrl) => {
if (!patchUrl) return

let patchData = await limitedFetch(patchUrl, 1024 * 40)
patchData = patchData.substring(patchData.indexOf('---'))
return patchData
}

export default {
inputQuery: async () => {
try {
const patchUrl = await getPatchUrl()
const patchData = await getPatchData(patchUrl)
if (!patchData) return

return 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)
}
},
}

0 comments on commit ba99239

Please sign in to comment.