Class: Gitlab::GithubImport::Representation::Issue
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Representation::Issue
- Includes:
- Representable
- Defined in:
- lib/gitlab/github_import/representation/issue.rb
Class Method Summary collapse
-
.from_api_response(issue, additional_data = {}) ⇒ Object
Builds an issue from a GitHub API response.
-
.from_json_hash(raw_hash) ⇒ Object
Builds a new issue using a Hash that was built from a JSON payload.
Instance Method Summary collapse
- #github_identifiers ⇒ Object
-
#initialize(attributes) ⇒ Issue
constructor
attributes - A hash containing the raw issue details.
- #issuable_type ⇒ Object
- #labels? ⇒ Boolean
- #pull_request? ⇒ Boolean
- #truncated_title ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Issue
attributes - A hash containing the raw issue details. The keys of this
Hash (and any nested hashes) must be symbols.
56 57 58 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 56 def initialize(attributes) @attributes = attributes end |
Class Method Details
.from_api_response(issue, additional_data = {}) ⇒ Object
Builds an issue from a GitHub API response.
issue - An instance of Hash containing the issue
details.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 17 def self.from_api_response(issue, additional_data = {}) user = if issue[:user] Representation::User.from_api_response(issue[:user]) end hash = { iid: issue[:number], title: issue[:title], description: issue[:body], milestone_number: issue.dig(:milestone, :number), state: issue[:state] == 'open' ? :opened : :closed, assignees: issue[:assignees].map do |u| Representation::User.from_api_response(u) end, label_names: issue[:labels].map { _1[:name] }, author: user, created_at: issue[:created_at], updated_at: issue[:updated_at], pull_request: issue[:pull_request] ? true : false, work_item_type_id: additional_data[:work_item_type_id] } new(hash) end |
.from_json_hash(raw_hash) ⇒ Object
Builds a new issue using a Hash that was built from a JSON payload.
44 45 46 47 48 49 50 51 52 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 44 def self.from_json_hash(raw_hash) hash = Representation.symbolize_hash(raw_hash) hash[:state] = hash[:state].to_sym hash[:assignees].map! { |u| Representation::User.from_json_hash(u) } hash[:author] &&= Representation::User.from_json_hash(hash[:author]) new(hash) end |
Instance Method Details
#github_identifiers ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 76 def github_identifiers { iid: iid, issuable_type: issuable_type, title: title } end |
#issuable_type ⇒ Object
72 73 74 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 72 def issuable_type pull_request? ? 'MergeRequest' : 'Issue' end |
#labels? ⇒ Boolean
64 65 66 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 64 def labels? label_names && label_names.any? end |
#pull_request? ⇒ Boolean
68 69 70 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 68 def pull_request? attributes[:pull_request] end |
#truncated_title ⇒ Object
60 61 62 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 60 def truncated_title title.truncate(255) end |