Class: Jira::Auto::Tool::Project::TicketFields

Inherits:
Object
  • Object
show all
Defined in:
lib/jira/auto/tool/project/ticket_fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool, project) ⇒ TicketFields

Returns a new instance of TicketFields.



10
11
12
13
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 10

def initialize(tool, project)
  @tool = tool
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 8

def project
  @project
end

#toolObject (readonly)

Returns the value of attribute tool.



8
9
10
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 8

def tool
  @tool
end

Instance Method Details

#each_issue_type_fieldObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 39

def each_issue_type_field
  tool.jira_client.Createmeta.all({ projectKeys: project.key, "expand" => "projects.issuetypes.fields" })
      .each do |createmeta|
    createmeta.attrs["issuetypes"].each do |issue_type|
      issue_type_name = issue_type["name"]
      issue_type["fields"].each_value do |field|
        yield(issue_type_name, field)
      end
    end
  end
end

#listObject



15
16
17
18
19
20
21
22
23
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 15

def list
  table = Terminal::Table.new(
    title: "Project #{project.key} Ticket Fields",
    headings: table_row_header,
    rows: table_rows
  )

  puts table
end

#table_row_headerObject



25
26
27
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 25

def table_row_header
  ["Ticket Type", "Field Key", "Field Name", "Field Type", "Allowed Values"]
end

#table_rowsObject



29
30
31
32
33
34
35
36
37
# File 'lib/jira/auto/tool/project/ticket_fields.rb', line 29

def table_rows
  rows = []

  each_issue_type_field do |issue_type_name, field|
    rows << [issue_type_name, field["key"], field["name"], field["schema"]["type"], allowed_values(field)]
  end

  rows.sort
end