Module: GitlabQuality::TestTooling::FeatureReadiness::Concerns::WorkItemConcern
- Included in:
- AnalyzedItems::AnalyzedEpic, EpicReadinessNotifier, OperationalReadinessCheck, Report::FeatureReadiness::ReportOnEpic
- Defined in:
- lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb
Constant Summary collapse
- OPERATIONAL_READINESS_NOTE_ID =
'<!-- OPERATIONAL READINESS PRECHECK COMMENT -->'- OPERATIONAL_READINESS_TRACKING_LABEL =
'tracking operational readiness'
Instance Method Summary collapse
- #add_labels(label_ids, work_item_id, client) ⇒ Object
- #add_operational_readiness_precheck_comment(work_item, work_items_client, label_client) ⇒ Object
- #existing_note_containing_text(text, work_item_iid, client) ⇒ Object
- #extract_id_from_gid(gid) ⇒ Object
- #fetch_work_item(iid, client, widgets = []) ⇒ Object
- #get_id_for_group_label(label_name, group_labels_client) ⇒ Object
- #get_id_for_label(label_name, label_client) ⇒ Object
- #get_issue_iids(work_item, project) ⇒ Object
- #get_labels(work_item) ⇒ Object
- #has_a_child_epic?(epic) ⇒ Boolean
- #has_label?(work_item, label) ⇒ Boolean
- #ids_for_group_labels(labels, group_labels_client) ⇒ Object
- #ids_for_labels(labels, label_client) ⇒ Object
- #label_gids(label_ids = []) ⇒ Object
- #link_operation_readiness_issue(issue, work_item, link_type, client) ⇒ Object
- #linked_issue_iids(work_item) ⇒ Object
- #note_has_emoji?(note, emoji_name) ⇒ Boolean
- #post_comment_about_operation_readiness_issue_created(work_item, issue, precheck_comment, client) ⇒ Object
- #work_item_author_id(work_item) ⇒ Object
Instance Method Details
#add_labels(label_ids, work_item_id, client) ⇒ Object
81 82 83 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 81 def add_labels(label_ids, work_item_id, client) client.add_labels(work_item_id: work_item_id, label_ids: label_gids(label_ids)) end |
#add_operational_readiness_precheck_comment(work_item, work_items_client, label_client) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 11 def add_operational_readiness_precheck_comment(work_item, work_items_client, label_client) comment = " \#{OPERATIONAL_READINESS_NOTE_ID}\n ## Operational Readiness Pre-Check\n\n @\#{work_item[:author][:username]} This is an automated comment to help determine if an\n [operational readiness check](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/issue_templates/Operational%20Readiness.md?ref_type=heads)\n is needed for this feature.\n\n Please respond with the \u2705 emoji on this comment if your feature meets any of the below criteria. If not, please respond with the \u274C emoji.\n\n 1. Requires new infrastructure components, or significant changes to existing components that have dependencies on the GitLab application.\n 2. Requires changes to our application architecture that change how the infrastructure scales, GitLab is deployed or how data is processed or stored.\n 3. Adds new services or changes existing services that will factor into the availability of the GitLab application.\n COMMENT\n\n add_labels(ids_for_labels([OPERATIONAL_READINESS_TRACKING_LABEL], label_client), work_item[:id], work_items_client)\n\n discussion = existing_note_containing_text(OPERATIONAL_READINESS_NOTE_ID, work_item[:iid], work_items_client)\n\n return discussion if discussion\n\n work_items_client.create_discussion(id: work_item[:id], note: comment)\n\n puts \"\\nAdded operational readiness comment to epic work item: \#{work_item[:webUrl]}\\n\"\n\n existing_note_containing_text(OPERATIONAL_READINESS_NOTE_ID, work_item[:iid], work_items_client)\nend\n" |
#existing_note_containing_text(text, work_item_iid, client) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 40 def existing_note_containing_text(text, work_item_iid, client) work_item = fetch_work_item(work_item_iid, client, [:notes]) work_item[:widgets] .find { || .key?(:discussions) } .dig(:discussions, :nodes) .find { |node| node[:notes][:nodes].any? { |node| node[:body].include?(text) } } &.dig(:notes, :nodes, 0) end |
#extract_id_from_gid(gid) ⇒ Object
132 133 134 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 132 def extract_id_from_gid(gid) gid.to_s.split('/').last.to_i end |
#fetch_work_item(iid, client, widgets = []) ⇒ Object
85 86 87 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 85 def fetch_work_item(iid, client, = []) client.work_item(workitem_iid: iid, widgets: ) end |
#get_id_for_group_label(label_name, group_labels_client) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 125 def get_id_for_group_label(label_name, group_labels_client) labels = group_labels_client.group_labels(options: { search: label_name }) return nil if labels.empty? labels.first.id end |
#get_id_for_label(label_name, label_client) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 113 def get_id_for_label(label_name, label_client) labels = label_client.labels(options: { search: label_name }) raise "No labels found with name: '#{label_name}'" if labels.empty? labels.first.id end |
#get_issue_iids(work_item, project) ⇒ Object
72 73 74 75 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 72 def get_issue_iids(work_item, project) childern_node = work_item[:widgets]&.find { || .key?(:children) } childern_node && childern_node[:children][:nodes].filter_map { |issue| issue[:iid] if issue[:workItemType][:name] == "Issue" && issue[:project][:fullPath] == project } end |
#get_labels(work_item) ⇒ Object
67 68 69 70 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 67 def get_labels(work_item) labels_node = work_item[:widgets]&.find { || .key?(:labels) } labels_node && labels_node[:labels][:nodes].map { |label| label[:title] } end |
#has_a_child_epic?(epic) ⇒ Boolean
89 90 91 92 93 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 89 def has_a_child_epic?(epic) epic[:widgets] .find { || .has_key?(:children) }[:children][:nodes] .any? { |child| child[:workItemType][:name] == "Epic" } end |
#has_label?(work_item, label) ⇒ Boolean
77 78 79 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 77 def has_label?(work_item, label) get_labels(work_item).include?(label) end |
#ids_for_group_labels(labels, group_labels_client) ⇒ Object
121 122 123 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 121 def ids_for_group_labels(labels, group_labels_client) labels.filter_map { |label| get_id_for_group_label(label, group_labels_client) } end |
#ids_for_labels(labels, label_client) ⇒ Object
109 110 111 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 109 def ids_for_labels(labels, label_client) labels.map { |label| get_id_for_label(label, label_client) } end |
#label_gids(label_ids = []) ⇒ Object
105 106 107 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 105 def label_gids(label_ids = []) label_ids.map { |label_id| "gid://gitlab/Label/#{label_id}" } end |
#link_operation_readiness_issue(issue, work_item, link_type, client) ⇒ Object
50 51 52 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 50 def link_operation_readiness_issue(issue, work_item, link_type, client) client.create_linked_items(work_item_id: work_item[:id], item_ids: ["gid://gitlab/Issue/#{issue.id}"], link_type: link_type) end |
#linked_issue_iids(work_item) ⇒ Object
99 100 101 102 103 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 99 def linked_issue_iids(work_item) work_item[:widgets].find { || .key?(:linkedItems) } .dig(:linkedItems, :nodes) .map { |node| node.dig(:workItem, :iid) } end |
#note_has_emoji?(note, emoji_name) ⇒ Boolean
54 55 56 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 54 def note_has_emoji?(note, emoji_name) note&.dig(:awardEmoji, :nodes)&.any? { |node| node[:name] == emoji_name } end |
#post_comment_about_operation_readiness_issue_created(work_item, issue, precheck_comment, client) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 58 def post_comment_about_operation_readiness_issue_created(work_item, issue, precheck_comment, client) comment_text = " @\#{work_item[:author][:username]} Thanks for confirming that your feature requires an operational readiness check.\n Based on your response, an operational readiness check issue has been created and linked to this issue: \#{issue.web_url}.\n COMMENT\n\n client.create_discussion_note(work_item_id: work_item[:id], discussion_id: precheck_comment.dig(:discussion, :id), text: comment_text)\nend\n" |
#work_item_author_id(work_item) ⇒ Object
95 96 97 |
# File 'lib/gitlab_quality/test_tooling/feature_readiness/concerns/work_item_concern.rb', line 95 def (work_item) extract_id_from_gid(work_item[:author][:id]) end |