Class: Crep::HockeyAppCrashSource

Inherits:
CrashSource show all
Defined in:
lib/crep/model/crash_sources/hockeyapp_crash_source.rb

Overview

The HockeyApp Crash Source

Instance Attribute Summary

Attributes inherited from CrashSource

#app

Instance Method Summary collapse

Instance Method Details

#configure(bundle_identifier) ⇒ Object


12
13
14
15
16
17
18
19
20
21
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 12

def configure(bundle_identifier)
  HockeyApp::Config.configure do |config|
    raise 'Missing API token (CREP_HOCKEY_API_TOKEN)' unless ENV['CREP_HOCKEY_API_TOKEN']
    config.token = ENV['CREP_HOCKEY_API_TOKEN']
  end

  @client = HockeyApp.build_client
  @hockeyapp_app = hockeyapp(bundle_identifier, @client)
  @app = App.new(@hockeyapp_app.title, bundle_identifier)
end

#crash_count(version:, build:) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 28

def crash_count(version:, build:)
  statistics = @client.get_statistics @hockeyapp_app
  statistics_filtered_by_version = statistics.select do |statistic|
    statistic.shortversion == version && statistic.version == build
  end
  statistics_filtered_by_version.first.crashes
end

#crash_groups(version, show_only_unresolved) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 36

def crash_groups(version, show_only_unresolved)
  reasons = version.crash_reasons('sort' => 'number_of_crashes', 'order' => 'desc')
  unresolved_reasons = show_only_unresolved ? unresolved_reasons(reasons) : reasons
  unresolved_reasons.map do |reason|
    url = url(app_id: reason.app.public_identifier, version_id: version.id, reason_id: reason.id)
    deep_link = deep_link(app_id: reason.app.public_identifier, reason_id: reason.id)
    Crash.new(file_line: "#{reason.file}:#{reason.line}",
              occurrences: reason.number_of_crashes,
              reason: reason.reason,
              crash_class: reason.crash_class,
              registered_at: Date.parse(reason.created_at),
              deep_link: deep_link,
              url: url)
  end
end

#crashes(top, version, build, show_only_unresolved) ⇒ Object


23
24
25
26
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 23

def crashes(top, version, build, show_only_unresolved)
  version = version(version: version, build: build)
  crash_groups(version, show_only_unresolved).take(top.to_i)
end

56
57
58
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 56

def deep_link(app_id:, reason_id:)
  "hockeyapp-coach://view-crash/#{app_id}/#{reason_id}/latest"
end

#filtered_versions_by_version_and_build(versions, version_filter, build_filter) ⇒ Object


91
92
93
94
95
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 91

def filtered_versions_by_version_and_build(versions, version_filter, build_filter)
  versions.select do |version|
    (version.shortversion == version_filter) && (version.version == build_filter)
  end
end

#hockeyapp(bundle_identifier, client) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 79

def hockeyapp(bundle_identifier, client)
  all_apps = client.get_apps
  apps = all_apps.select do |app|
    app.bundle_identifier == bundle_identifier
  end
  unless apps.first
    CrepLogger.error("No app with the give bundle identifier (#{bundle_identifier}) was found.")
    raise
  end
  apps.first
end

#unresolved_reasons(reasons) ⇒ Object


75
76
77
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 75

def unresolved_reasons(reasons)
  reasons.reject(&:fixed)
end

#url(app_id:, version_id:, reason_id:) ⇒ Object


52
53
54
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 52

def url(app_id:, version_id:, reason_id:)
  "https://rink.hockeyapp.net/manage/apps/#{app_id}/app_versions/#{version_id}/crash_reasons/#{reason_id}"
end

#version(version:, build:) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/crep/model/crash_sources/hockeyapp_crash_source.rb', line 60

def version(version:, build:)
  filtered_versions = filtered_versions_by_version_and_build(@hockeyapp_app.versions, version, build)

  if filtered_versions.count <= 0
    CrepLogger.error("No version was found for #{version})#{build})")
    raise
  end

  report_version = filtered_versions.first

  CrepLogger.warn("Multiple results for #{version}/#{build} were found, using the first (with ID #{report_version.id}) one that was found") unless filtered_versions.count <= 1

  report_version
end