Class: Gitlab::GithubImport::Representation::Note
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Representation::Note
- Includes:
- ExposeAttribute, ToHash
- Defined in:
- lib/gitlab/github_import/representation/note.rb
Constant Summary collapse
- NOTEABLE_TYPE_REGEX =
%r{/(?<type>(pull|issues))/(?<iid>\d+)}i
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.from_api_response(note, additional_data = {}) ⇒ Object
Builds a note from a GitHub API response.
-
.from_json_hash(raw_hash) ⇒ Object
Builds a new note using a Hash that was built from a JSON payload.
Instance Method Summary collapse
- #discussion_id ⇒ Object
- #github_identifiers ⇒ Object
-
#initialize(attributes) ⇒ Note
constructor
attributes - A Hash containing the raw note details.
Methods included from ExposeAttribute
Methods included from ToHash
#convert_value_for_to_hash, #to_hash
Constructor Details
#initialize(attributes) ⇒ Note
attributes - A Hash containing the raw note details. The keys of this
Hash must be Symbols.
62 63 64 |
# File 'lib/gitlab/github_import/representation/note.rb', line 62 def initialize(attributes) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/gitlab/github_import/representation/note.rb', line 10 def attributes @attributes end |
Class Method Details
.from_api_response(note, additional_data = {}) ⇒ Object
Builds a note from a GitHub API response.
note - An instance of ‘Hash` containing the note details.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gitlab/github_import/representation/note.rb', line 20 def self.from_api_response(note, additional_data = {}) matches = note[:html_url].match(NOTEABLE_TYPE_REGEX) if !matches || !matches[:type] raise( ArgumentError, "The note URL #{note[:html_url].inspect} is not supported" ) end noteable_type = if matches[:type] == 'pull' 'MergeRequest' else 'Issue' end user = Representation::User.from_api_response(note[:user]) if note[:user] hash = { noteable_type: noteable_type, noteable_id: matches[:iid].to_i, author: user, note: note[:body], created_at: note[:created_at], updated_at: note[:updated_at], note_id: note[:id] } new(hash) end |
.from_json_hash(raw_hash) ⇒ Object
Builds a new note using a Hash that was built from a JSON payload.
52 53 54 55 56 57 58 |
# File 'lib/gitlab/github_import/representation/note.rb', line 52 def self.from_json_hash(raw_hash) hash = Representation.symbolize_hash(raw_hash) hash[:author] &&= Representation::User.from_json_hash(hash[:author]) new(hash) end |
Instance Method Details
#discussion_id ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/gitlab/github_import/representation/note.rb', line 66 def discussion_id Discussion.discussion_id( Struct .new(:noteable_id, :noteable_type) .new(noteable_id, noteable_type) ) end |
#github_identifiers ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/gitlab/github_import/representation/note.rb', line 76 def github_identifiers { note_id: note_id, noteable_iid: noteable_id, noteable_type: noteable_type } end |