class GitLab::Exporter::Git

Git monitoring helping class

Takes a repository path for construction and provides 2 main methods:

- pull
- push

Both methods return a CommandResult which includes the output of the execution plus the tracked execution time.

Public Class Methods

new(repo) click to toggle source
# File lib/gitlab_exporter/git.rb, line 14
def initialize(repo)
  fail "Repository #{repo} does not exists" unless Dir.exist? repo

  @repo = repo
  @tracker = TimeTracker.new
end

Public Instance Methods

empty_commit(message = "Beep") click to toggle source
# File lib/gitlab_exporter/git.rb, line 30
def empty_commit(message = "Beep")
  @tracker.track { execute("git commit --allow-empty -m '#{message}'") }
end
pull() click to toggle source
# File lib/gitlab_exporter/git.rb, line 21
def pull
  @tracker.track { execute "git pull -q" }
end
push() click to toggle source
# File lib/gitlab_exporter/git.rb, line 25
def push
  empty_commit
  @tracker.track { execute "git push -q" }
end

Private Instance Methods

execute(command) click to toggle source
# File lib/gitlab_exporter/git.rb, line 36
def execute(command)
  result = CommandResult.new(*Open3.capture2e(command, chdir: @repo))
  fail "Command #{command} failed with status #{result.status}\n#{result.stdout}" if result.failed?

  result
end