Class: TeamcityService

Inherits:
CiService show all
Includes:
ReactiveService, ServicePushDataValidations
Defined in:
app/models/project_services/teamcity_service.rb

Constant Summary

Constants inherited from Service

Service::DEV_SERVICE_NAMES, Service::SERVICE_NAMES

Instance Attribute Summary collapse

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ServicePushDataValidations

#merge_request_valid?, #push_valid?, #tag_push_valid?

Methods inherited from CiService

#valid_token?

Methods inherited from Service

#activated?, #api_field_names, #async_execute, available_services_names, available_services_types, boolean_accessor, build_from_integration, #can_test?, #category, #configurable_event_actions, #configurable_events, default_integration, dev_services_names, #editable?, #event_channel_names, #event_field, #event_names, event_names, find_or_create_templates, find_or_initialize_all, find_or_initialize_integration, #global_fields, #initialize_properties, instance_exists_for?, #issue_tracker?, #json_fields, #operating?, prop_accessor, #reset_updated_properties, services_names, services_types, #show_active_box?, supported_event_actions, #supported_events, #supports_data_fields?, #test, #to_data_fields_hash, #to_param, #to_service_hash, #updated_properties

Methods included from ProjectServicesLoggable

#build_message, #log_error, #log_info, #logger

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Attribute Details

#responseObject

Returns the value of attribute response


18
19
20
# File 'app/models/project_services/teamcity_service.rb', line 18

def response
  @response
end

Class Method Details

.event_description(event) ⇒ Object


32
33
34
35
36
37
38
39
# File 'app/models/project_services/teamcity_service.rb', line 32

def event_description(event)
  case event
  when 'push', 'push_events'
    'TeamCity CI will be triggered after every push to the repository except branch delete'
  when 'merge_request', 'merge_request_events'
    'TeamCity CI will be triggered after a merge request has been created or updated'
  end
end

.supported_eventsObject


28
29
30
# File 'app/models/project_services/teamcity_service.rb', line 28

def supported_events
  %w(push merge_request)
end

.to_paramObject


24
25
26
# File 'app/models/project_services/teamcity_service.rb', line 24

def to_param
  'teamcity'
end

Instance Method Details

#build_page(sha, ref) ⇒ Object


78
79
80
# File 'app/models/project_services/teamcity_service.rb', line 78

def build_page(sha, ref)
  with_reactive_cache(sha, ref) {|cached| cached[:build_page] }
end

#calculate_reactive_cache(sha, ref) ⇒ Object


86
87
88
89
90
91
92
93
94
# File 'app/models/project_services/teamcity_service.rb', line 86

def calculate_reactive_cache(sha, ref)
  response = get_path("httpAuth/app/rest/builds/branch:unspecified:any,revision:#{sha}")

  if response
    { build_page: read_build_page(response), commit_status: read_commit_status(response) }
  else
    { build_page: teamcity_url, commit_status: :error }
  end
end

#commit_status(sha, ref) ⇒ Object


82
83
84
# File 'app/models/project_services/teamcity_service.rb', line 82

def commit_status(sha, ref)
  with_reactive_cache(sha, ref) {|cached| cached[:commit_status] }
end

#compose_service_hookObject


42
43
44
45
# File 'app/models/project_services/teamcity_service.rb', line 42

def compose_service_hook
  hook = service_hook || build_service_hook
  hook.save
end

#descriptionObject


57
58
59
# File 'app/models/project_services/teamcity_service.rb', line 57

def description
  'A continuous integration and build server'
end

#execute(data) ⇒ Object


96
97
98
99
100
101
102
103
# File 'app/models/project_services/teamcity_service.rb', line 96

def execute(data)
  case data[:object_kind]
  when 'push'
    execute_push(data)
  when 'merge_request'
    execute_merge_request(data)
  end
end

#fieldsObject


66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/project_services/teamcity_service.rb', line 66

def fields
  [
    { type: 'text', name: 'teamcity_url',
      placeholder: 'TeamCity root URL like https://teamcity.example.com', required: true },
    { type: 'text', name: 'build_type',
      placeholder: 'Build configuration ID', required: true },
    { type: 'text', name: 'username',
      placeholder: 'A user with permissions to trigger a manual build' },
    { type: 'password', name: 'password' }
  ]
end

#helpObject


61
62
63
64
# File 'app/models/project_services/teamcity_service.rb', line 61

def help
  'You will want to configure monitoring of all branches so merge '\
  'requests build, that setting is in the vsc root advanced settings.'
end

#reset_passwordObject


47
48
49
50
51
# File 'app/models/project_services/teamcity_service.rb', line 47

def reset_password
  if teamcity_url_changed? && !password_touched?
    self.password = nil
  end
end

#titleObject


53
54
55
# File 'app/models/project_services/teamcity_service.rb', line 53

def title
  'JetBrains TeamCity CI'
end