2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
|
|
module MergeRequests
|
|
|
|
module Mergeability
|
|
|
|
class CheckResult
|
|
|
|
SUCCESS_STATUS = :success
|
|
|
|
FAILED_STATUS = :failed
|
|
|
|
|
|
|
|
attr_reader :status, :payload
|
|
|
|
|
|
|
|
def self.default_payload
|
|
|
|
{ last_run_at: Time.current }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.success(payload: {})
|
2022-08-27 11:52:29 +05:30
|
|
|
new(status: SUCCESS_STATUS, payload: default_payload.merge(**payload))
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.failed(payload: {})
|
2022-08-27 11:52:29 +05:30
|
|
|
new(status: FAILED_STATUS, payload: default_payload.merge(**payload))
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.from_hash(data)
|
|
|
|
new(
|
2023-01-13 00:05:48 +05:30
|
|
|
status: data.fetch(:status).to_sym,
|
|
|
|
payload: data.fetch(:payload))
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(status:, payload: {})
|
|
|
|
@status = status
|
|
|
|
@payload = payload
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_hash
|
|
|
|
{ status: status, payload: payload }
|
|
|
|
end
|
|
|
|
|
|
|
|
def failed?
|
|
|
|
status == FAILED_STATUS
|
|
|
|
end
|
|
|
|
|
|
|
|
def success?
|
|
|
|
status == SUCCESS_STATUS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|