Class: Abt::Providers::Devops::Services::WorkItemPicker
- Inherits:
-
Object
- Object
- Abt::Providers::Devops::Services::WorkItemPicker
- Defined in:
- lib/abt/providers/devops/services/work_item_picker.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #columns ⇒ Object
-
#initialize(cli:, path:, config:, board:) ⇒ WorkItemPicker
constructor
A new instance of WorkItemPicker.
- #prompt_work_item(work_items) ⇒ Object
- #select_work_item ⇒ Object
- #work_items_in_column(column) ⇒ Object
Constructor Details
#initialize(cli:, path:, config:, board:) ⇒ WorkItemPicker
Returns a new instance of WorkItemPicker.
23 24 25 26 27 28 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 23 def initialize(cli:, path:, config:, board:) @cli = cli @config = config @path = path @board = board end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
21 22 23 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 21 def board @board end |
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
21 22 23 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 21 def cli @cli end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
21 22 23 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 21 def config @config end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 21 def path @path end |
Class Method Details
.call(**args) ⇒ Object
17 18 19 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 17 def self.call(**args) new(**args).call end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 30 def call work_item = select_work_item path_with_work_item = Path.from_ids( organization_name: path.organization_name, project_name: path.project_name, team_name: path.team_name, board_name: path.board_name, work_item_id: work_item["id"] ) Result.new(work_item: work_item, path: path_with_work_item) end |
#columns ⇒ Object
82 83 84 85 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 82 def columns board["columns"] || api.get("#{path.project_name}/#{path.team_name}/_apis/work/boards/#{path.board_name}")["columns"] end |
#prompt_work_item(work_items) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 57 def prompt_work_item(work_items) = work_items.map do |work_item| { "id" => work_item["id"], "name" => "##{work_item['id']} #{work_item['name']}" } end choice = cli.prompt.choice("Select a work item", , nil_option: true) choice && work_items.find { |work_item| work_item["id"] == choice["id"] } end |
#select_work_item ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 44 def select_work_item column = cli.prompt.choice("Which column in #{board['name']}?", columns) cli.warn("Fetching work items...") work_items = work_items_in_column(column) if work_items.length.zero? cli.warn("Section is empty") select_work_item else prompt_work_item(work_items) || select_work_item end end |
#work_items_in_column(column) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/abt/providers/devops/services/work_item_picker.rb', line 69 def work_items_in_column(column) work_items = api.work_item_query( <<~WIQL SELECT [System.Id] FROM WorkItems WHERE [System.BoardColumn] = '#{column['name']}' ORDER BY [Microsoft.VSTS.Common.BacklogPriority] ASC WIQL ) work_items.map { |work_item| api.sanitize_work_item(work_item) } end |