diff options
| author | Rémy Coutable <remy@rymai.me> | 2017-10-05 19:02:50 +0200 |
|---|---|---|
| committer | Rémy Coutable <remy@rymai.me> | 2017-10-09 16:44:47 +0200 |
| commit | f070265a6ddd0173c8924bfcd7791ecafa15ab7e (patch) | |
| tree | cf364687889aa546f39b607aa57db839d7059c97 /app | |
| parent | 075d6516047d899746d22b5323d3b74558e200d0 (diff) | |
| download | gitlab-ce-f070265a6ddd0173c8924bfcd7791ecafa15ab7e.tar.gz | |
Introduce new hook data builders for Issue and MergeRequest34284-add-changes-to-issuable-webhook-data
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/issue.rb | 52 | ||||
| -rw-r--r-- | app/models/merge_request.rb | 57 |
2 files changed, 2 insertions, 107 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 2527622a989..36e4108b9d6 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -18,36 +18,6 @@ class Issue < ActiveRecord::Base DueThisWeek = DueDateStruct.new('Due This Week', 'week').freeze DueThisMonth = DueDateStruct.new('Due This Month', 'month').freeze - SAFE_HOOK_ATTRIBUTES = %i[ - assignee_id - author_id - branch_name - closed_at - confidential - created_at - deleted_at - description - due_date - id - iid - last_edited_at - last_edited_by_id - milestone_id - moved_to_id - project_id - relative_position - state - time_estimate - title - updated_at - updated_by_id - ].freeze - - SAFE_HOOK_RELATIONS = %i[ - assignees - labels - ].freeze - belongs_to :project belongs_to :moved_to, class_name: 'Issue' @@ -147,28 +117,8 @@ class Issue < ActiveRecord::Base "id DESC") end - def self.safe_hook_attributes - SAFE_HOOK_ATTRIBUTES - end - - def self.safe_hook_relations - SAFE_HOOK_RELATIONS - end - def hook_attrs - assignee_ids = self.assignee_ids - - attrs = { - url: Gitlab::UrlBuilder.build(self), - total_time_spent: total_time_spent, - human_total_time_spent: human_total_time_spent, - human_time_estimate: human_time_estimate, - assignee_ids: assignee_ids, - assignee_id: assignee_ids.first # This key is deprecated - } - - attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes) - .merge!(attrs) + Gitlab::HookData::IssueBuilder.new(self).build end # Returns a Hash of attributes to be used for Twitter card metadata diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ce32b7cb05e..75e9bdaaa45 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -7,41 +7,6 @@ class MergeRequest < ActiveRecord::Base include IgnorableColumn include CreatedAtFilterable - SAFE_HOOK_ATTRIBUTES = %i[ - assignee_id - author_id - created_at - deleted_at - description - head_pipeline_id - id - iid - last_edited_at - last_edited_by_id - merge_commit_sha - merge_error - merge_params - merge_status - merge_user_id - merge_when_pipeline_succeeds - milestone_id - ref_fetched - source_branch - source_project_id - state - target_branch - target_project_id - time_estimate - title - updated_at - updated_by_id - ].freeze - - SAFE_HOOK_RELATIONS = %i[ - assignee - labels - ].freeze - ignore_column :locked_at belongs_to :target_project, class_name: "Project" @@ -214,28 +179,8 @@ class MergeRequest < ActiveRecord::Base work_in_progress?(title) ? title : "WIP: #{title}" end - def self.safe_hook_attributes - SAFE_HOOK_ATTRIBUTES - end - - def self.safe_hook_relations - SAFE_HOOK_RELATIONS - end - def hook_attrs - attrs = { - url: Gitlab::UrlBuilder.build(self), - source: source_project.try(:hook_attrs), - target: target_project.hook_attrs, - last_commit: diff_head_commit&.hook_attrs, - work_in_progress: work_in_progress?, - total_time_spent: total_time_spent, - human_total_time_spent: human_total_time_spent, - human_time_estimate: human_time_estimate - } - - attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes) - .merge!(attrs) + Gitlab::HookData::MergeRequestBuilder.new(self).build end # Returns a Hash of attributes to be used for Twitter card metadata |
