Skip to content
Snippets Groups Projects

Add audit events for merge request settings

Merged Harsimar Sandhu requested to merge 355805-merge-request-settings-audit-events into master
Compare and
17 files
+ 398
43
Compare changes
  • Side-by-side
  • Inline
Files
17
@@ -4,6 +4,7 @@ module MergeRequests
class ExternalStatusCheck < ApplicationRecord
self.table_name = 'external_status_checks'
include Auditable
include IgnorableColumns
ignore_column :external_approval_rule_id, remove_with: '14.3', remove_after: '2021-09-22'
@@ -15,8 +16,10 @@ class ExternalStatusCheck < ApplicationRecord
end
belongs_to :project
has_and_belongs_to_many :protected_branches
has_and_belongs_to_many :protected_branches,
after_add: :audit_protected_branch_add, after_remove: :audit_protected_branch_remove
after_create_commit :audit_creation
after_destroy_commit :audit_deletion
validates :external_url, presence: true, uniqueness: { scope: :project_id }, addressable_url: true
validates :name, uniqueness: { scope: :project_id }, presence: true
validate :protected_branches_must_belong_to_project
@@ -43,6 +46,26 @@ def to_h
}
end
def audit_protected_branch_add(model)
message = "Added #{model.class.name} #{model.name} to #{self.name} status check"
message += " and removed All Branches from status check" if protected_branches.count == 1
push_audit_event(message)
end
def audit_creation
push_audit_event("Added status check")
end
def audit_deletion
push_audit_event("Removed status check")
end
def audit_protected_branch_remove(model)
message = "Removed #{model.class.name} #{model.name} from #{self.name} status check"
message += " and added All Branches to status check" if protected_branches.blank?
push_audit_event(message)
end
private
def payload_data(merge_request_hook_data)
Loading