|
|
|
@@ -1,14 +1,14 @@ |
|
|
|
class Api::V1::Projects::Webhooks::CreateService < ApplicationService |
|
|
|
include ActiveModel::Model |
|
|
|
|
|
|
|
attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events |
|
|
|
attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events, :type |
|
|
|
attr_accessor :gitea_data |
|
|
|
|
|
|
|
validates :url, format: { with: URI::regexp(%w[http https]), message: "请输入正确的地址" } |
|
|
|
validates :active, inclusion: {in: [true, false]} |
|
|
|
validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"} |
|
|
|
validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"} |
|
|
|
|
|
|
|
validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu), message: "请输入正确的Webhook Type"} |
|
|
|
def initialize(project, params, token=nil) |
|
|
|
@project = project |
|
|
|
@owner = project&.owner.login |
|
|
|
@@ -20,6 +20,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService |
|
|
|
@http_method = params[:http_method] |
|
|
|
@secret = params[:secret] |
|
|
|
@events = params[:events] |
|
|
|
@type = params[:type] || "gitea" |
|
|
|
@token = token |
|
|
|
end |
|
|
|
|
|
|
|
@@ -52,7 +53,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService |
|
|
|
secret: secret |
|
|
|
}, |
|
|
|
events: events || [], |
|
|
|
type: 'gitea', |
|
|
|
type: type, |
|
|
|
} |
|
|
|
end |
|
|
|
|
|
|
|
|