Class: IssueTrackerService

Inherits:
Service
  • Object
show all
Defined in:
app/models/project_services/issue_tracker_service.rb

Overview

Schema Information

Table name: services

id                    :integer          not null, primary key
type                  :string
title                 :string
project_id            :integer
created_at            :datetime         not null
updated_at            :datetime         not null
active                :boolean          not null
properties            :text
template              :boolean          default(FALSE)
push_events           :boolean          default(TRUE)
issues_events         :boolean          default(TRUE)
merge_requests_events :boolean          default(TRUE)
tag_push_events       :boolean          default(TRUE)
note_events           :boolean          default(TRUE), not null
build_events          :boolean          default(FALSE), not null
category              :string           default("common"), not null
default               :boolean          default(FALSE)
wiki_page_events      :boolean          default(TRUE)

Instance Method Summary collapse

Methods inherited from Service

#activated?, #async_execute, available_services_names, boolean_accessor, #can_test?, #category, create_from_template, #description, #help, #issue_tracker?, prop_accessor, #reset_updated_properties, #template?, #test, #title, #to_param, #updated_properties

Instance Method Details

#default?Boolean


31
32
33
# File 'app/models/project_services/issue_tracker_service.rb', line 31

def default?
  default
end

#execute(data) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/project_services/issue_tracker_service.rb', line 79

def execute(data)
  return unless supported_events.include?(data[:object_kind])

  message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again."
  result = false

  begin
    response = HTTParty.head(self.project_url, verify: true)

    if response
      message = "#{self.type} received response #{response.code} when attempting to connect to #{self.project_url}"
      result = true
    end
  rescue HTTParty::Error, Timeout::Error, SocketError, Errno::ECONNRESET, Errno::ECONNREFUSED => error
    message = "#{self.type} had an error when trying to connect to #{self.project_url}: #{error.message}"
  end
  Rails.logger.info(message)
  result
end

#fieldsObject


51
52
53
54
55
56
57
58
# File 'app/models/project_services/issue_tracker_service.rb', line 51

def fields
  [
    { type: 'text', name: 'description', placeholder: description },
    { type: 'text', name: 'project_url', placeholder: 'Project url' },
    { type: 'text', name: 'issues_url', placeholder: 'Issue url' },
    { type: 'text', name: 'new_issue_url', placeholder: 'New Issue url' }
  ]
end

#initialize_propertiesObject


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/project_services/issue_tracker_service.rb', line 60

def initialize_properties
  if properties.nil?
    if enabled_in_gitlab_config
      self.properties = {
        title: issues_tracker['title'],
        project_url: add_issues_tracker_id(issues_tracker['project_url']),
        issues_url: add_issues_tracker_id(issues_tracker['issues_url']),
        new_issue_url: add_issues_tracker_id(issues_tracker['new_issue_url'])
      }
    else
      self.properties = {}
    end
  end
end

#issue_path(iid) ⇒ Object


47
48
49
# File 'app/models/project_services/issue_tracker_service.rb', line 47

def issue_path(iid)
  issue_url(iid)
end

#issue_url(iid) ⇒ Object


35
36
37
# File 'app/models/project_services/issue_tracker_service.rb', line 35

def issue_url(iid)
  self.issues_url.gsub(':id', iid.to_s)
end

#new_issue_pathObject


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

def new_issue_path
  new_issue_url
end

#project_pathObject


39
40
41
# File 'app/models/project_services/issue_tracker_service.rb', line 39

def project_path
  project_url
end

#supported_eventsObject


75
76
77
# File 'app/models/project_services/issue_tracker_service.rb', line 75

def supported_events
  %w(push)
end