Class: Abide::CLI::JiraFromXccdfCommand

Inherits:
CmdParse::Command
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/jira.rb

Constant Summary collapse

CMD_NAME =
'from-xccdf'
CMD_SHORT =
'Creates a parent issue with subtasks from a xccdf file'
CMD_LONG =
'Creates a parent issue with subtasks for a benchmark and any uncovered controls'

Instance Method Summary collapse

Constructor Details

#initializeJiraFromXccdfCommand

Returns a new instance of JiraFromXccdfCommand.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/abide_dev_utils/cli/jira.rb', line 116

def initialize
  super(CMD_NAME, takes_commands: false)
  short_desc(CMD_SHORT)
  long_desc(CMD_LONG)
  argument_desc(PATH: 'An XCCDF file', PROJECT: 'A Jira project')
  options.on('-d', '--dry-run', 'Runs through mock issue creation. Useful for testing, but not reliable for knowing what exactly will be created. Use --explain for more accurate information.') do
    @data[:dry_run] = true
  end
  options.on('-x', '--explain', 'Shows a report of all the controls that will and won\'t be created as issues, and why. DOES NOT create issues.') do
    @data[:explain] = true
  end
  options.on('-e [EPIC]', '--epic [EPIC]', 'If given, tasks will be created and assigned to this epic. Takes form <PROJECT>-<NUM>') { |e| @data[:epic] = e }
  options.on('-l [LEVEL]', '--level [LEVEL]', 'Only create tasks for rules belonging to the matching level. Takes a string that is treated as RegExp') do |x|
    @data[:level] = x
  end
  options.on('-p [PROFILE]', '--profile [PROFILE]', 'Only create tasks for rules belonging to the matching profile. Takes a string that is treated as RegExp') do |x|
    @data[:profile] = x
  end
end

Instance Method Details

#execute(path, project) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/abide_dev_utils/cli/jira.rb', line 136

def execute(path, project)
  Abide::CLI::VALIDATE.file(path)
  # Each control gets assigned labels based on the levels and profiles it supports.
  # Those labels all take the form "level_<level>_<profile>". This allows us to
  # filter the controls we want to create tasks for by level and profile.
  @data[:label_include] = nil
  @data[:label_include] = "level_#{@data[:level]}_" if @data[:level]
  @data[:label_include] = "#{@data[:label_include]}#{@data[:profile]}" if @data[:profile]
  Abide::CLI::OUTPUT.simple "Label include: #{@data[:label_include]}"
  AbideDevUtils::Jira.new_issues_from_xccdf(
    project,
    path,
    epic: @data[:epic],
    dry_run: @data[:dry_run],
    explain: @data[:explain],
    label_include: @data[:label_include],
  )
end