Class: Apadmi::Grout::AdoBoardService
- Inherits:
-
BoardService
- Object
- BoardService
- Apadmi::Grout::AdoBoardService
- Defined in:
- lib/apadmi/grout/service/board_service/ado_board_service.rb
Overview
Provides a layer of abstraction on top of the ADO api
Constant Summary collapse
- API_VERSION_PARAM =
"api-version=6.0"
Instance Method Summary collapse
- #add_comment(key, comment) ⇒ Object
- #add_tag(key, tag) ⇒ Object
- #assign_fixversions(key, versions) ⇒ Object
- #assign_to_user(key, user) ⇒ Object
- #find_issues_by_keys(keys) ⇒ Array<Apadmi::Grout::Issue>
- #flag_ticket(key, comment) ⇒ Object
- #flagged?(key) ⇒ Boolean
-
#get_ticket_fixversions(key) ⇒ Array<String>
Fix versions.
- #get_ticket_status(key) ⇒ String
- #get_work_item(key) ⇒ RawWorkItemHash
-
#initialize(network_service, ado_config, logger) ⇒ AdoBoardService
constructor
A new instance of AdoBoardService.
- #remove_tag(key, tag) ⇒ Object
- #search_unblocked_issues(component, status, ticket_types = [], options = nil) ⇒ Array<Apadmi::Grout::Issue>
- #transition_issue(issue, state_name) ⇒ Object
- #un_flag_ticket(key) ⇒ Object
- #update_ticket(key, payload) ⇒ Object
Constructor Details
#initialize(network_service, ado_config, logger) ⇒ AdoBoardService
Returns a new instance of AdoBoardService.
14 15 16 17 18 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 14 def initialize(network_service, ado_config, logger) @network_service = network_service @ado_config = ado_config @logger = logger end |
Instance Method Details
#add_comment(key, comment) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 76 def add_comment(key, comment) key = sanitise_key(key) payload = { "text" => comment } @network_service.do_post("/wit/workitems/#{key}/comments?#{API_VERSION_PARAM}-preview.3", payload.to_json) end |
#add_tag(key, tag) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 93 def add_tag(key, tag) payload = [{ "op" => "add", "path" => "/fields/System.Tags", "value" => tag }] update_ticket(key, payload) end |
#assign_fixversions(key, versions) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 133 def assign_fixversions(key, versions) key = sanitise_key(key) payload = [{ "op" => "replace", "path" => "/fields/Microsoft.VSTS.Build.IntegrationBuild", "value" => versions.join("; ") }] update_ticket(key, payload) end |
#assign_to_user(key, user) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 167 def assign_to_user(key, user) key = sanitise_key(key) payload = if user [{ "op": "add", "path": "/fields/System.AssignedTo", "value": user }] else [{ "op": "remove", "path": "/fields/System.AssignedTo" }] end update_ticket(key, payload) end |
#find_issues_by_keys(keys) ⇒ Array<Apadmi::Grout::Issue>
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 22 def find_issues_by_keys(keys) return [] if keys.length <= 0 keys = keys.map { |k| sanitise_key(k) } # Allows supporting raw keys, and keys prefixed with a hash which is common ADO practice res = @network_service.do_get("/wit/workitems?ids=#{keys.join(",")}&$expand=#{@ado_config.}&errorPolicy=omit&api-version=7.1-preview.2") parsed = JSON.parse(res.body) items = parsed["value"] return [] if items.nil? || items.compact.empty? items.compact.map { |i| Apadmi::Grout::Issue.from_ado_hash(i) } end |
#flag_ticket(key, comment) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 60 def flag_ticket(key, comment) key = sanitise_key(key) add_tag(key, @ado_config.flag_tag) add_comment(key, comment) unless comment.blank? end |
#flagged?(key) ⇒ Boolean
117 118 119 120 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 117 def flagged?(key) = get_work_item(key)["fields"]["System.Tags"].split("; ") .include?(@ado_config.flag_tag) end |
#get_ticket_fixversions(key) ⇒ Array<String>
Returns fix versions.
146 147 148 149 150 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 146 def get_ticket_fixversions(key) key = sanitise_key(key) get_work_item(key)["fields"]["Microsoft.VSTS.Build.IntegrationBuild"].split("; ") end |
#get_ticket_status(key) ⇒ String
187 188 189 190 191 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 187 def get_ticket_status(key) key = sanitise_key(key) get_work_item(key)["fields"]["System.State"] end |
#get_work_item(key) ⇒ RawWorkItemHash
124 125 126 127 128 129 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 124 def get_work_item(key) key = sanitise_key(key) res = @network_service.do_get("/wit/workitems/#{key}?#{API_VERSION_PARAM}") JSON.parse(res.body) end |
#remove_tag(key, tag) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 104 def remove_tag(key, tag) = get_work_item(key)["fields"]["System.Tags"].split("; ") = .filter { |t| t != tag } payload = [{ "op" => "replace", "path" => "/fields/System.Tags", "value" => .join("; ") }] update_ticket(key, payload) end |
#search_unblocked_issues(component, status, ticket_types = [], options = nil) ⇒ Array<Apadmi::Grout::Issue>
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 42 def search_unblocked_issues(component, status, ticket_types = [], = nil) status_filter = ("AND [System.State]='#{status}' " unless status.blank?) || "" type_filter = ("AND [System.WorkItemType] IN (#{ticket_types.map { |t| "'#{t}'" }.join(", ")})" unless ticket_types.empty?) || "" = (component, ) wiql = %( Select [System.Id] From WorkItems Where [System.Id] >= 1 #{status_filter} #{type_filter} #{} ) get_issues_by_wiql(wiql) end |
#transition_issue(issue, state_name) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 154 def transition_issue(issue, state_name) key = sanitise_key(issue.key) payload = [{ "op" => "add", "path" => "/fields/System.State", "value" => state_name }] update_ticket(key, payload) end |
#un_flag_ticket(key) ⇒ Object
68 69 70 71 72 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 68 def un_flag_ticket(key) key = sanitise_key(key) remove_tag(key, @ado_config.flag_tag) end |
#update_ticket(key, payload) ⇒ Object
87 88 89 |
# File 'lib/apadmi/grout/service/board_service/ado_board_service.rb', line 87 def update_ticket(key, payload) @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json) end |