Class: DraftNote
Constant Summary
collapse
- PUBLISH_ATTRS =
i[noteable type note internal].freeze
- DIFF_ATTRS =
i[position original_position change_position commit_id].freeze
BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, #diff_refs_match_commit, #keep_around_commits, #on_file?, #on_image?, #on_text?, #repository, #set_original_position, #shas, #should_update_position?, #supported?, #update_position
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Instance Attribute Details
#commands_changes ⇒ Object
Attribute used to store quick actions changes and users referenced.
15
16
17
|
# File 'app/models/draft_note.rb', line 15
def commands_changes
@commands_changes
end
|
#rendered_note ⇒ Object
Text with quick actions filtered out
19
20
21
|
# File 'app/models/draft_note.rb', line 19
def rendered_note
@rendered_note
end
|
#review ⇒ Object
Returns the value of attribute review.
21
22
23
|
# File 'app/models/draft_note.rb', line 21
def review
@review
end
|
#users_referenced ⇒ Object
Returns the value of attribute users_referenced.
16
17
18
|
# File 'app/models/draft_note.rb', line 16
def users_referenced
@users_referenced
end
|
Class Method Details
.bulk_insert_and_keep_commits!(items, **options) ⇒ Object
50
51
52
53
54
55
56
|
# File 'app/models/draft_note.rb', line 50
def self.bulk_insert_and_keep_commits!(items, **options)
inserted_records = bulk_insert!(items, **options)
keep_commits_for_records(items)
inserted_records
end
|
.keep_commits_for_records(records) ⇒ Object
58
59
60
|
# File 'app/models/draft_note.rb', line 58
def self.keep_commits_for_records(records)
records.find(&:on_diff?)&.keep_around_commits
end
|
.positions ⇒ Object
44
45
46
47
48
|
# File 'app/models/draft_note.rb', line 44
def self.positions
where.not(position: nil)
.select(:position)
.map(&:position)
end
|
.preload_author(draft_notes) ⇒ Object
134
135
136
|
# File 'app/models/draft_note.rb', line 134
def self.preload_author(draft_notes)
ActiveRecord::Associations::Preloader.new(records: draft_notes, associations: { author: :status }).call
end
|
Instance Method Details
#commit ⇒ Object
148
149
150
|
# File 'app/models/draft_note.rb', line 148
def commit
@commit ||= project.commit(commit_id) if commit_id.present?
end
|
#diff_file ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'app/models/draft_note.rb', line 138
def diff_file
strong_memoize(:diff_file) do
file = original_position&.diff_file(project.repository)
file&.unfold_diff_lines(original_position)
file
end
end
|
#emoji_awardable? ⇒ Boolean
92
93
94
|
# File 'app/models/draft_note.rb', line 92
def emoji_awardable?
false
end
|
#find_line_code ⇒ Object
119
120
121
|
# File 'app/models/draft_note.rb', line 119
def find_line_code
write_attribute(:line_code, diff_file&.line_code_for_position(original_position))
end
|
#for_commit? ⇒ Boolean
80
81
82
|
# File 'app/models/draft_note.rb', line 80
def for_commit?
commit_id.present?
end
|
#importing? ⇒ Boolean
84
85
86
|
# File 'app/models/draft_note.rb', line 84
def importing?
false
end
|
#line_code ⇒ Object
115
116
117
|
# File 'app/models/draft_note.rb', line 115
def line_code
super.presence || find_line_code
end
|
#noteable ⇒ Object
72
73
74
|
# File 'app/models/draft_note.rb', line 72
def noteable
merge_request
end
|
#noteable_id ⇒ Object
noteable_id and noteable_type methods are used to generate discussion_id on Discussion.discussion_id
68
69
70
|
# File 'app/models/draft_note.rb', line 68
def noteable_id
merge_request_id
end
|
#noteable_type ⇒ Object
76
77
78
|
# File 'app/models/draft_note.rb', line 76
def noteable_type
"MergeRequest"
end
|
#on_diff? ⇒ Boolean
96
97
98
|
# File 'app/models/draft_note.rb', line 96
def on_diff?
position&.complete?
end
|
#project ⇒ Object
62
63
64
|
# File 'app/models/draft_note.rb', line 62
def project
merge_request.target_project
end
|
#publish_params ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'app/models/draft_note.rb', line 123
def publish_params
attrs = PUBLISH_ATTRS.dup
attrs.concat(DIFF_ATTRS) if on_diff?
params = slice(*attrs)
params[:in_reply_to_discussion_id] = discussion_id if discussion_id.present?
params[:review_id] = review.id if review.present?
params.except("internal") if on_diff?
params
end
|
#references ⇒ Object
108
109
110
111
112
113
|
# File 'app/models/draft_note.rb', line 108
def references
{
users: users_referenced,
commands: commands_changes
}
end
|
#resolvable? ⇒ Boolean
88
89
90
|
# File 'app/models/draft_note.rb', line 88
def resolvable?
false
end
|
#type ⇒ Object
100
101
102
103
104
105
106
|
# File 'app/models/draft_note.rb', line 100
def type
return note_type if note_type.present?
return 'DiffNote' if on_diff?
return 'DiscussionNote' if discussion_id.present?
'Note'
end
|