47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
const { formatMessage } = require('./formatters')
|
|
|
|
/**
|
|
* Handle Gitea webhook
|
|
* @param {Object} payload - Gitea webhook payload
|
|
* @returns {Object} - Normalized webhook data
|
|
*/
|
|
const normalizeGiteaPayload = (payload) => ({
|
|
repository: {
|
|
full_name: payload.repository.full_name,
|
|
html_url: payload.repository.html_url || payload.repository.url
|
|
},
|
|
ref: payload.ref,
|
|
commits: payload.commits.map(commit => ({
|
|
id: commit.id,
|
|
message: commit.message,
|
|
stats: {
|
|
additions: commit.added?.length || 0,
|
|
deletions: commit.removed?.length || 0
|
|
}
|
|
}))
|
|
})
|
|
|
|
/**
|
|
* Handle Gitea webhook
|
|
* @param {Object} payload - Webhook payload
|
|
* @param {Set} reportedCommits - Set of reported commit hashes
|
|
* @param {Map} commitTimestamps - Map of commit timestamps
|
|
* @returns {Object} - Formatted message or null
|
|
*/
|
|
const handleGitea = (payload, reportedCommits, commitTimestamps) => {
|
|
const data = normalizeGiteaPayload(payload)
|
|
|
|
// Filter new commits
|
|
const newCommits = data.commits.filter(commit => {
|
|
if (reportedCommits.has(commit.id)) return false
|
|
reportedCommits.add(commit.id)
|
|
commitTimestamps.set(commit.id, Date.now())
|
|
return true
|
|
})
|
|
|
|
if (newCommits.length === 0) return null
|
|
|
|
return formatMessage(data, newCommits)
|
|
}
|
|
|
|
module.exports = { handleGitea }
|