Module: Gitlab::Triage::Resource::Shared::Issuable
- Included in:
- Epic, Issue, MergeRequest
- Defined in:
- lib/gitlab/triage/resource/shared/issuable.rb
Constant Summary collapse
- SourceTooDeep =
Class.new(RuntimeError)
- MAX_PARENT_LOOKUP =
10
Instance Method Summary collapse
- #author ⇒ Object
- #full_resource_reference ⇒ Object
- #group_url(group_id) ⇒ Object private
- #label_events ⇒ Object
-
#labels ⇒ Object
This will be more useful when we have: gitlab.com/gitlab-org/gitlab-ce/issues/51011.
- #labels_chronologically ⇒ Object
-
#labels_with_details ⇒ Object
Make this an alias of ‘labels` when we have: gitlab.com/gitlab-org/gitlab-ce/issues/51011.
- #milestone ⇒ Object
- #project_path ⇒ Object
- #project_url(project_id) ⇒ Object private
- #query_label_events ⇒ Object private
- #request_group(group_id) ⇒ Object private
- #request_project(project_id) ⇒ Object private
- #root_id(resource: source_resource, max_levels: MAX_PARENT_LOOKUP) ⇒ Object
- #state ⇒ Object
Instance Method Details
#author ⇒ Object
54 55 56 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 54 def @author ||= resource.dig(:author, :username) end |
#full_resource_reference ⇒ Object
63 64 65 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 63 def full_resource_reference @full_resource_reference ||= resource.dig(:references, :full) end |
#group_url(group_id) ⇒ Object (private)
100 101 102 103 104 105 106 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 100 def group_url(group_id) Gitlab::Triage::UrlBuilders::UrlBuilder.new( network_options: network., source: 'groups', source_id: group_id ).build end |
#label_events ⇒ Object
41 42 43 44 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 41 def label_events @label_events ||= query_label_events .map { |label_event| LabelEvent.new(label_event, parent: self) } end |
#labels ⇒ Object
This will be more useful when we have: gitlab.com/gitlab-org/gitlab-ce/issues/51011
23 24 25 26 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 23 def labels @labels ||= resource[:labels] # an array of label names .map { |label| Label.new({ name: label }, parent: self) } end |
#labels_chronologically ⇒ Object
46 47 48 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 46 def labels_chronologically @labels_chronologically ||= labels_with_details.sort_by(&:added_at) end |
#labels_with_details ⇒ Object
Make this an alias of ‘labels` when we have: gitlab.com/gitlab-org/gitlab-ce/issues/51011
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 30 def labels_with_details # Labels can be deleted thus event.label can be nil @labels_with_details ||= label_events .select { |event| event.action == 'add' && event.label } .map(&:label) .sort_by(&:added_at) .reverse .uniq(&:name) .select { |label| resource[:labels].include?(label.name) } end |
#milestone ⇒ Object
15 16 17 18 19 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 15 def milestone @milestone ||= resource[:milestone] && Milestone.new(resource[:milestone], parent: self) end |
#project_path ⇒ Object
58 59 60 61 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 58 def project_path @project_path ||= request_project(resource[:project_id])[:path_with_namespace] end |
#project_url(project_id) ⇒ Object (private)
108 109 110 111 112 113 114 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 108 def project_url(project_id) Gitlab::Triage::UrlBuilders::UrlBuilder.new( network_options: network., source: 'projects', source_id: project_id ).build end |
#query_label_events ⇒ Object (private)
87 88 89 90 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 87 def query_label_events network.query_api_cached( resource_url(sub_resource_type: 'resource_label_events')) end |
#request_group(group_id) ⇒ Object (private)
96 97 98 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 96 def request_group(group_id) network.query_api_cached(group_url(group_id)).first end |
#request_project(project_id) ⇒ Object (private)
92 93 94 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 92 def request_project(project_id) network.query_api_cached(project_url(project_id)).first end |
#root_id(resource: source_resource, max_levels: MAX_PARENT_LOOKUP) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 67 def root_id( resource: source_resource, max_levels: MAX_PARENT_LOOKUP) raise SourceTooDeep if max_levels <= 0 # In projects, the reference to the namespace's parent ID is `namespace.parent_id` # but in groups, the reference is directly in `parent_id` parent_id = resource.dig(:namespace, :parent_id) || resource.dig(:parent_id) if parent_id root_id( resource: request_group(parent_id), max_levels: max_levels - 1) else resource.dig(:namespace, :id) || resource[:id] end end |
#state ⇒ Object
50 51 52 |
# File 'lib/gitlab/triage/resource/shared/issuable.rb', line 50 def state @state ||= resource.dig(:state) end |