Module: StillActive::BotContext

Extended by:
BotContext
Included in:
BotContext
Defined in:
lib/helpers/bot_context.rb

Overview

Best-effort detection of a Dependabot/Renovate-authored run, so –baseline reports can lead with a narrative (“Dependabot bump: rack 2.0.0 → 2.0.6”) instead of an unattributed list. Detection is heuristic: false negatives are fine (we just lose the narrative), false positives are not, so the subject patterns are anchored and require the literal bump/update keyword.

Constant Summary collapse

DEPENDABOT_SUBJECT =

Dependabot’s default subject is “Bump X from Y to Z” (capitalized, no prefix). The ‘from … to …` skeleton rarely occurs in human commits, so it is safe unprefixed. The conventional-commit prefix only appears when configured.

/\A(?:build\(deps(?:-dev)?\):\s*)?bump (\S+) from (\S+) to (\S+)/i
RENOVATE_SUBJECT =

Renovate’s default is “Update dependency X to vN.…” — note the required ‘v`+digit version. Matching a bare “to <word>” would false-positive on ordinary commits (“Update README to mention SARIF”), so we anchor on the v-prefixed version. False negatives (a no-`v` Renovate config) are acceptable; false positives are not. The `v` is consumed, so the captured version excludes it.

/\A(?:(?:chore|fix|build)\(deps(?:-dev)?\):\s*)?update (?:dependency )?(\S+) to v(\d[\w.\-]*)/i
DEPENDABOT_BUMP =

Unanchored variants used only to EXTRACT the bump after a bot is already confirmed (via GITHUB_ACTOR / branch / the anchored subject above). Because detection has already happened, these can ignore whatever commit-message prefix or scope Dependabot/Renovate is configured with and just find the “bump X from Y to Z” / “update X to vN” skeleton anywhere in the subject.

/bump (\S+) from (\S+) to (\S+)/i
RENOVATE_BUMP =
/update (?:dependency )?(\S+) to v(\d[\w.\-]*)/i

Instance Method Summary collapse

Instance Method Details

#detect(env: ENV, head_subject: head_commit_subject) ⇒ Object

Returns { bot: “dependabot” | “renovate”, bumps: [{ gem:, from:, to: }] } or nil when no bot signal is present. ‘bumps` is parsed from the head commit subject; a grouped or unparseable subject yields an empty list.



38
39
40
41
42
43
# File 'lib/helpers/bot_context.rb', line 38

def detect(env: ENV, head_subject: head_commit_subject)
  bot = detect_bot(env: env, head_subject: head_subject)
  return if bot.nil?

  { bot: bot, bumps: bumps_from(bot, head_subject) }
end

#summary(context) ⇒ Object

A one-line, format-agnostic narrative for the detected context.



46
47
48
49
50
51
52
53
54
55
# File 'lib/helpers/bot_context.rb', line 46

def summary(context)
  label = context[:bot] == "renovate" ? "Renovate" : "Dependabot"
  bumps = context[:bumps]

  case bumps.length
  when 0 then "#{label} dependency update"
  when 1 then single_bump_summary(label, bumps.first)
  else "#{label}: #{bumps.length} dependency updates"
  end
end