Class: Lita::Handlers::VersionCheck

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/version_check.rb

Instance Method Summary collapse

Instance Method Details

#check_version(message) ⇒ Object

START:handler



46
47
48
49
50
51
52
53
# File 'lib/lita/handlers/version_check.rb', line 46

def check_version(message)
  message.reply [
    "My git revision is [#{git_sha}].",
    "My repository URL is [#{git_repository_url}].",
    '<<<>>>',
    "Brought to you by [#{gemspec_version}]."
  ].join(' ')
end

#gemspec_versionObject

START:gemspec_version Asks the bundle command which version of lita-version-check you’re

running.

e.g. lita-version-check 0.1.0


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lita/handlers/version_check.rb', line 22

def gemspec_version
  # list all installed gems in this context and filter for the one named
  #   version check
  `bundle list | grep lita-version-check`
  # strip out all characters other than alphanumerics and . - and space.
  .gsub(/[^A-Za-z0-9\.\- ]/i, '')
  # trim leading and trailing whitespace
  .strip
  # split on whitespace
  .split
  # join the split tokens back together with a uniform single space
  .join(" ")
end

#git_repository_urlObject

START:repo_url Fetch the short-form repository URL of this git repo e.g.

git@github.com:dpritchett/ruby-bookbot.git


40
41
42
# File 'lib/lita/handlers/version_check.rb', line 40

def git_repository_url
  `git config --get remote.origin.url`.strip
end

#git_shaObject

START:commit_hash Fetch the SHA representing the current git commit in this repository:

e.g. fc648e78f54a74ca92a82d0ff77a9151fcf8e373


11
12
13
# File 'lib/lita/handlers/version_check.rb', line 11

def git_sha
  `git rev-parse HEAD`.strip
end