Class: Tefoji::JiraMockApi

Inherits:
JiraApi
  • Object
show all
Defined in:
lib/tefoji/jira_api.rb

Constant Summary

Constants inherited from JiraApi

Tefoji::JiraApi::FIELD_ACCOUNT_ID, Tefoji::JiraApi::FIELD_ID, Tefoji::JiraApi::FIELD_KEY, Tefoji::JiraApi::FIELD_NAME, Tefoji::JiraApi::FIELD_VALUE, Tefoji::JiraApi::ISSUE_EPIC, Tefoji::JiraApi::ISSUE_NEW_FEATURE, Tefoji::JiraApi::ISSUE_SUB_TASK, Tefoji::JiraApi::ISSUE_TASK

Instance Attribute Summary

Attributes inherited from JiraApi

#jira_base_rest_url, #jira_base_url, #jira_username, #log_level, #logger

Instance Method Summary collapse

Methods inherited from JiraApi

#add_issue_to_epic, #add_watcher, #create_issue, #get_components, #get_transition_id, #get_username, #link_issues, #retrieve_issue, #save_authentication, #test_authentication, #transition, #user_email_to_account_id, #user_name_to_account_name

Methods included from Logging

#fatal

Constructor Details

#initialize(log_level = Logger::ERROR) ⇒ JiraMockApi

Returns a new instance of JiraMockApi.



458
459
460
461
462
# File 'lib/tefoji/jira_api.rb', line 458

def initialize(log_level = Logger::ERROR)
  super
  @key_count = 0
  @summary_count = 0
end

Instance Method Details

#authenticate(jira_base_url, username = nil, jira_auth = nil) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/tefoji/jira_api.rb', line 464

def authenticate(jira_base_url, username = nil, jira_auth = nil)
  @jira_base_url = jira_base_url
  @jira_base_rest_url = "#{jira_base_url}/rest/api/2"

  @logger.info "Using mock of Jira instance: \"#{jira_base_url}\""

  if jira_auth.nil?
    if username.nil?
      print 'Enter jira user name: '
      username = $stdin.gets.chomp
    end
  else
    plain_auth = Base64.decode64(jira_auth)
    username = plain_auth.split(':')[0]
  end

  @jira_username = username
end

#greenhopper_put(request_path, payload) ⇒ Object



499
500
501
502
503
504
505
506
507
# File 'lib/tefoji/jira_api.rb', line 499

def greenhopper_put(request_path, payload)
  greenhopper_base_rest_url = "#{@jira_base_url}:443/rest/greenhopper/1.0"
  url = "#{greenhopper_base_rest_url}/#{request_path}/"
  # json_header = { 'Content-Type' => 'application/json' }
  # headers = { 'Authorization' => 'Basic mocked-auth-header' }.merge(json_header)

  puts "\n  RestClient.put #{url}\n  #{pretty(payload)}\n\n"
  mocked_response
end

#jira_get(jira_request_path) ⇒ Object



483
484
485
486
487
488
# File 'lib/tefoji/jira_api.rb', line 483

def jira_get(jira_request_path)
  url = "#{@jira_base_rest_url}/#{jira_request_path}"
  header = { 'Authorization' => 'Basic mocked-auth-header' }
  puts "\n  RestClient.get #{url} #{header}\n"
  mocked_response
end

#jira_post(jira_request_path, payload) ⇒ Object



490
491
492
493
494
495
496
497
# File 'lib/tefoji/jira_api.rb', line 490

def jira_post(jira_request_path, payload)
  url = "#{@jira_base_rest_url}/#{jira_request_path}/"
  # json_header = { 'Content-Type' => 'application/json' }
  # headers = { 'Authorization' => 'Basic mocked-auth-header' }.merge(json_header)

  puts "\n  RestClient.post #{url}\n  #{pretty(payload)}\n\n"
  mocked_response
end

#mocked_responseObject



513
514
515
516
517
518
519
520
521
522
523
# File 'lib/tefoji/jira_api.rb', line 513

def mocked_response
  @key_count += 1
  @summary_count += 1

  return {
    'key' => "MOCKED-#{@key_count}",
    'fields' => {
      'summary' => "Mocked issue summary #{@summary_count}"
    }
  }
end

#pretty(issue_data) ⇒ Object



509
510
511
# File 'lib/tefoji/jira_api.rb', line 509

def pretty(issue_data)
  JSON.pretty_generate(issue_data)
end