Class: GitlabQuality::TestTooling::GitlabClient::WorkItemsClient
Instance Method Summary
collapse
-
#add_labels(work_item_id:, label_ids:) ⇒ Object
-
#create_discussion(id:, note:) ⇒ Object
-
#create_discussion_note(work_item_id:, discussion_id:, text:) ⇒ Object
-
#create_linked_items(work_item_id:, item_ids:, link_type:) ⇒ Object
-
#group_work_items(labels: [], cursor: '', state: 'opened', created_after: nil, extras: [:work_item_fields]) ⇒ Object
-
#paginated_call(method_name, args) ⇒ Object
-
#update_note(note_id:, body:) ⇒ Object
-
#work_item(workitem_iid:, widgets: [:notes, :linked_items, :labels, :hierarchy]) ⇒ Object
#initialize, #post
Instance Method Details
#add_labels(work_item_id:, label_ids:) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 100
def add_labels(work_item_id:, label_ids:)
query =
<<~GQL
mutation WorkItemUpdate {
workItemUpdate(input: { id: "#{work_item_id}", labelsWidget: { addLabelIds: [#{label_ids.map { |id| "\"#{id}\"" }.join(', ')}] } }) {
clientMutationId
errors
}
}
GQL
post(query)
end
|
#create_discussion(id:, note:) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 44
def create_discussion(id:, note:)
post(
<<~GQL
mutation CreateDiscussion {
createDiscussion(input: {noteableId: "#{id}", body: "#{note}"}) {
clientMutationId
errors
note {
#{note_fields}
}
}
}
GQL
)
end
|
#create_discussion_note(work_item_id:, discussion_id:, text:) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 60
def create_discussion_note(work_item_id:, discussion_id:, text:)
query = <<~GQL
mutation CreateNote {
createNote(input: { discussionId: "#{discussion_id}", noteableId: "#{work_item_id}", body: "#{text}" }) {
clientMutationId
errors
note {
#{note_fields}
}
}
}
GQL
post(query)
end
|
#create_linked_items(work_item_id:, item_ids:, link_type:) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 87
def create_linked_items(work_item_id:, item_ids:, link_type:)
query = <<~GQL
mutation WorkItemAddLinkedItems {
workItemAddLinkedItems(
input: { id: "#{work_item_id}", workItemsIds: [#{item_ids.map { |id| "\"#{id}\"" }.join(', ')}], linkType: #{link_type} }
) {
clientMutationId
}
}
GQL
post(query)
end
|
#group_work_items(labels: [], cursor: '', state: 'opened', created_after: nil, extras: [:work_item_fields]) ⇒ Object
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_quality/test_tooling/gitlab_client/work_items_client.rb', line 21
def group_work_items(labels: [], cursor: '', state: 'opened', created_after: nil, extras: [:work_item_fields])
query = <<~GQL
query {
group(fullPath: "#{group}") {
workItems(after: "#{cursor}",#{created_after ? " createdAfter: \"#{created_after}\"," : ''} labelName: [#{labels.map { |label| "\"#{label}\"" }.join(', ')}], state: #{state}) {
nodes {
#{()}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
GQL
begin
post(query)[:workItems]
rescue StandardError => e
puts "Error: #{e}"
end
end
|
#paginated_call(method_name, args) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 113
def paginated_call(method_name, args)
results = []
raise ArgumentError, "Unknown method: #{method_name}" unless respond_to?(method_name, true)
method_obj = method(method_name)
loop do
response = method_obj.call(**args)
break unless response
results += response[:nodes]
break unless response[:pageInfo][:hasNextPage]
args[:cursor] = response[:pageInfo][:endCursor]
end
results
end
|
#update_note(note_id:, body:) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 75
def update_note(note_id:, body:)
query = <<~GQL
mutation UpdateNote {
updateNote(input: { body: "#{body}", id: "#{note_id}" }) {
clientMutationId
errors
}
}
GQL
post(query)
end
|
#work_item(workitem_iid:, widgets: [:notes, :linked_items, :labels, :hierarchy]) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/gitlab_quality/test_tooling/gitlab_client/work_items_client.rb', line 7
def work_item(workitem_iid:, widgets: [:notes, :linked_items, :labels, :hierarchy])
query = <<~GQL
query {
namespace(fullPath: "#{group}") {
workItem(iid: "#{workitem_iid}") {
#{work_item_fields}
#{work_item_widgets(widgets)}
}
}
}
GQL
post(query)[:workItem]
end
|