Class: Gitlab::GithubImport::Representation::Issue
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::Representation::Issue
- Includes:
- ExposeAttribute, ToHash
- Defined in:
- lib/gitlab/github_import/representation/issue.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.from_api_response(issue) ⇒ 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
-
#initialize(attributes) ⇒ Issue
constructor
attributes - A hash containing the raw issue details.
- #issuable_type ⇒ Object
- #labels? ⇒ Boolean
- #pull_request? ⇒ Boolean
- #truncated_title ⇒ Object
Methods included from ToHash
#convert_value_for_to_hash, #to_hash
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.
58 59 60 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 58 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/issue.rb', line 10 def attributes @attributes end |
Class Method Details
.from_api_response(issue) ⇒ Object
Builds an issue from a GitHub API response.
issue - An instance of `Sawyer::Resource` containing the issue
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 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 20 def self.from_api_response(issue) 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.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(&:name), author: user, created_at: issue.created_at, updated_at: issue.updated_at, pull_request: issue.pull_request ? true : false } new(hash) end |
.from_json_hash(raw_hash) ⇒ Object
Builds a new issue using a Hash that was built from a JSON payload.
46 47 48 49 50 51 52 53 54 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 46 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
#issuable_type ⇒ Object
74 75 76 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 74 def issuable_type pull_request? ? 'MergeRequest' : 'Issue' end |
#labels? ⇒ Boolean
66 67 68 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 66 def labels? label_names && label_names.any? end |
#pull_request? ⇒ Boolean
70 71 72 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 70 def pull_request? attributes[:pull_request] end |
#truncated_title ⇒ Object
62 63 64 |
# File 'lib/gitlab/github_import/representation/issue.rb', line 62 def truncated_title title.truncate(255) end |