Module: FerrisBueller::Helpers

Includes:
Constants
Included in:
Main
Defined in:
lib/ferris-bueller/helpers.rb

Constant Summary

Constants included from Constants

Constants::CLOSED_STATE, Constants::CLOSED_TRANSITIONS, Constants::RESOLVED_STATE, Constants::RESOLVED_TRANSITIONS, Constants::RETRY_DELAY, Constants::SEVERITIES, Constants::SEVERITY_FIELD, Constants::SHOW_FIELDS

Instance Method Summary collapse

Instance Method Details

#go_refresh_jira_incidentsObject



56
57
58
59
60
61
62
63
# File 'lib/ferris-bueller/helpers.rb', line 56

def go_refresh_jira_incidents
  Thread.new do
    loop do
      refresh_jira_incidents
      sleep options.incident_refresh
    end
  end
end

#go_refresh_jira_membersObject



46
47
48
49
50
51
52
53
# File 'lib/ferris-bueller/helpers.rb', line 46

def go_refresh_jira_members
  Thread.new do
    loop do
      refresh_jira_members
      sleep options.member_refresh
    end
  end
end

#go_refresh_jira_usersObject



36
37
38
39
40
41
42
43
# File 'lib/ferris-bueller/helpers.rb', line 36

def go_refresh_jira_users
  Thread.new do
    loop do
      refresh_jira_users
      sleep options.user_refresh
    end
  end
end

#jira_request(path, params) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ferris-bueller/helpers.rb', line 144

def jira_request path, params
  api_url = File.join options.jira_url, 'rest/api/latest', path
  log.trace \
    event: 'jira request',
    path: path,
    params: params,
    api_url: api_url
  encoded_params = QueryParams.encode params
  uri = URI(api_url + '?' + encoded_params)
  http = Net::HTTP.new uri.host, uri.port
  req = Net::HTTP::Get.new uri
  req.use_ssl if uri.scheme == 'https'
  req.basic_auth options.jira_user, options.jira_pass
  req['Content-Type'] = 'application/json'
  req['Accept'] = 'application/json'
  resp = http.request req
  log.debug \
    event: 'jira request responded',
    path: path,
    params: params,
    api_url: api_url,
    response: resp
  JSON.parse resp.body
end

#refresh_jira_incidentsObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ferris-bueller/helpers.rb', line 119

def refresh_jira_incidents
  data = jira_request 'search', \
    jql: "project = #{options.jira_project} ORDER BY created ASC, priority DESC",
    fields: SHOW_FIELDS.keys.join(','),
    startAt: 0,
    maxResults: 1_000_000

  store['jira_incidents'] = data['issues'].map do |i|
    i['num'] = i['key'].split('-', 2).last ; i
  end

rescue StandardError => e
  log.error \
    error: 'could not refresh incidents',
    event: 'exception',
    exception: e.inspect,
    class: e.class,
    message: e.message,
    backtrace: e.backtrace,
    remediation: 'pausing breifly before retrying'
  sleep RETRY_DELAY
  retry
end

#refresh_jira_membersObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ferris-bueller/helpers.rb', line 97

def refresh_jira_members
  data = jira_request 'group', \
    groupname: options.jira_group,
    expand: 'users'

  user_names = data['users']['items'].map { |u| u['displayName'] }
  store['jira_members'] = user_names

rescue StandardError => e
  log.error \
    error: 'could not refresh members',
    event: 'exception',
    exception: e.inspect,
    class: e.class,
    message: e.message,
    backtrace: e.backtrace,
    remediation: 'pausing breifly before retrying'
  sleep RETRY_DELAY
  retry
end

#refresh_jira_usersObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ferris-bueller/helpers.rb', line 66

def refresh_jira_users
  data = jira_request 'user/assignable/search', \
    project: options.jira_project,
    startAt: 0,
    maxResults: 1_000_000

  users = data.inject({}) do |h, user|
    h[user['name']] = {
      key: user['key'],
      nick: user['name'],
      name: user['displayName'],
      email: user['emailAddress']
    } ; h
  end

  store['jira_users'] = users

rescue StandardError => e
  log.error \
    error: 'could not refresh users',
    event: 'exception',
    exception: e.inspect,
    class: e.class,
    message: e.message,
    backtrace: e.backtrace,
    remediation: 'pausing breifly before retrying'
  sleep RETRY_DELAY
  retry
end

#start_your_day_offObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ferris-bueller/helpers.rb', line 16

def start_your_day_off
  Web.set :environment, options.environment
  Web.set :port, options.port
  Web.set :bind, options.bind
  Web.set :store, @store
  Web.set :logger, log

  if log.level >= ::Logger::DEBUG
    Web.set :raise_errors, true
    Web.set :dump_errors, true
    Web.set :show_exceptions, true
    Web.set :logging, ::Logger::DEBUG
  end

  Thin::Logging.logger = log

  Web.run!
end

#storeObject



13
# File 'lib/ferris-bueller/helpers.rb', line 13

def store ; @store end