init
This commit is contained in:
47
api/gitea.js
Normal file
47
api/gitea.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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 }
|
Reference in New Issue
Block a user