Class: Gitlab::Triage::Normalizers::WorkItemNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/normalizers/work_item_normalizer.rb

Overview

Translates a raw Work Items REST API payload into the flat, issue-shaped resource hash the rest of the gem expects (integer id, iid, state as opened/closed, labels as title strings, assignees and author as hashes). This is the single place that knows the Work Items REST wire shape: the sparse fields payload and the nested features object with its labels/assignees/status widgets.

Instance Method Summary collapse

Instance Method Details

#assignees(features) ⇒ Object (private)



64
65
66
# File 'lib/gitlab/triage/normalizers/work_item_normalizer.rb', line 64

def assignees(features)
  [*features[:assignees]]
end

#call(raw) ⇒ Object



15
16
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
42
# File 'lib/gitlab/triage/normalizers/work_item_normalizer.rb', line 15

def call(raw)
  resource = raw.deep_transform_keys(&:underscore).with_indifferent_access
  features = resource[:features] || {}

  namespace = resource[:namespace] || {}

  {
    id: resource[:id],
    iid: resource[:iid],
    web_url: resource[:web_url],
    title: resource[:title],
    state: resource[:state],
    confidential: resource[:confidential],
    created_at: resource[:created_at],
    updated_at: resource[:updated_at],
    author: resource[:author],
    labels: label_titles(features),
    assignees: assignees(features),
    milestone: features[:milestone],
    work_item_type: resource.dig(:work_item_type, :name),
    work_item_status: status_name(features),
    start_date: features.dig(:start_and_due_date, :start_date),
    due_date: features.dig(:start_and_due_date, :due_date),
    namespace: namespace.presence,
    group_id: group_id_for(namespace),
    type: 'work_items'
  }.compact.with_indifferent_access
end

#group_id_for(namespace) ⇒ Object (private)

The list endpoint exposes the containing namespace, not a legacy project id. For a group namespace, namespace.id IS the legacy group id, so we can surface group_id directly - that lets the resource's group-scoped helpers build /groups/:id/... URLs unchanged.

For a project namespace, namespace.id is the project-namespace id, which is NOT the legacy project id and is useless for /projects/:id endpoints. We deliberately do NOT map it to project_id; the source resolves the real project id from namespace.full_path instead (it needs the network, so it cannot happen here).



56
57
58
# File 'lib/gitlab/triage/normalizers/work_item_normalizer.rb', line 56

def group_id_for(namespace)
  namespace[:id] if namespace[:kind] == 'group'
end

#label_titles(features) ⇒ Object (private)



60
61
62
# File 'lib/gitlab/triage/normalizers/work_item_normalizer.rb', line 60

def label_titles(features)
  [*features.dig(:labels, :labels)].pluck(:title)
end

#status_name(features) ⇒ Object (private)



68
69
70
# File 'lib/gitlab/triage/normalizers/work_item_normalizer.rb', line 68

def status_name(features)
  features.dig(:status, :status, :name)
end