Class: Gitlab::GithubImport::Representation::IssueEvent

Inherits:
Object
  • Object
show all
Includes:
ExposeAttribute, ToHash
Defined in:
lib/gitlab/github_import/representation/issue_event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExposeAttribute

#[]

Methods included from ToHash

#convert_value_for_to_hash, #to_hash

Constructor Details

#initialize(attributes) ⇒ IssueEvent

attributes - A Hash containing the event details. The keys of this

Hash (and any nested hashes) must be symbols.


18
19
20
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 18

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



10
11
12
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 10

def attributes
  @attributes
end

Class Method Details

.from_api_response(event, additional_data = {}) ⇒ Object

Builds an event from a GitHub API response.

event - An instance of ‘Hash` containing the event details.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 42

def from_api_response(event, additional_data = {})
  new(
    id: event[:id],
    actor: user_representation(event[:actor]),
    event: event[:event],
    commit_id: event[:commit_id],
    label_title: event.dig(:label, :name),
    old_title: event.dig(:rename, :from),
    new_title: event.dig(:rename, :to),
    milestone_title: event.dig(:milestone, :title),
    issue: event[:issue],
    source: event[:source],
    assignee: user_representation(event[:assignee]),
    requested_reviewer: user_representation(event[:requested_reviewer]),
    review_requester: user_representation(event[:review_requester]),
    created_at: event[:created_at]
  )
end

.from_json_hash(raw_hash) ⇒ Object

Builds an event using a Hash that was built from a JSON payload.



62
63
64
65
66
67
68
69
70
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 62

def from_json_hash(raw_hash)
  hash = Representation.symbolize_hash(raw_hash)
  hash[:actor] = user_representation(hash[:actor], source: :hash)
  hash[:assignee] = user_representation(hash[:assignee], source: :hash)
  hash[:requested_reviewer] = user_representation(hash[:requested_reviewer], source: :hash)
  hash[:review_requester] = user_representation(hash[:review_requester], source: :hash)

  new(hash)
end

Instance Method Details

#github_identifiersObject



22
23
24
25
26
27
28
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 22

def github_identifiers
  {
    id: id,
    issuable_iid: issuable_id,
    event: event
  }
end

#issuable_idObject



34
35
36
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 34

def issuable_id
  issue && issue[:number]
end

#issuable_typeObject



30
31
32
# File 'lib/gitlab/github_import/representation/issue_event.rb', line 30

def issuable_type
  issue && issue[:pull_request].present? ? 'MergeRequest' : 'Issue'
end