Module: StillActive::ActivityHelper

Extended by:
ActivityHelper
Included in:
ActivityHelper
Defined in:
lib/helpers/activity_helper.rb

Instance Method Summary collapse

Instance Method Details

#activity_level(gem_data) ⇒ Object

Returns :archived, :ok, :stale, :critical, or :unknown



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/helpers/activity_helper.rb', line 42

def activity_level(gem_data)
  return :archived if gem_data[:archived]

  activity = last_activity(gem_data)
  return :unknown if activity.nil?

  config = StillActive.config
  if activity[:date] >= config.no_warning_range_end.years.ago
    :ok
  elsif activity[:date] >= config.warning_range_end.years.ago
    :stale
  else
    :critical
  end
end

#last_activity(gem_data) ⇒ Object

The most recent activity signal that drives the level, or nil if none: { date:, kind: } where kind is :release (preferred) or :commit. Release recency drives the level because a release is what a consumer can actually consume (you can’t ‘bundle update` to unreleased commits), so a lone rubocop/README commit can’t mask a multi-year release drought. The commit date stands in only when a gem has no releases at all (e.g. a git-sourced gem), where it is the only signal available.



19
20
21
22
23
24
25
26
27
28
# File 'lib/helpers/activity_helper.rb', line 19

def last_activity(gem_data)
  release = [
    gem_data[:latest_version_release_date],
    gem_data[:latest_pre_release_version_release_date],
  ].filter_map { parse_time(_1) }.max
  return { date: release, kind: :release } if release

  commit = parse_time(gem_data[:last_commit_date])
  commit ? { date: commit, kind: :commit } : nil
end

#parse_time(value) ⇒ Object

Coerce a Time or an iso8601-ish string (the SARIF path may supply either) to a Time, or nil if absent/unparseable.



32
33
34
35
36
37
38
39
# File 'lib/helpers/activity_helper.rb', line 32

def parse_time(value)
  return value if value.is_a?(Time)
  return if value.nil?

  Time.parse(value.to_s)
rescue ArgumentError, TypeError, RangeError
  nil
end