26 lines
558 B
Crystal
26 lines
558 B
Crystal
require "json"
|
|
|
|
class Payload
|
|
include JSON::Serializable
|
|
|
|
property kind : String
|
|
property content : String
|
|
|
|
def initialize(req : HTTP::Request)
|
|
|
|
agent = req.headers.fetch("User-Agent", "None")
|
|
if agent == "GiteaServer" && req.headers.has_key?("X-Gitea-Event")
|
|
@kind = "gitea"
|
|
elsif agent.starts_with?("GitHub-Hookshot/") && req.headers.has_key?("X-Github-Event")
|
|
@kind = "github"
|
|
elsif req.headers.has_key?("X-Gitlab-Event")
|
|
@kind = "gitlab"
|
|
else
|
|
@kind = "undefined"
|
|
end
|
|
|
|
@content = req.body.not_nil!.gets_to_end.to_s
|
|
|
|
end
|
|
end
|